]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: use xgetlogin from pwdutils.
authorÉrico Nogueira <erico.erc@gmail.com>
Wed, 28 Jul 2021 02:54:42 +0000 (23:54 -0300)
committerÉrico Nogueira <erico.erc@gmail.com>
Thu, 29 Jul 2021 12:58:19 +0000 (09:58 -0300)
It defined its own xgetlogin, which queried geteuid() instead of getuid(),
with a fallback to "<someone>" when lookup fails. This has been the case
since the function was introduced in
019b97024fde3f07eaf541eef990762483369a11, so geteuid() has always been
used. Since using geteuid for identification isn't consistent with the
rest of util-linux, switching to xgetlogin(), which uses getuid(),
should be correct.

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
misc-utils/Makemodule.am
misc-utils/logger.c

index 070c2083521857c7be898420f0c532d2b6eddc77..6415f0cf0f8c77f1b87921cc07dff24f4f36cc8b 100644 (file)
@@ -28,7 +28,7 @@ usrbin_exec_PROGRAMS += logger
 MANPAGES += misc-utils/logger.1
 dist_noinst_DATA += misc-utils/logger.1.adoc
 logger_SOURCES = misc-utils/logger.c lib/strutils.c lib/strv.c
-logger_LDADD = $(LDADD)
+logger_LDADD = $(LDADD) libcommon.la
 logger_CFLAGS = $(AM_CFLAGS)
 if HAVE_SYSTEMD
 logger_LDADD += $(SYSTEMD_LIBS) $(SYSTEMD_DAEMON_LIBS) $(SYSTEMD_JOURNAL_LIBS)
index 27f745975b24154bbe593d8b4ddfe1dd15736fe1..5b122de79f96af4d5c0311ef190127a809923d50 100644 (file)
@@ -63,6 +63,7 @@
 #include "xalloc.h"
 #include "strv.h"
 #include "list.h"
+#include "pwdutils.h"
 
 #define        SYSLOG_NAMES
 #include <syslog.h>
@@ -393,16 +394,6 @@ static int journald_entry(struct logger_ctl *ctl, FILE *fp)
 }
 #endif
 
-static char const *xgetlogin(void)
-{
-       char const *cp;
-       struct passwd *pw;
-
-       if (!(cp = getlogin()) || !*cp)
-               cp = (pw = getpwuid(geteuid()))? pw->pw_name : "<someone>";
-       return cp;
-}
-
 /* this creates a timestamp based on current time according to the
  * fine rules of RFC3164, most importantly it ensures in a portable
  * way that the month day is correctly written (with a SP instead
@@ -927,6 +918,8 @@ static void logger_open(struct logger_ctl *ctl)
                                              syslog_local_header;
        if (!ctl->tag)
                ctl->tag = xgetlogin();
+       if (!ctl->tag)
+               ctl->tag = "<someone>";
 
        generate_syslog_header(ctl);
 }