Remove argv0, cosmetic in usage(), use err(3), add Xr to rwho(1) and users(1).

This commit is contained in:
Philippe Charnier 1997-08-08 12:12:54 +00:00
parent 880fdc3dd9
commit 223884e545
2 changed files with 33 additions and 38 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)rusers.1 6.7 (Berkeley) 4/23/91
.\" $Id$
.\" $Id: rusers.1,v 1.5 1997/02/22 19:56:52 peter Exp $
.\"
.Dd April 23, 1991
.Dt RUSERS 1
@ -44,7 +44,7 @@
.Op Ar host ...
.Sh DESCRIPTION
The
.Nm rusers
.Nm
command produces output similar to
.Xr who ,
but for the list of hosts or all machines on the local
@ -80,12 +80,14 @@ The remote host is not running the portmapper (see
and cannot accommodate any RPC-based services. The host may be down.
.El
.Sh SEE ALSO
.Xr rwho 1 ,
.Xr users 1 ,
.Xr who 1 ,
.Xr portmap 8 ,
.Xr rpc.rusersd 8
.Sh HISTORY
The
.Nm rusers
.Nm
command
appeared in
.Em Sun-OS .

View File

@ -32,23 +32,27 @@
*/
#ifndef lint
static char rcsid[] = "$Id$";
static const char rcsid[] =
"$Id: rusers.c,v 1.5 1997/02/22 19:56:52 peter Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <arpa/inet.h>
#include <rpcsvc/rnusers.h>
#define MAX_INT 0x7fffffff
#define HOST_WIDTH 20
#define LINE_WIDTH 15
char *argv0;
int longopt;
int allopt;
@ -58,7 +62,8 @@ struct host_list {
struct in_addr addr;
} *hosts;
int search_host(struct in_addr addr)
int
search_host(struct in_addr addr)
{
struct host_list *hp;
@ -72,19 +77,19 @@ int search_host(struct in_addr addr)
return(0);
}
void remember_host(struct in_addr addr)
void
remember_host(struct in_addr addr)
{
struct host_list *hp;
if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) {
fprintf(stderr, "%s: no memory.\n", argv0);
exit(1);
}
if (!(hp = (struct host_list *)malloc(sizeof(struct host_list))))
errx(1, "no memory");
hp->addr.s_addr = addr.s_addr;
hp->next = hosts;
hosts = hp;
}
int
rusers_reply(char *replyp, struct sockaddr_in *raddrp)
{
int x, idle;
@ -164,6 +169,7 @@ rusers_reply(char *replyp, struct sockaddr_in *raddrp)
return(0);
}
void
onehost(char *host)
{
utmpidlearr up;
@ -173,29 +179,23 @@ onehost(char *host)
struct timeval tv;
hp = gethostbyname(host);
if (hp == NULL) {
fprintf(stderr, "%s: unknown host \"%s\"\n",
argv0, host);
exit(1);
}
if (hp == NULL)
errx(1, "unknown host \"%s\"", host);
rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
if (rusers_clnt == NULL) {
clnt_pcreateerror(argv0);
exit(1);
}
if (rusers_clnt == NULL)
errx(1, "%s", clnt_spcreateerror(""));
bzero((char *)&up, sizeof(up));
tv.tv_sec = 15; /* XXX ?? */
tv.tv_usec = 0;
if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, tv) != RPC_SUCCESS) {
clnt_perror(rusers_clnt, argv0);
exit(1);
}
if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, tv) != RPC_SUCCESS)
errx(1, "%s", clnt_sperror(rusers_clnt, ""));
addr.sin_addr.s_addr = *(int *)hp->h_addr;
rusers_reply((char *)&up, &addr);
}
void
allhosts()
{
utmpidlearr up;
@ -205,28 +205,21 @@ allhosts()
clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES,
xdr_void, NULL,
xdr_utmpidlearr, &up, rusers_reply);
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
exit(1);
}
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT)
errx(1, "%s", clnt_sperrno(clnt_stat));
}
static void
usage()
{
fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);
fprintf(stderr, "usage: rusers [-la] [hosts ...]\n");
exit(1);
}
int
main(int argc, char *argv[])
{
int ch;
extern int optind;
if (!(argv0 = rindex(argv[0], '/')))
argv0 = argv[0];
else
argv0++;
while ((ch = getopt(argc, argv, "al")) != -1)
switch (ch) {