Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/w keep track of the two proc entries significant to ...



details:   https://anonhg.NetBSD.org/src/rev/5b3b468d3d27
branches:  trunk
changeset: 543496:5b3b468d3d27
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Feb 26 19:10:28 2003 +0000

description:
keep track of the two proc entries significant to the utmp entry. The one
indicated by the pid in struct utmpx [or ftpd hack], and the one that is
associated with the controlling tty, is in the foreground process group,
and has most cpu. If the second one exists, use that one, else use the first
one.

diffstat:

 usr.bin/w/w.c |  43 +++++++++++++++++++++++--------------------
 1 files changed, 23 insertions(+), 20 deletions(-)

diffs (90 lines):

diff -r 745f12dcd316 -r 5b3b468d3d27 usr.bin/w/w.c
--- a/usr.bin/w/w.c     Wed Feb 26 19:01:54 2003 +0000
+++ b/usr.bin/w/w.c     Wed Feb 26 19:10:28 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: w.c,v 1.57 2003/02/26 19:01:54 fredb Exp $     */
+/*     $NetBSD: w.c,v 1.58 2003/02/26 19:10:28 christos Exp $  */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)w.c        8.6 (Berkeley) 6/30/94";
 #else
-__RCSID("$NetBSD: w.c,v 1.57 2003/02/26 19:01:54 fredb Exp $");
+__RCSID("$NetBSD: w.c,v 1.58 2003/02/26 19:10:28 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -119,7 +119,8 @@
        struct timeval tv;
        dev_t   tdev;                   /* dev_t of terminal */
        time_t  idle;                   /* idle time of terminal in seconds */
-       struct  kinfo_proc2 *kp;        /* `most interesting' proc */
+       struct  kinfo_proc2 *tp;        /* `most interesting' tty proc */
+       struct  kinfo_proc2 *pp;        /* pid proc */
        pid_t   pid;                    /* pid or ~0 if not known */
 } *ep, *ehead = NULL, **nextp = &ehead;
 
@@ -298,20 +299,18 @@
                        continue;
 
                for (ep = ehead; ep != NULL; ep = ep->next) {
-                       if (ep->tdev != 0) {
-                               if (ep->tdev == kp->p_tdev &&
-                                   kp->p__pgid == kp->p_tpgid) {
-                                       /*
-                                        * Proc is in foreground of this
-                                        * terminal
-                                        */
-                                       if (proc_compare(ep->kp, kp)) {
-                                               ep->kp = kp;
-                                       }
-                                       break;
-                               }
-                       } else if (ep->pid != 0 && ep->pid == kp->p_pid) {
-                               ep->kp = kp;
+                       if (ep->tdev != 0 && ep->tdev == kp->p_tdev &&
+                           kp->p__pgid == kp->p_tpgid) {
+                               /*
+                                * Proc is in foreground of this
+                                * terminal
+                                */
+                               if (proc_compare(ep->tp, kp))
+                                       ep->tp = kp;
+                               break;
+                       } 
+                       if (ep->pid != 0 && ep->pid == kp->p_pid) {
+                               ep->pp = kp;
                                break;
                        }
                }
@@ -407,13 +406,17 @@
                        (void)snprintf(buf, sizeof(buf), "%s:%s", p, x);
                        p = buf;
                }
-               if (ep->kp == NULL) {
+               if (ep->tp != NULL)
+                       kp = ep->tp;
+               else if (ep->pp != NULL)
+                       kp = ep->pp;
+               else {
                        warnx("Stale utmp%s entry: %s %s %s",
                            ep->type, ep->name, ep->line, ep->host);
                        continue;
                }
                (void)printf("%-*s %-2.2s %-*.*s ",
-                   maxname, ep->kp->p_login,
+                   maxname, kp->p_login,
                    (strncmp(ep->line, "tty", 3) &&
                    strncmp(ep->line, "dty", 3)) ?
                    ep->line : ep->line + 3,
@@ -421,7 +424,7 @@
                then = (time_t)ep->tv.tv_sec;
                pr_attime(&then, &now);
                pr_idle(ep->idle);
-               pr_args(ep->kp);
+               pr_args(kp);
                (void)printf("\n");
        }
        exit(0);



Home | Main Index | Thread Index | Old Index