From d0fe5ff7e0d8d023945c688f7d31296cfb5ad266 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Tue, 8 Oct 1996 21:25:42 +0000 Subject: (w_deps): New function. (main): Initialize dependencies field of USER_HOOKS to w_deps. (_w_specs): Add PS_FMT_FIELD_COLON_MOD to Idle's flags. (w_fetch): Set HAVE bits even if the values are `nominal'. Correctly propagate PS->inapp bits. --- utils/w.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'utils/w.c') diff --git a/utils/w.c b/utils/w.c index bfeefcc5..eadb99c0 100644 --- a/utils/w.c +++ b/utils/w.c @@ -93,6 +93,14 @@ struct w_hook #define W_PSTAT_IDLE (PSTAT_USER_BASE << 2) #define W_PSTAT_LOGIN (PSTAT_USER_BASE << 3) +static ps_flags_t +w_deps (ps_flags_t flags) +{ + if (flags & W_PSTAT_IDLE) + flags |= PSTAT_TTY; + return flags; +} + static ps_flags_t w_fetch (struct proc_stat *ps, ps_flags_t need, ps_flags_t have) { @@ -122,24 +130,33 @@ w_fetch (struct proc_stat *ps, ps_flags_t need, ps_flags_t have) if (sd) *sd = '\0'; } - - have |= W_PSTAT_HOST; } + have |= W_PSTAT_HOST; } if (need & W_PSTAT_IDLE) - { - struct stat stat; - struct ps_tty *tty = ps->tty; - - hook->idle.tv_usec = 0; - if (io_stat (tty->port, &stat) == 0) - { - hook->idle.tv_sec = now.tv_sec - stat.st_mtime; - if (hook->idle.tv_sec > 0) + if (have & PSTAT_TTY) + { + struct stat stat; + struct ps_tty *tty = ps->tty; + + hook->idle.tv_usec = 0; + if (! tty) + { + hook->idle.tv_sec = 0; have |= W_PSTAT_IDLE; - } - } + } + else + { + if (io_stat (tty->port, &stat) == 0) + { + hook->idle.tv_sec = now.tv_sec - stat.st_mtime; + have |= W_PSTAT_IDLE; + } + } + } + else if (ps->inapp & PSTAT_TTY) + ps->inapp |= W_PSTAT_IDLE; if (need & W_PSTAT_USER) if (ps_user_uname_create (hook->utmp.ut_name, &hook->user) == 0) @@ -219,7 +236,7 @@ const struct ps_fmt_spec _w_specs[] = {"Name", 0, 20, -1,0, &w_user_getter, ps_emit_user_name,ps_cmp_strings}, {"Login","Login@", -7, -1,0,&w_login_getter,ps_emit_past_time,ps_cmp_times}, {"From", 0, 16, -1,0, &w_host_getter, ps_emit_string, ps_cmp_strings}, - {"Idle", 0, -5, -1,0, &w_idle_getter, ps_emit_minutes,ps_cmp_times}, + {"Idle", 0, -5, -1,PS_FMT_FIELD_COLON_MOD, &w_idle_getter, ps_emit_minutes,ps_cmp_times}, {"What=args"}, {0} }; @@ -381,7 +398,7 @@ main(int argc, char *argv[]) unsigned num_tty_names = 0; struct idvec *only_uids = make_idvec (), *not_uids = make_idvec (); #endif - struct ps_user_hooks ps_hooks = { 0, w_fetch, w_cleanup }; + struct ps_user_hooks ps_hooks = { w_deps, w_fetch, w_cleanup }; int has_hook (struct proc_stat *ps) { return ps->hook != 0; } -- cgit v1.2.3