added depend label
[unix-history] / usr / src / usr.bin / rwho / rwho.c
index 25ef415..c71b64a 100644 (file)
@@ -1,13 +1,25 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rwho.c     4.6 83/05/25";
-#endif
+static char sccsid[] = "@(#)rwho.c     5.2 (Berkeley) %G%";
+#endif not lint
 
 #include <sys/param.h>
 #include <stdio.h>
 
 #include <sys/param.h>
 #include <stdio.h>
-#include <dir.h>
-#include <rwhod.h>
+#include <sys/dir.h>
+#include <protocols/rwhod.h>
 
 
-DIR    *etc;
+DIR    *dirp;
 
 struct whod wd;
 int    utmpcmp();
 
 struct whod wd;
 int    utmpcmp();
@@ -21,6 +33,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 +65,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 +84,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;
                }
@@ -100,8 +116,8 @@ again:
        }
        mp = myutmp;
        for (i = 0; i < nusers; i++) {
        }
        mp = myutmp;
        for (i = 0; i < nusers; i++) {
-               char buf[22];
-               sprintf(buf, "%s:%s", mp->myhost, mp->myutmp.out_line);
+               char buf[BUFSIZ];
+               (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,