1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)rwho.c	5.2 (Berkeley) 6/18/85";
  15: #endif not lint
  16: 
  17: #include <sys/param.h>
  18: #include <stdio.h>
  19: #include <sys/dir.h>
  20: #include <protocols/rwhod.h>
  21: 
  22: DIR *dirp;
  23: 
  24: struct  whod wd;
  25: int utmpcmp();
  26: #define NUSERS  500
  27: struct  myutmp {
  28:     char    myhost[32];
  29:     long    myidle;
  30:     struct  outmp myutmp;
  31: } myutmp[NUSERS];
  32: int nusers;
  33: 
  34: #define WHDRSIZE    (sizeof (wd) - sizeof (wd.wd_we))
  35: #define RWHODIR     "/usr/spool/rwho"
  36: /*
  37:  * this macro should be shared with ruptime.
  38:  */
  39: #define down(w,now) ((now) - (w)->wd_recvtime > 11L * 60L)
  40: 
  41: char    *ctime(), *strcpy();
  42: time_t  now;
  43: int aflg;
  44: 
  45: main(argc, argv)
  46:     int argc;
  47:     char **argv;
  48: {
  49:     struct direct *dp;
  50:     int cc, width;
  51:     register struct whod *w = &wd;
  52:     register struct whoent *we;
  53:     register struct myutmp *mp;
  54:     int f, n, i;
  55: 
  56:     argc--, argv++;
  57: again:
  58:     if (argc > 0 && !strcmp(argv[0], "-a")) {
  59:         argc--, argv++;
  60:         aflg++;
  61:         goto again;
  62:     }
  63:     (void) time(&now);
  64:     if (chdir(RWHODIR) < 0) {
  65:         perror(RWHODIR);
  66:         exit(1);
  67:     }
  68:     dirp = opendir(".");
  69:     if (dirp == NULL) {
  70:         perror(RWHODIR);
  71:         exit(1);
  72:     }
  73:     mp = myutmp;
  74:     while (dp = readdir(dirp)) {
  75:         if (dp->d_ino == 0)
  76:             continue;
  77:         if (strncmp(dp->d_name, "whod.", 5))
  78:             continue;
  79:         f = open(dp->d_name, 0);
  80:         if (f < 0)
  81:             continue;
  82:         cc = read(f, (char *)&wd, sizeof (struct whod));
  83:         if (cc < WHDRSIZE) {
  84:             (void) close(f);
  85:             continue;
  86:         }
  87:         if (down(w,now)) {
  88:             (void) close(f);
  89:             continue;
  90:         }
  91:         cc -= WHDRSIZE;
  92:         we = w->wd_we;
  93:         for (n = cc / sizeof (struct whoent); n > 0; n--) {
  94:             if (aflg == 0 && we->we_idle >= 60L*60L) {
  95:                 we++;
  96:                 continue;
  97:             }
  98:             if (nusers >= NUSERS) {
  99:                 printf("too many users\n");
 100:                 exit(1);
 101:             }
 102:             mp->myutmp = we->we_utmp; mp->myidle = we->we_idle;
 103:             (void) strcpy(mp->myhost, w->wd_hostname);
 104:             nusers++; we++; mp++;
 105:         }
 106:         (void) close(f);
 107:     }
 108:     qsort((char *)myutmp, nusers, sizeof (struct myutmp), utmpcmp);
 109:     mp = myutmp;
 110:     width = 0;
 111:     for (i = 0; i < nusers; i++) {
 112:         int j = strlen(mp->myhost) + 1 + strlen(mp->myutmp.out_line);
 113:         if (j > width)
 114:             width = j;
 115:         mp++;
 116:     }
 117:     mp = myutmp;
 118:     for (i = 0; i < nusers; i++) {
 119:         char buf[BUFSIZ];
 120:         (void)sprintf(buf, "%s:%s", mp->myhost, mp->myutmp.out_line);
 121:         printf("%-8.8s %-*s %.12s",
 122:            mp->myutmp.out_name,
 123:            width,
 124:            buf,
 125:            ctime((time_t *)&mp->myutmp.out_time)+4);
 126:         mp->myidle /= 60L;
 127:         if (mp->myidle) {
 128:             if (aflg) {
 129:                 if (mp->myidle >= 100L*60L)
 130:                     mp->myidle = 100L*60L - 1;
 131:                 if (mp->myidle >= 60L)
 132:                     printf(" %2D", mp->myidle / 60L);
 133:                 else
 134:                     printf("   ");
 135:             } else
 136:                 printf(" ");
 137:             printf(":%02D", mp->myidle % 60L);
 138:         }
 139:         printf("\n");
 140:         mp++;
 141:     }
 142:     exit(0);
 143: }
 144: 
 145: utmpcmp(u1, u2)
 146:     struct myutmp *u1, *u2;
 147: {
 148:     int rc;
 149: 
 150:     rc = strncmp(u1->myutmp.out_name, u2->myutmp.out_name, 8);
 151:     if (rc)
 152:         return (rc);
 153:     rc = strncmp(u1->myhost, u2->myhost, 8);
 154:     if (rc)
 155:         return (rc);
 156:     return (strncmp(u1->myutmp.out_line, u2->myutmp.out_line, 8));
 157: }

Defined functions

main defined in line 45; never used
utmpcmp defined in line 145; used 2 times

Defined variables

aflg defined in line 43; used 3 times
copyright defined in line 8; never used
dirp defined in line 22; used 3 times
myutmp defined in line 31; used 14 times
now defined in line 42; used 4 times
nusers defined in line 32; used 5 times
sccsid defined in line 14; never used
wd defined in line 24; used 4 times

Defined struct's

myutmp defined in line 27; used 6 times

Defined macros

NUSERS defined in line 26; used 2 times
RWHODIR defined in line 35; used 3 times
WHDRSIZE defined in line 34; used 2 times
down defined in line 39; used 1 times
  • in line 87
Last modified: 1988-02-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2959
Valid CSS Valid XHTML 1.0 Strict