From: Érico Nogueira Date: Wed, 28 Jul 2021 02:54:42 +0000 (-0300) Subject: logger: use xgetlogin from pwdutils. X-Git-Tag: v2.38-rc1~333^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f22751bd1fa6693dbe05872551c6f13f6371096;p=thirdparty%2Futil-linux.git logger: use xgetlogin from pwdutils. It defined its own xgetlogin, which queried geteuid() instead of getuid(), with a fallback to "" 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 --- diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am index 070c208352..6415f0cf0f 100644 --- a/misc-utils/Makemodule.am +++ b/misc-utils/Makemodule.am @@ -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) diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 27f745975b..5b122de79f 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -63,6 +63,7 @@ #include "xalloc.h" #include "strv.h" #include "list.h" +#include "pwdutils.h" #define SYSLOG_NAMES #include @@ -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 : ""; - 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 = ""; generate_syslog_header(ctl); }