Wait 11 minutes before deciding a machine is down (same as ruptime).
[unix-history] / usr / src / usr.bin / rwho / rwho.c
index 25ef415..805c21e 100644 (file)
@@ -1,13 +1,13 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rwho.c     4.6 83/05/25";
+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 <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();
@@ -21,6 +21,10 @@ int  nusers;
 
 #define        WHDRSIZE        (sizeof (wd) - sizeof (wd.wd_we))
 #define        RWHODIR         "/usr/spool/rwho"
 
 #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;
@@ -49,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))
@@ -68,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;
                }
@@ -101,7 +105,7 @@ 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.out_line);
+               (void)sprintf(buf, "%s:%s", mp->myhost, mp->myutmp.out_line);
                printf("%-8.8s %-*s %.12s",
                   mp->myutmp.out_name,
                   width,
                printf("%-8.8s %-*s %.12s",
                   mp->myutmp.out_name,
                   width,