summaryrefslogtreecommitdiff
path: root/system/procps/use-utmpx.patch
blob: 83047cf222fb9557d8812e86410f589c8eab57f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
diff --git a/configure.ac b/configure.ac
index bc84a0d..da2916e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,7 +44,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 netinet/in.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 netinet/in.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/proc/whattime.c b/proc/whattime.c
index c223cad..d55fd22 100644
--- a/proc/whattime.c
+++ b/proc/whattime.c
@@ -33,7 +33,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <time.h>
-#include <utmp.h>
+#include <utmpx.h>
 #include <sys/ioctl.h>
 #include "whattime.h"
 #include "sysinfo.h"
@@ -42,7 +42,7 @@ static char buf[256];
 static double av[3];
 
 char *sprint_uptime(int human_readable) {
-  struct utmp *utmpstruct;
+  struct utmpx *utmpstruct;
   int upminutes, uphours, updays, upweeks, upyears, updecades;
   int pos;
   int comma;
@@ -98,13 +98,13 @@ char *sprint_uptime(int human_readable) {
 /* count the number of users */
 
     numuser = 0;
-    setutent();
-    while ((utmpstruct = getutent())) {
+    setutxent();
+    while ((utmpstruct = getutxent())) {
       if ((utmpstruct->ut_type == USER_PROCESS) &&
          (utmpstruct->ut_name[0] != '\0'))
         numuser++;
     }
-    endutent();
+    endutxent();
 
     pos += sprintf(buf + pos, "%2d user%s, ", numuser, numuser == 1 ? "" : "s");
 
diff --git a/w.c b/w.c
index 35710a3..6caa8a6 100644
--- a/w.c
+++ b/w.c
@@ -23,6 +23,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include "config.h"
 #include "c.h"
 #include "fileutils.h"
 #include "nls.h"
@@ -54,14 +55,22 @@
 #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>
 
 static int ignoreuser = 0;	/* for '-u' */
 static int oldstyle = 0;	/* for '-o' */
 static proc_t **procs;		/* our snapshot of the process table */
 
+#ifdef HAVE_UTMPX_H
+typedef struct utmpx utmp_t;
+#else
 typedef struct utmp utmp_t;
+#endif
 
 #ifdef W_SHOWFROM
 # define FROM_STRING "on"
@@ -604,11 +613,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 (unlikely(!u))
 				break;
 			if (u->ut_type != USER_PROCESS)
@@ -619,7 +636,11 @@ int main(int argc, char **argv)
 		}
 	} else {
 		for (;;) {
+#ifdef HAVE_UTMPX_H
+			u = getutxent();
+#else
 			u = getutent();
+#endif
 			if (unlikely(!u))
 				break;
 			if (u->ut_type != USER_PROCESS)
@@ -629,7 +650,11 @@ int main(int argc, char **argv)
 					 fromlen, ip_addresses);
 		}
 	}
+#ifdef HAVE_UTMPX_H
+	endutxent();
+#else
 	endutent();
+#endif
 
 	return EXIT_SUCCESS;
 }