From 1dacc480a176cf023be1b9ac1fe2aa51f5993be1 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 21 Sep 1999 09:11:28 +0000 Subject: 1999-09-19 Roland McGrath * w.c (add_utmp_procs): Ignore entries whose ut_type is not LOGIN_PROCESS or USER_PROCESS, or whose ut_line is empty. --- utils/w.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'utils/w.c') 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); -- cgit v1.2.3