=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rwho/Attic/rwho.c,v retrieving revision 1.12 retrieving revision 1.13 diff -c -r1.12 -r1.13 *** src/usr.bin/rwho/Attic/rwho.c 2001/02/17 17:35:14 1.12 --- src/usr.bin/rwho/Attic/rwho.c 2001/09/27 18:38:58 1.13 *************** *** 1,4 **** ! /* $OpenBSD: rwho.c,v 1.12 2001/02/17 17:35:14 pjanzen Exp $ */ /* * Copyright (c) 1983 The Regents of the University of California. --- 1,4 ---- ! /* $OpenBSD: rwho.c,v 1.13 2001/09/27 18:38:58 millert Exp $ */ /* * Copyright (c) 1983 The Regents of the University of California. *************** *** 34,47 **** */ #ifndef lint ! char copyright[] = "@(#) Copyright (c) 1983 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint ! /*static char sccsid[] = "from: @(#)rwho.c 5.5 (Berkeley) 6/1/90";*/ ! static char rcsid[] = "$OpenBSD: rwho.c,v 1.12 2001/02/17 17:35:14 pjanzen Exp $"; #endif /* not lint */ #include --- 34,50 ---- */ #ifndef lint ! static const char copyright[] = "@(#) Copyright (c) 1983 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint ! #if 0 ! static const char sccsid[] = "from: @(#)rwho.c 5.5 (Berkeley) 6/1/90"; ! #else ! static const char rcsid[] = "$OpenBSD: rwho.c,v 1.13 2001/09/27 18:38:58 millert Exp $"; ! #endif #endif /* not lint */ #include *************** *** 65,77 **** struct myutmp { char myhost[MAXHOSTNAMELEN]; int myidle; ! struct outmp myutmp; } myutmp[NUSERS]; int nusers; ! int utmpcmp __P((struct myutmp *, struct myutmp *)); ! #define WHDRSIZE (sizeof (wd) - sizeof (wd.wd_we)) /* * this macro should be shared with ruptime. */ --- 68,85 ---- struct myutmp { char myhost[MAXHOSTNAMELEN]; int myidle; ! struct { ! char out_line[9]; /* tty name + NUL */ ! char out_name[9]; /* user id + NUL */ ! int32_t out_time; /* time on */ ! } myutmp; } myutmp[NUSERS]; int nusers; ! int utmpcmp(const void *, const void *); ! __dead void usage(void); ! #define WHDRSIZE (sizeof(wd) - sizeof(wd.wd_we)) /* * this macro should be shared with ruptime. */ *************** *** 80,105 **** time_t now; int aflg; - void - usage() - { - fprintf(stderr, "usage: rwho [-a]\n"); - exit(1); - } - int ! main(argc, argv) ! int argc; ! char **argv; { - extern char *optarg; - extern int optind; int ch; struct dirent *dp; int cc, width; ! register struct whod *w = &wd; ! register struct whoent *we; ! register struct myutmp *mp; int f, n, i; int nhosts = 0; --- 88,102 ---- time_t now; int aflg; int ! main(int argc, char **argv) { int ch; struct dirent *dp; int cc, width; ! struct whod *w = &wd; ! struct whoent *we; ! struct myutmp *mp; int f, n, i; int nhosts = 0; *************** *** 108,114 **** case 'a': aflg = 1; break; - case '?': default: usage(); } --- 105,110 ---- *************** *** 117,126 **** if (argc != 0) usage(); ! if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL) { ! perror(_PATH_RWHODIR); ! exit(1); ! } mp = myutmp; (void)time(&now); while ((dp = readdir(dirp))) { --- 113,120 ---- if (argc != 0) usage(); ! if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL) ! err(1, _PATH_RWHODIR); mp = myutmp; (void)time(&now); while ((dp = readdir(dirp))) { *************** *** 129,165 **** f = open(dp->d_name, O_RDONLY); if (f < 0) continue; ! cc = read(f, (char *)&wd, sizeof (struct whod)); if (cc < WHDRSIZE) { ! (void) close(f); continue; } nhosts++; if (down(w,now)) { ! (void) close(f); continue; } cc -= WHDRSIZE; we = w->wd_we; ! for (n = cc / sizeof (struct whoent); n > 0; n--) { if (aflg == 0 && we->we_idle >= 60*60) { we++; continue; } if (nusers >= NUSERS) errx(1, "too many users"); ! mp->myutmp = we->we_utmp; mp->myidle = we->we_idle; ! (void) strncpy(mp->myhost, w->wd_hostname, sizeof(mp->myhost)-1); mp->myhost[sizeof(mp->myhost)-1] = '\0'; nusers++; we++; mp++; } ! (void) close(f); } if (nhosts == 0) errx(0, "no hosts in %s.", _PATH_RWHODIR); ! qsort((char *)myutmp, nusers, sizeof (struct myutmp), ! (int (*)())utmpcmp); mp = myutmp; width = 0; for (i = 0; i < nusers; i++) { --- 123,169 ---- f = open(dp->d_name, O_RDONLY); if (f < 0) continue; ! cc = read(f, &wd, sizeof(struct whod)); if (cc < WHDRSIZE) { ! (void)close(f); continue; } nhosts++; if (down(w,now)) { ! (void)close(f); continue; } cc -= WHDRSIZE; we = w->wd_we; ! for (n = cc / sizeof(struct whoent); n > 0; n--) { if (aflg == 0 && we->we_idle >= 60*60) { we++; continue; } if (nusers >= NUSERS) errx(1, "too many users"); ! memcpy(mp->myhost, w->wd_hostname, sizeof(mp->myhost)-1); mp->myhost[sizeof(mp->myhost)-1] = '\0'; + mp->myidle = we->we_idle; + /* + * Copy we->we_utmp by hand since the name and line + * variables in myutmp have room for NUL (unlike outmp). + */ + memcpy(mp->myutmp.out_line, we->we_utmp.out_line, + sizeof(mp->myutmp.out_line)-1); + mp->myutmp.out_line[sizeof(mp->myutmp.out_line)-1] = 0; + memcpy(mp->myutmp.out_name, we->we_utmp.out_name, + sizeof(mp->myutmp.out_name)-1); + mp->myutmp.out_name[sizeof(mp->myutmp.out_name)-1] = 0; + mp->myutmp.out_time = we->we_utmp.out_time; nusers++; we++; mp++; } ! (void)close(f); } if (nhosts == 0) errx(0, "no hosts in %s.", _PATH_RWHODIR); ! qsort(myutmp, nusers, sizeof(struct myutmp), utmpcmp); mp = myutmp; width = 0; for (i = 0; i < nusers; i++) { *************** *** 170,182 **** } mp = myutmp; for (i = 0; i < nusers; i++) { ! char buf[BUFSIZ], vis_user[4*UT_NAMESIZE]; ! (void)snprintf(buf, sizeof buf, "%s:%s", mp->myhost, mp->myutmp.out_line); strvis(vis_user, mp->myutmp.out_name, VIS_CSTYLE); printf("%-*.*s %-*s %.12s", ! UT_NAMESIZE, UT_NAMESIZE, vis_user, ! width, buf, ctime((time_t *)&mp->myutmp.out_time)+4); mp->myidle /= 60; if (mp->myidle) { --- 174,186 ---- } mp = myutmp; for (i = 0; i < nusers; i++) { ! char buf[BUFSIZ], vis_user[4 * sizeof(mp->myutmp.out_name)]; ! ! (void)snprintf(buf, sizeof(buf), "%s:%s", mp->myhost, mp->myutmp.out_line); strvis(vis_user, mp->myutmp.out_name, VIS_CSTYLE); printf("%-*.*s %-*s %.12s", ! UT_NAMESIZE, UT_NAMESIZE, vis_user, width, buf, ctime((time_t *)&mp->myutmp.out_time)+4); mp->myidle /= 60; if (mp->myidle) { *************** *** 198,207 **** } int ! utmpcmp(u1, u2) ! struct myutmp *u1, *u2; { int rc; rc = strncmp(u1->myutmp.out_name, u2->myutmp.out_name, 8); if (rc) --- 202,212 ---- } int ! utmpcmp(const void *v1, const void *v2) { int rc; + const struct myutmp *u1 = (struct myutmp *)v1; + const struct myutmp *u2 = (struct myutmp *)v2; rc = strncmp(u1->myutmp.out_name, u2->myutmp.out_name, 8); if (rc) *************** *** 210,213 **** --- 215,227 ---- if (rc) return (rc); return (strncmp(u1->myutmp.out_line, u2->myutmp.out_line, 8)); + } + + void + usage(void) + { + extern char *__progname; + + fprintf(stderr, "usage: %s [-a]\n", __progname); + exit(1); }