summaryrefslogtreecommitdiff
path: root/utils/w.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-09-21 09:11:28 +0000
committerRoland McGrath <roland@gnu.org>1999-09-21 09:11:28 +0000
commit1dacc480a176cf023be1b9ac1fe2aa51f5993be1 (patch)
treec1c575be98d80ee4883c48c750a5ed9db08f0335 /utils/w.c
parent19c24c308bda3932d7c174c472df53e66059b551 (diff)
1999-09-19 Roland McGrath <roland@baalperazim.frob.com>
* w.c (add_utmp_procs): Ignore entries whose ut_type is not LOGIN_PROCESS or USER_PROCESS, or whose ut_line is empty.
Diffstat (limited to 'utils/w.c')
-rw-r--r--utils/w.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/utils/w.c b/utils/w.c
index a00c4b97..1ffbaaa9 100644
--- a/utils/w.c
+++ b/utils/w.c
@@ -260,8 +260,18 @@ add_utmp_procs (struct proc_stat_list *procs, struct utmp *u)
int pos;
struct proc_stat *ps;
- if (u->ut_type == DEAD_PROCESS || !*u->ut_name)
- return; /* Unused entry. */
+ switch (u->ut_type)
+ {
+ case LOGIN_PROCESS:
+ case USER_PROCESS:
+ /* These are the types that indicate a user job that we might
+ find processes for. */
+ if (u->ut_name[0] != '\0' && u->ut_line[0] != '\0')
+ break;
+ default:
+ /* This entry is not for a user, skip it. */
+ return;
+ }
strncpy (tty, u->ut_line, sizeof u->ut_line);
tty[sizeof u->ut_line] = '\0'; /* Ensure it's '\0' terminated. */
@@ -325,6 +335,9 @@ add_utmp_procs (struct proc_stat_list *procs, struct utmp *u)
tty, pid < 0 ? "pgrp" : "pid", pid < 0 ? -pid : pid);
}
+/* Find the absolute timestamp of when the system was booted.
+ We define "system boot time" as the task creation time of PID 1 (init). */
+
static error_t
fetch_boot_time (struct timeval *when)
{
@@ -368,7 +381,8 @@ uptime (struct proc_stat_list *procs)
char uptime_rep[20], tod_rep[20];
struct host_load_info *load;
unsigned nusers = 0;
- int maybe_add_user (struct proc_stat *ps) { if (ps->hook) nusers++; return 0; }
+ int maybe_add_user (struct proc_stat *ps)
+ { if (ps->hook) nusers++; return 0; }
proc_stat_list_for_each (procs, maybe_add_user);