Use err(3). Add usage() and prototypes. Add Xr to who(1).

This commit is contained in:
Philippe Charnier 1997-08-08 12:20:24 +00:00
parent 3f9b28f9d0
commit 157f1c6c00
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27978
2 changed files with 34 additions and 20 deletions

View File

@ -38,26 +38,26 @@
.Nm rwho
.Nd who is logged in on local machines
.Sh SYNOPSIS
.Nm rwho
.Nm
.Op Fl a
.Sh DESCRIPTION
The
.Nm rwho
.Nm
command produces output similar to
.Xr who ,
but for all machines on the local network.
If no report has been
received from a machine for 5 minutes then
.Nm rwho
.Nm
assumes the machine is down, and does not report users last known
to be logged into that machine.
.Pp
If a users hasn't typed to the system for a minute or more, then
.Nm rwho
.Nm
reports this idle time. If a user hasn't typed to the system for
an hour or more, then
the user will be omitted from the output of
.Nm rwho
.Nm
unless the
.Fl a
flag is given.
@ -68,10 +68,11 @@ information about other machines
.El
.Sh SEE ALSO
.Xr ruptime 1 ,
.Xr who 1 ,
.Xr rwhod 8
.Sh HISTORY
The
.Nm rwho
.Nm
command
appeared in
.Bx 4.3 .

View File

@ -32,23 +32,30 @@
*/
#ifndef lint
static char copyright[] =
static const char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)rwho.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/param.h>
#include <sys/file.h>
#include <protocols/rwhod.h>
#include <dirent.h>
#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <utmp.h>
DIR *dirp;
@ -72,12 +79,14 @@ int nusers;
time_t now;
int aflg;
static void usage __P((void));
int utmpcmp __P((struct myutmp *, struct myutmp *));
int
main(argc, argv)
int argc;
char **argv;
{
extern char *optarg;
extern int optind;
int ch;
struct dirent *dp;
int cc, width;
@ -95,16 +104,13 @@ main(argc, argv)
break;
case '?':
default:
fprintf(stderr, "usage: rwho [-a]\n");
exit(1);
usage();
}
if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL) {
perror(_PATH_RWHODIR);
exit(1);
}
if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL)
err(1, "%s", _PATH_RWHODIR);
mp = myutmp;
(void)time(&now);
while (dp = readdir(dirp)) {
while ((dp = readdir(dirp))) {
if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5))
continue;
f = open(dp->d_name, O_RDONLY);
@ -126,10 +132,8 @@ main(argc, argv)
we++;
continue;
}
if (nusers >= NUSERS) {
printf("too many users\n");
exit(1);
}
if (nusers >= NUSERS)
errx(1, "too many users");
mp->myutmp = we->we_utmp; mp->myidle = we->we_idle;
(void) strcpy(mp->myhost, w->wd_hostname);
nusers++; we++; mp++;
@ -177,6 +181,15 @@ main(argc, argv)
exit(0);
}
static void
usage()
{
fprintf(stderr, "usage: rwho [-a]\n");
exit(1);
}
int
utmpcmp(u1, u2)
struct myutmp *u1, *u2;
{