Re: [PATCH] improve check if systemd is running
"Thorsten Kukuk" <[email protected]> ("kukuk") Tue, 30 May 2023 15:28:50 +0000
| Newsgroups | gmane.linux.procps.devel |
|---|---|
| Message-ID | <[email protected]> |
--LQksG6bCIzRHxTLp Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi, What about this patch? I haven't seen any comment on it? Thanks, Thorsten On Fri, Apr 14, Thorsten Kukuk wrote: > library: use sd_booted() if systemd is in use > > sd_get_sessions() will not return ENOENT as error, as this only means > that there is no session, not that systemd is not used. Use the > recommended sd_booted() function for this. > > Signed-off-by: Thorsten Kukuk <[email protected]> -- Thorsten Kukuk, Distinguished Engineer, Senior Architect, Future Technologies SUSE Software Solutions Germany GmbH, Frankenstraße 146, 90461 Nuernberg, Germany Managing Director: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman (HRB 36809, AG Nürnberg) --LQksG6bCIzRHxTLp Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-library-use-sd_booted-if-systemd-is-in-use.patch" library: use sd_booted() if systemd is in use sd_get_sessions() will not return ENOENT as error, as this only means that there is no session, not that systemd is not used. Use the recommended sd_booted() function for this. Signed-off-by: Thorsten Kukuk <[email protected]> --- library/uptime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/uptime.c b/library/uptime.c index bb9344a2..1826343d 100644 --- a/library/uptime.c +++ b/library/uptime.c @@ -32,9 +32,11 @@ #include <unistd.h> #include <utmp.h> #ifdef WITH_SYSTEMD +#include <systemd/sd-daemon.h> #include <systemd/sd-login.h> #endif #ifdef WITH_ELOGIND +#include <elogind/sd-daemon.h> #include <elogind/sd-login.h> #endif @@ -52,10 +54,8 @@ static int count_users(void) struct utmp *ut; #if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND) - numuser = sd_get_sessions(NULL); - - if (numuser >= 0 || numuser != ENOENT) - return numuser; + if (sd_booted() > 0) + return sd_get_sessions(NULL); #endif setutent(); -- 2.40.0 --LQksG6bCIzRHxTLp--