]> granicus.if.org Git - procps-ng/commitdiff
Merge branch 'awilfox/procps-utmpx-support'
authorCraig Small <csmall@dropbear.xyz>
Tue, 22 Dec 2020 03:59:47 +0000 (14:59 +1100)
committerCraig Small <csmall@dropbear.xyz>
Tue, 22 Dec 2020 04:09:08 +0000 (15:09 +1100)
References:
 procps-ng/procps!67

configure.ac
w.c

index f9375d40c41e4da647414d23a8e301cb588b2c09..84f0f18f8d7b8cdfb482dd43ed7b037e54b1dafc 100644 (file)
@@ -45,7 +45,7 @@ AC_PROG_MAKE_SET
 
 # Checks for header files.
 AC_HEADER_MAJOR
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h langinfo.h libintl.h limits.h locale.h stdint.h stdio_ext.h stdlib.h string.h sys/file.h sys/ioctl.h sys/param.h sys/time.h termios.h unistd.h utmp.h values.h wchar.h wctype.h])
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h float.h langinfo.h libintl.h limits.h locale.h stdint.h stdio_ext.h stdlib.h string.h sys/file.h sys/ioctl.h sys/param.h sys/time.h termios.h unistd.h utmp.h utmpx.h values.h wchar.h wctype.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_CHECK_HEADER_STDBOOL
diff --git a/w.c b/w.c
index bf275631d5595543a46ee5aee5041dd197cfe161..9c43bbd687bea3b2c54130de8ef64a0e3e0819aa 100644 (file)
--- a/w.c
+++ b/w.c
 #include <termios.h>
 #include <time.h>
 #include <unistd.h>
-#include <utmp.h>
+#ifdef HAVE_UTMPX_H
+#      include <utmpx.h>
+#else
+#      include <utmp.h>
+#endif
 #include <arpa/inet.h>
 
 #include "c.h"
 static int ignoreuser = 0;     /* for '-u' */
 static int oldstyle = 0;       /* for '-o' */
 
+#ifdef HAVE_UTMPX_H
+typedef struct utmpx utmp_t;
+#else
 typedef struct utmp utmp_t;
+#endif
+
+#if !defined(UT_HOSTSIZE) || defined(__UT_HOSTSIZE)
+#      define UT_HOSTSIZE __UT_HOSTSIZE
+#      define UT_LINESIZE __UT_LINESIZE
+#      define UT_NAMESIZE __UT_NAMESIZE
+#endif
 
 #ifdef W_SHOWFROM
 # define FROM_STRING "on"
@@ -471,7 +485,11 @@ static void showinfo(
         printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line);
         if (from)
             print_from(u, ip_addresses, fromlen);
+#ifdef HAVE_UTMPX_H
+        print_logintime(u->ut_tv.tv_sec, stdout);
+#else
         print_logintime(u->ut_time, stdout);
+#endif
         if (*u->ut_line == ':')
             /* idle unknown for xdm logins */
             printf(" ?xdm? ");
@@ -653,11 +671,19 @@ int main(int argc, char **argv)
                        printf(_("   IDLE WHAT\n"));
        }
 
+#ifdef HAVE_UTMPX_H
+       setutxent();
+#else
        utmpname(UTMP_FILE);
        setutent();
+#endif
        if (user) {
                for (;;) {
+#ifdef HAVE_UTMPX_H
+                       u = getutxent();
+#else
                        u = getutent();
+#endif
                        if (!u)
                                break;
                        if (u->ut_type != USER_PROCESS)
@@ -668,7 +694,11 @@ int main(int argc, char **argv)
                }
        } else {
                for (;;) {
+#ifdef HAVE_UTMPX_H
+                       u = getutxent();
+#else
                        u = getutent();
+#endif
                        if (!u)
                                break;
                        if (u->ut_type != USER_PROCESS)
@@ -678,7 +708,11 @@ int main(int argc, char **argv)
                                         fromlen, ip_addresses);
                }
        }
+#ifdef HAVE_UTMPX_H
+       endutxent();
+#else
        endutent();
+#endif
 
        return EXIT_SUCCESS;
 }