From: Thorsten Kukuk Date: Wed, 31 May 2023 06:57:01 +0000 (+0200) Subject: agetty: use sd_get_sessions() for number of users (#2088) X-Git-Tag: v2.40-rc1~274^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e915e6baeba3cbce154336a4f1f24a8be93e85ae;p=thirdparty%2Futil-linux.git agetty: use sd_get_sessions() for number of users (#2088) --- diff --git a/term-utils/Makemodule.am b/term-utils/Makemodule.am index 1542320422..b7037fb116 100644 --- a/term-utils/Makemodule.am +++ b/term-utils/Makemodule.am @@ -58,6 +58,10 @@ endif if HAVE_ECONF agetty_LDADD += -leconf endif +if HAVE_SYSTEMD +agetty_LDADD += $(SYSTEMD_LIBS) +agetty_CFLAGS = $(SYSTEMD_CFLAGS) +endif endif # BUILD_AGETTY diff --git a/term-utils/agetty.c b/term-utils/agetty.c index cf8725537b..6bc3e5b5a8 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -73,6 +73,11 @@ # endif #endif +#ifdef USE_SYSTEMD +# include +# include +#endif + #ifdef __linux__ # include # define USE_SYSLOG @@ -2864,12 +2869,23 @@ static void output_special_char(struct issue *ie, case 'U': { int users = 0; - struct utmpx *ut; - setutxent(); - while ((ut = getutxent())) - if (ut->ut_type == USER_PROCESS) - users++; - endutxent(); +#ifdef USE_SYSTEMD + if (sd_booted() > 0) { + users = sd_get_sessions(NULL); + if (users < 0) + users = 0; + } else { +#endif + users = 0; + struct utmpx *ut; + setutxent(); + while ((ut = getutxent())) + if (ut->ut_type == USER_PROCESS) + users++; + endutxent(); +#ifdef USE_SYSTEMD + } +#endif if (c == 'U') fprintf(ie->output, P_("%d user", "%d users", users), users); else