Merge branch 'awilfox/procps-utmpx-support'

References:
 procps-ng/procps!67
This commit is contained in:
Craig Small 2020-12-22 14:59:47 +11:00
parent 5a9c978f8a
commit 68f0941433
2 changed files with 36 additions and 2 deletions

View File

@ -45,7 +45,7 @@ AC_PROG_MAKE_SET
# Checks for header files. # Checks for header files.
AC_HEADER_MAJOR 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. # Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL AC_CHECK_HEADER_STDBOOL

34
w.c
View File

@ -43,7 +43,11 @@
#include <termios.h> #include <termios.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
#else
# include <utmp.h> # include <utmp.h>
#endif
#include <arpa/inet.h> #include <arpa/inet.h>
#include "c.h" #include "c.h"
@ -57,7 +61,17 @@
static int ignoreuser = 0; /* for '-u' */ static int ignoreuser = 0; /* for '-u' */
static int oldstyle = 0; /* for '-o' */ static int oldstyle = 0; /* for '-o' */
#ifdef HAVE_UTMPX_H
typedef struct utmpx utmp_t;
#else
typedef struct utmp utmp_t; 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 #ifdef W_SHOWFROM
# define FROM_STRING "on" # define FROM_STRING "on"
@ -471,7 +485,11 @@ static void showinfo(
printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line); printf("%-*.*s%-9.8s", userlen + 1, userlen, uname, u->ut_line);
if (from) if (from)
print_from(u, ip_addresses, fromlen); 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); print_logintime(u->ut_time, stdout);
#endif
if (*u->ut_line == ':') if (*u->ut_line == ':')
/* idle unknown for xdm logins */ /* idle unknown for xdm logins */
printf(" ?xdm? "); printf(" ?xdm? ");
@ -653,11 +671,19 @@ int main(int argc, char **argv)
printf(_(" IDLE WHAT\n")); printf(_(" IDLE WHAT\n"));
} }
#ifdef HAVE_UTMPX_H
setutxent();
#else
utmpname(UTMP_FILE); utmpname(UTMP_FILE);
setutent(); setutent();
#endif
if (user) { if (user) {
for (;;) { for (;;) {
#ifdef HAVE_UTMPX_H
u = getutxent();
#else
u = getutent(); u = getutent();
#endif
if (!u) if (!u)
break; break;
if (u->ut_type != USER_PROCESS) if (u->ut_type != USER_PROCESS)
@ -668,7 +694,11 @@ int main(int argc, char **argv)
} }
} else { } else {
for (;;) { for (;;) {
#ifdef HAVE_UTMPX_H
u = getutxent();
#else
u = getutent(); u = getutent();
#endif
if (!u) if (!u)
break; break;
if (u->ut_type != USER_PROCESS) if (u->ut_type != USER_PROCESS)
@ -678,7 +708,11 @@ int main(int argc, char **argv)
fromlen, ip_addresses); fromlen, ip_addresses);
} }
} }
#ifdef HAVE_UTMPX_H
endutxent();
#else
endutent(); endutent();
#endif
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }