]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: use sd_get_sessions() for number of users (#2088)
authorThorsten Kukuk <kukuk@suse.com>
Wed, 31 May 2023 06:57:01 +0000 (08:57 +0200)
committerThorsten Kukuk <kukuk@suse.com>
Wed, 31 May 2023 11:58:26 +0000 (13:58 +0200)
term-utils/Makemodule.am
term-utils/agetty.c

index 15423204222392eed576f4f0604a21fda97f71a1..b7037fb116d60f5a3e6f018e6851a299f4e060cd 100644 (file)
@@ -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
 
 
index cf8725537b98a8e2824828b6c49d76bbaabb32e5..6bc3e5b5a8338c3673db26f9998b2382c4b84b5f 100644 (file)
 # endif
 #endif
 
+#ifdef USE_SYSTEMD
+# include <systemd/sd-daemon.h>
+# include <systemd/sd-login.h>
+#endif
+
 #ifdef __linux__
 #  include <sys/kd.h>
 #  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