Add rup and rusers. Changes to rwall

This commit is contained in:
brezak 1993-06-03 19:32:26 +00:00
parent e715315160
commit 5f2b367636
8 changed files with 535 additions and 18 deletions

View File

@ -1,6 +1,6 @@
# @(#)Makefile 5.8.1.1 (Berkeley) 5/8/91
#
# $Id: Makefile,v 1.21 1993/05/27 22:15:20 cgd Exp $
# $Id: Makefile,v 1.22 1993/06/03 19:32:26 brezak Exp $
SUBDIR= ar biff basename cal calendar cap_mkdb \
checknr chpass cksum cmp col colcrt colrm column comm compress \
@ -11,7 +11,8 @@ SUBDIR= ar biff basename cal calendar cap_mkdb \
login logname look lorder m4 machine mail make man mesg mkdep mkfifo \
mkstr more msgs netstat newsyslog nfsstat nice nm nohup pagesize \
passwd paste patch printenv printf quota ranlib \
rdist ref renice rev rlogin rpcgen rpcinfo rsh ruptime rwall rwho \
rdist ref renice rev rlogin rpcgen rpcinfo \
rsh rup ruptime rusers rwall rwho \
sccs script sed shar showmount size soelim split strings \
strip su symorder tail talk tcopy tee telnet tftp time \
tip tn3270 touch tput tr true tset tsort tty ul uname unexpand \

13
usr.bin/rup/Makefile Normal file
View File

@ -0,0 +1,13 @@
#
# a makefile for /usr/bin/rup
#
# $Header: /cvsroot/src/usr.bin/rup/Makefile,v 1.1 1993/06/03 19:32:28 brezak Exp $
#
PROG = rup
MAN1= rup.0
DPADD= ${LIBRPCSVC} ${LIBRPC}
LDADD= ${LDARGS} -lrpcsvc -lrpc
.include <bsd.prog.mk>

58
usr.bin/rup/rup.1 Normal file
View File

@ -0,0 +1,58 @@
.\" @(#)rstat.1 2.1 88/08/03 4.0 RPCSRC
.TH RUP 1 "3 August 1988"
.SH NAME
rup \- remote status display
.SH SYNOPSIS
.B rup
.B [host ...]
.SH DESCRIPTION
.LP
.B rup
displays a summary of the current system status of a particular
.BR host
or all hosts on the local network.
The output shows the current time of day, how long the system has
been up,
and the load averages.
The load average numbers give the number of jobs in the run queue
averaged over 1, 5 and 15 minutes.
.PP
The
.B rpc.rstatd(8)
daemon must be running on the remote host for this command to
work.
.B rup
uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x.
.SH EXAMPLE
.RS
.ft B
.nf
example% rup otherhost
otherhost 7:36am up 6 days, 16:45, load average: 0.20, 0.23, 0.18
example%
.ft R
.fi
.RE
.SH DIAGNOSTICS
.LP
rup: RPC: Program not registered
.IP
The
.B rstat_svc
daemon has not been started on the remote host.
.LP
rup: RPC: Timed out
.IP
A communication error occurred. Either the network is
excessively congested, or the
.B rstat_svc
daemon has terminated on the remote host.
.LP
rup: RPC: Port mapper failure - RPC: Timed out
.IP
The remote host is not running the portmapper (see
.BR portmap(8) ),
and cannot accomodate any RPC-based services. The host may be down.
.SH "SEE ALSO"
.BR portmap (8),
.BR rpc.rstatd (8)

216
usr.bin/rup/rup.c Normal file
View File

@ -0,0 +1,216 @@
/*-
* Copyright (c) 1993, John Brezak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netdb.h>
#include <rpc/rpc.h>
#include <arpa/inet.h>
#include <rpcsvc/rstat.h>
#define HOST_WIDTH 12
char *argv0;
struct host_list {
struct host_list *next;
struct in_addr addr;
} *hosts;
int search_host(struct in_addr addr)
{
struct host_list *hp;
if (!hosts)
return(0);
for (hp = hosts; hp != NULL; hp = hp->next) {
if (hp->addr.s_addr == addr.s_addr)
return(1);
}
return(0);
}
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);
}
hp->addr.s_addr = addr.s_addr;
hp->next = hosts;
hosts = hp;
}
rstat_reply(char *replyp, struct sockaddr_in *raddrp)
{
struct tm *tmp_time;
struct tm host_time;
struct tm host_uptime;
char days_buf[16];
char hours_buf[16];
struct hostent *hp;
char *host;
statstime *host_stat = (statstime *)replyp;
if (search_host(raddrp->sin_addr))
return(0);
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
sizeof(struct in_addr), AF_INET);
if (hp)
host = hp->h_name;
else
host = inet_ntoa(raddrp->sin_addr);
printf("%-*.*s\t", HOST_WIDTH, HOST_WIDTH, host);
tmp_time = localtime((time_t *)&host_stat->curtime.tv_sec);
host_time = *tmp_time;
host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
tmp_time = gmtime((time_t *)&host_stat->curtime.tv_sec);
host_uptime = *tmp_time;
if (host_uptime.tm_yday != 0)
sprintf(days_buf, "%3d day%s, ", host_uptime.tm_yday,
(host_uptime.tm_yday > 1) ? "s" : "");
else
days_buf[0] = '\0';
if (host_uptime.tm_hour != 0)
sprintf(hours_buf, "%2d:%02d, ",
host_uptime.tm_hour, host_uptime.tm_min);
else
if (host_uptime.tm_min != 0)
sprintf(hours_buf, "%2d mins, ", host_uptime.tm_min);
else
hours_buf[0] = '\0';
printf(" %2d:%02d%cm up %9.9s%9.9s load average: %.2f %.2f %.2f\n",
(host_time.tm_hour > 12) ? host_time.tm_hour - 12
: host_time.tm_hour,
host_time.tm_min,
(host_time.tm_hour >= 12) ? 'p'
: 'a',
days_buf,
hours_buf,
(double)host_stat->avenrun[0]/FSCALE,
(double)host_stat->avenrun[1]/FSCALE,
(double)host_stat->avenrun[2]/FSCALE);
remember_host(raddrp->sin_addr);
return(0);
}
onehost(char *host)
{
CLIENT *rstat_clnt;
statstime host_stat;
struct sockaddr_in addr;
struct hostent *hp;
hp = gethostbyname(host);
if (hp == NULL) {
fprintf(stderr, "%s: unknown host \"%s\"\n",
argv0, host);
return(-1);
}
rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
if (rstat_clnt == NULL) {
fprintf(stderr, "%s: %s %s", argv0, host, clnt_spcreateerror(""));
return(-1);
}
bzero((char *)&host_stat, sizeof(host_stat));
if (clnt_call(rstat_clnt, RSTATPROC_STATS, xdr_void, NULL, xdr_statstime, &host_stat, NULL) != RPC_SUCCESS) {
fprintf(stderr, "%s: %s: %s\n", argv0, host, clnt_sperror(rstat_clnt));
return(-1);
}
addr.sin_addr.s_addr = *(int *)hp->h_addr;
rstat_reply((char *)&host_stat, &addr);
}
allhosts()
{
statstime host_stat;
enum clnt_stat clnt_stat;
clnt_stat = clnt_broadcast(RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS,
xdr_void, NULL,
xdr_statstime, &host_stat, rstat_reply);
if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) {
fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat));
exit(1);
}
}
usage()
{
fprintf(stderr, "Usage: %s [hosts ...]\n", argv0);
exit(1);
}
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, "?")) != -1)
switch (ch) {
default:
usage();
/*NOTREACHED*/
}
if (argc == optind)
allhosts();
else {
for (; optind < argc; optind++)
(void) onehost(argv[optind]);
}
exit(0);
}

13
usr.bin/rusers/Makefile Normal file
View File

@ -0,0 +1,13 @@
#
# a makefile for /usr/bin/rusers
#
# $Header: /cvsroot/src/usr.bin/rusers/Makefile,v 1.1 1993/06/03 19:32:33 brezak Exp $
#
PROG = rusers
NOMAN= noman
DPADD= ${LIBRPCSVC} ${LIBRPC}
LDADD= ${LDARGS} -lrpcsvc -lrpc
.include <bsd.prog.mk>

226
usr.bin/rusers/rusers.c Normal file
View File

@ -0,0 +1,226 @@
/*-
* Copyright (c) 1993, John Brezak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <strings.h>
#include <rpc/rpc.h>
#include <arpa/inet.h>
#include <rpcsvc/rnusers.h>
#define MAX_INT 0x7fffffff
#define HOST_WIDTH 12
#define LINE_WIDTH 15
char *argv0;
int longopt;
int allopt;
struct host_list {
struct host_list *next;
struct in_addr addr;
} *hosts;
int search_host(struct in_addr addr)
{
struct host_list *hp;
if (!hosts)
return(0);
for (hp = hosts; hp != NULL; hp = hp->next) {
if (hp->addr.s_addr == addr.s_addr)
return(1);
}
return(0);
}
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);
}
hp->addr.s_addr = addr.s_addr;
hp->next = hosts;
hosts = hp;
}
rusers_reply(char *replyp, struct sockaddr_in *raddrp)
{
int x, idle;
char date[128], idle_time[128], remote[128];
struct hostent *hp;
utmpidlearr *up = (utmpidlearr *)replyp;
char *host;
if (search_host(raddrp->sin_addr))
return(0);
if (!allopt && !up->utmpidlearr_len)
return(0);
hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
sizeof(struct in_addr), AF_INET);
if (hp)
host = hp->h_name;
else
host = inet_ntoa(raddrp->sin_addr);
if (!longopt)
printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host);
for (x = 0; x < up->utmpidlearr_len; x++) {
strcpy(date, &(ctime((time_t *)&(up->utmpidlearr_val[x].ui_utmp.ut_time))[4]));
idle = up->utmpidlearr_val[x].ui_idle;
sprintf(idle_time, " :%02d", idle);
if (idle == 0)
strcpy(idle_time, "");
if (idle > 60)
sprintf(idle_time, "%d:%02d", idle/60, idle%60);
if (idle == MAX_INT)
strcpy(idle_time, "??");
strcpy(remote, up->utmpidlearr_val[x].ui_utmp.ut_host);
if (strlen(remote) != 0)
sprintf(remote, "(%.16s)", up->utmpidlearr_val[x].ui_utmp.ut_host);
if (longopt)
printf("%-8.8s %*.*s:%-*.*s %-12.12s %6s %.18s\n",
up->utmpidlearr_val[x].ui_utmp.ut_name,
HOST_WIDTH, HOST_WIDTH, host,
LINE_WIDTH, LINE_WIDTH, up->utmpidlearr_val[x].ui_utmp.ut_line,
date,
idle_time,
remote
);
else
printf("%s ",
up->utmpidlearr_val[x].ui_utmp.ut_name);
}
if (!longopt)
putchar('\n');
remember_host(raddrp->sin_addr);
return(0);
}
onehost(char *host)
{
utmpidlearr up;
CLIENT *rusers_clnt;
struct sockaddr_in addr;
struct hostent *hp;
hp = gethostbyname(host);
if (hp == NULL) {
fprintf(stderr, "%s: unknown host \"%s\"\n",
argv0, host);
exit(1);
}
rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
if (rusers_clnt == NULL) {
clnt_pcreateerror(argv0);
exit(1);
}
bzero((char *)&up, sizeof(up));
if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, NULL) != RPC_SUCCESS) {
clnt_perror(rusers_clnt, argv0);
exit(1);
}
addr.sin_addr.s_addr = *(int *)hp->h_addr;
rusers_reply((char *)&up, &addr);
}
allhosts()
{
utmpidlearr up;
enum clnt_stat clnt_stat;
bzero((char *)&up, sizeof(up));
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);
}
}
usage()
{
fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0);
exit(1);
}
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) {
case 'a':
allopt++;
break;
case 'l':
longopt++;
break;
default:
usage();
/*NOTREACHED*/
}
if (argc == optind)
allhosts();
else {
for (; optind < argc; optind++)
(void) onehost(argv[optind]);
}
exit(0);
}

View File

@ -1,23 +1,13 @@
#
# a makefile for /usr/bin/rwall
#
# $Header: /cvsroot/src/usr.bin/rwall/Makefile,v 1.1 1993/04/04 20:15:30 cgd Exp $
# $Header: /cvsroot/src/usr.bin/rwall/Makefile,v 1.2 1993/06/03 19:32:37 brezak Exp $
#
PROG = rwall
SRCS = rwall.c rwall_clnt.c
CLEANFILES += rwall_clnt.c
NOMAN= noman
RPCCOM = rpcgen
RPCDLOC= /usr/include
RPCDESC= rpcsvc/rwall.x
DPADD= ${LIBRPC}
LDADD= -lrpc
rwall_clnt.c: ${RPCDLOC}/${RPCDESC}
@echo generating $@...
@PWD=`pwd` ; cd ${RPCDLOC} ; ${RPCCOM} -l ${RPCDESC} -o $$PWD/$@
DPADD= ${LIBRPCSVC} ${LIBRPC}
LDADD= ${LDARGS} -lrpcsvc -lrpc
.include <bsd.prog.mk>

View File

@ -40,7 +40,7 @@ char copyright[] =
#ifndef lint
static char sccsid[] = "@(#)wall.c 5.14 (Berkeley) 3/2/91";
static char rcsid[] = "$Header: /cvsroot/src/usr.bin/rwall/rwall.c,v 1.2 1993/04/26 14:43:24 mycroft Exp $";
static char rcsid[] = "/b/source/CVS/src/usr.bin/rwall/rwall.c,v 1.2 1993/04/26 14:43:24 mycroft Exp";
#endif /* not lint */
/*
@ -69,7 +69,7 @@ main(argc, argv)
int argc;
char **argv;
{
char *wallhost;
char *wallhost, res;
CLIENT *cl;
if ((argc < 2) || (argc > 3)) {
@ -96,7 +96,7 @@ main(argc, argv)
exit(1);
}
if (wallproc_wall_1(&mbuf, cl) == NULL) {
if (clnt_call(cl, WALLPROC_WALL, xdr_wrapstring, &mbuf, xdr_void, &res, NULL) != RPC_SUCCESS) {
/*
* An error occurred while calling the server.
* Print error message and die.