From 8ab700b933caf18cb4547ea01bdcb1387a1145a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=89rico=20Nogueira?= Date: Tue, 27 Jul 2021 23:54:42 -0300 Subject: [PATCH] logger: use xgetlogin from pwdutils. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- misc-utils/Makemodule.am | 2 +- misc-utils/logger.c | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) 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); } -- 2.47.3