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
|
--- src/rmonitor.c
+++ src/rmonitor.c
@@ -88,7 +88,7 @@
#include <sys/vmmeter.h>
#include <time.h>
#include <unistd.h>
-#include <utmp.h>
+#include <utmpx.h>
#define DEFTOL 2.5 /* default tolerance */
@@ -300,7 +300,7 @@
int memfre = 0;
int memtot = 0;
int memuse = 0;
- int nu = -1;
+ int nu = 0;
int np = -1;
int openf = -1;
int pgcnt = 0;
@@ -309,9 +309,8 @@
int pgsize = 0;
int slvl = 0;
int vn[3];
- int utfd;
time_t ct;
- struct utmp utmprec;
+ struct utmpx *utmprec;
union {
char buf[STRLEN];
@@ -402,14 +401,12 @@
if (getloadavg(lavg, samples) != samples) errmsg("getloadavg");
- if ((utfd = open(_PATH_UTMP, O_RDONLY)) >= 0) {
- nu = 0;
- while (read(utfd, &utmprec, sizeof utmprec) > 0)
- if (*(utmprec.ut_name)) nu++;
- if (close(utfd) < 0) errmsg("close");
+ setutxent();
+ while ((utmprec = getutxent()) != NULL) {
+ if (utmprec->ut_type == USER_PROCESS)
+ nu++;
}
- else
- errmsg("open");
+ endutxent();
#if __FreeBSD_version >= 420000
snprintf(stat, STRLEN,
|