Wait 11 minutes before deciding a machine is down (same as ruptime).
[unix-history] / usr / src / usr.bin / rwho / rwho.c
index f591e9f..805c21e 100644 (file)
@@ -1,14 +1,13 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rwho.c     4.5 83/05/05";
+static char sccsid[] = "@(#)rwho.c     4.9 (Berkeley) 85/05/07";
 #endif
 
 #include <sys/param.h>
 #include <stdio.h>
 #endif
 
 #include <sys/param.h>
 #include <stdio.h>
-#include <dir.h>
-#include <utmp.h>
-#include <rwhod.h>
+#include <sys/dir.h>
+#include "../etc/rwhod/rwhod.h"
 
 
-DIR    *etc;
+DIR    *dirp;
 
 struct whod wd;
 int    utmpcmp();
 
 struct whod wd;
 int    utmpcmp();
@@ -16,12 +15,16 @@ int utmpcmp();
 struct myutmp {
        char    myhost[32];
        int     myidle;
 struct myutmp {
        char    myhost[32];
        int     myidle;
-       struct  utmp myutmp;
+       struct  outmp myutmp;
 } myutmp[NUSERS];
 int    nusers;
 
 #define        WHDRSIZE        (sizeof (wd) - sizeof (wd.wd_we))
 #define        RWHODIR         "/usr/spool/rwho"
 } myutmp[NUSERS];
 int    nusers;
 
 #define        WHDRSIZE        (sizeof (wd) - sizeof (wd.wd_we))
 #define        RWHODIR         "/usr/spool/rwho"
+/* 
+ * this macro should be shared with ruptime.
+ */
+#define        down(w,now)     ((now) - (w)->wd_recvtime > 11 * 60)
 
 char   *ctime(), *strcpy();
 int    now;
 
 char   *ctime(), *strcpy();
 int    now;
@@ -50,13 +53,13 @@ again:
                perror(RWHODIR);
                exit(1);
        }
                perror(RWHODIR);
                exit(1);
        }
-       etc = opendir(".");
-       if (etc == NULL) {
-               perror("/etc");
+       dirp = opendir(".");
+       if (dirp == NULL) {
+               perror(RWHODIR);
                exit(1);
        }
        mp = myutmp;
                exit(1);
        }
        mp = myutmp;
-       while (dp = readdir(etc)) {
+       while (dp = readdir(dirp)) {
                if (dp->d_ino == 0)
                        continue;
                if (strncmp(dp->d_name, "whod.", 5))
                if (dp->d_ino == 0)
                        continue;
                if (strncmp(dp->d_name, "whod.", 5))
@@ -69,7 +72,7 @@ again:
                        (void) close(f);
                        continue;
                }
                        (void) close(f);
                        continue;
                }
-               if (now - w->wd_recvtime > 5 * 60) {
+               if (down(w,now)) {
                        (void) close(f);
                        continue;
                }
                        (void) close(f);
                        continue;
                }
@@ -94,7 +97,7 @@ again:
        mp = myutmp;
        width = 0;
        for (i = 0; i < nusers; i++) {
        mp = myutmp;
        width = 0;
        for (i = 0; i < nusers; i++) {
-               int j = strlen(mp->myhost) + 1 + strlen(mp->myutmp.ut_line);
+               int j = strlen(mp->myhost) + 1 + strlen(mp->myutmp.out_line);
                if (j > width)
                        width = j;
                mp++;
                if (j > width)
                        width = j;
                mp++;
@@ -102,12 +105,12 @@ again:
        mp = myutmp;
        for (i = 0; i < nusers; i++) {
                char buf[22];
        mp = myutmp;
        for (i = 0; i < nusers; i++) {
                char buf[22];
-               sprintf(buf, "%s:%s", mp->myhost, mp->myutmp.ut_line);
+               (void)sprintf(buf, "%s:%s", mp->myhost, mp->myutmp.out_line);
                printf("%-8.8s %-*s %.12s",
                printf("%-8.8s %-*s %.12s",
-                  mp->myutmp.ut_name,
+                  mp->myutmp.out_name,
                   width,
                   buf,
                   width,
                   buf,
-                  ctime((time_t *)&mp->myutmp.ut_time)+4);
+                  ctime((time_t *)&mp->myutmp.out_time)+4);
                mp->myidle /= 60;
                if (mp->myidle) {
                        if (aflg) {
                mp->myidle /= 60;
                if (mp->myidle) {
                        if (aflg) {
@@ -132,11 +135,11 @@ utmpcmp(u1, u2)
 {
        int rc;
 
 {
        int rc;
 
-       rc = strncmp(u1->myutmp.ut_name, u2->myutmp.ut_name, 8);
+       rc = strncmp(u1->myutmp.out_name, u2->myutmp.out_name, 8);
        if (rc)
                return (rc);
        rc = strncmp(u1->myhost, u2->myhost, 8);
        if (rc)
                return (rc);
        if (rc)
                return (rc);
        rc = strncmp(u1->myhost, u2->myhost, 8);
        if (rc)
                return (rc);
-       return (strncmp(u1->myutmp.ut_line, u2->myutmp.ut_line, 8));
+       return (strncmp(u1->myutmp.out_line, u2->myutmp.out_line, 8));
 }
 }