Source: coreutils
Version: 9.7-3
Tags: ftbfs upstream patch
User: [email protected]
Usertags: rebootstrap

Hi,

I am trying to port coreutils to musl-linux-any. While doing so, I ran
into a build failure of coreutils. On the surface, logname fails to
link due to undefined symbols that evidently should come from -lsystemd.

Looking deeper, logname uses getlogin(). This is normally provided by
the C library (at least on glibc) except when the C library implements
getlogin() as `return getenv("LOGNAME");` such as musl. coreutils does
not consider this a sane implementation and provides its own
implementation. That implementation in turn uses read_utmp from
lib/readutmp.c. That latter file can integrate with systemd and does so
when available. Therefore logname ends up using -lsystemd symbols, but
its linker invocation lacks -lsystemd.

For most other tools, -lsystemd is conveyed via READUTMP_LIB and added
via ..._LDADD where necessary. Adding READUTMP_LIB to src_logname_LDADD
might be a simple way to fix this, but that would result in logname
uselessly linking -lsystemd when built on glibc. In looking further, I
stumbled into LOGNAME_LIB, which can be non-empty for Windows builds.
Unfortunately, it is set up via a separate functions to the one deciding
on the logname implementation.

I suggest fusing those two functions into one that both sets
REPLACE_LOGNAME and LOGNAME_LIB. When logname is being replaced,
READUTMP_LIB is added to LOGNAME_LIB. LOGNAME_LIB can then be added to
src_logname_LDADD without incurring unnecessary linkage.

Please find a patch attached. This is an upstream problem that likely
affects any Linux distribution that uses coreutils with systemd on musl.
At present, this probably is PostmarkedOS only, but Alpine and others
might pick this up soon. Please forward it upstream.

Helmut
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -1786,7 +1786,6 @@
   gl_CONDITIONAL([GL_COND_OBJ_GETLOGIN],
                  [test $HAVE_GETLOGIN = 0 || test $REPLACE_GETLOGIN = 1])
   gl_UNISTD_MODULE_INDICATOR([getlogin])
-  AC_REQUIRE([gl_LIB_GETLOGIN])
   gl_GETNDELIM2
   gl_FUNC_GETOPT_GNU
   dnl Because of the way gl_FUNC_GETOPT_GNU is implemented (the gl_getopt_required
--- a/src/local.mk
+++ b/src/local.mk
@@ -338,6 +338,7 @@
 src_uptime_LDADD += $(READUTMP_LIB)
 src_users_LDADD += $(READUTMP_LIB)
 src_who_LDADD += $(READUTMP_LIB)
+src_logname_LDADD += $(GETLOGIN_LIB)

 # for strsignal
 src_kill_LDADD += $(LIBTHREAD)
--- a/m4/getlogin.m4
+++ b/m4/getlogin.m4
@@ -64,12 +64,6 @@
       *) REPLACE_GETLOGIN=1 ;;
     esac
   fi
-])
-
-dnl Determines the library needed by the implementation of the
-dnl getlogin and getlogin_r functions.
-AC_DEFUN([gl_LIB_GETLOGIN],
-[
   AC_REQUIRE([AC_CANONICAL_HOST])
   case $host_os in
     mingw* | windows*)
@@ -77,6 +71,10 @@
     *)
       GETLOGIN_LIB= ;;
   esac
+  if test "x$REPLACE_GETLOGIN" = x1; then
+    AC_REQUIRE([gl_READUTMP])
+    GETLOGIN_LIB="$READUTMP_LIB"
+  fi
   AC_SUBST([GETLOGIN_LIB])
   dnl For backward compatibility.
   LIB_GETLOGIN="$GETLOGIN_LIB"

Reply via email to