+++ /dev/null
-# $OpenBSD: Makefile,v 1.2 1996/06/26 05:38:53 deraadt Exp $
-
-PROG= ruptime
-
-.include <bsd.prog.mk>
+++ /dev/null
-.\" $OpenBSD: ruptime.1,v 1.10 2007/05/31 19:20:15 jmc Exp $
-.\"
-.\" Copyright (c) 1983, 1990 The Regents of the University of California.
-.\" 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. 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.
-.\"
-.\" from: @(#)ruptime.1 6.9 (Berkeley) 4/23/91
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt RUPTIME 1
-.Os
-.Sh NAME
-.Nm ruptime
-.Nd show host status of local machines
-.Sh SYNOPSIS
-.Nm ruptime
-.Op Fl alrtu
-.Sh DESCRIPTION
-.Nm
-gives a status line like
-.Xr uptime 1
-for each machine on the local network; these are formed from packets
-broadcast by each host on the network once a minute.
-.Pp
-Machines for which no status report has been received for 11
-minutes are shown as being down.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl a
-Users idle an hour or more are not counted unless the
-.Fl a
-flag is given.
-.It Fl l
-Sort by load average.
-.It Fl r
-Reverses the sort order.
-.It Fl t
-Sort by uptime.
-.It Fl u
-Sort by number of users.
-.El
-.Pp
-The default listing is sorted by host name.
-.Sh FILES
-.Bl -tag -width /var/rwho/whod.* -compact
-.It Pa /var/rwho/whod.*
-data files
-.El
-.Sh SEE ALSO
-.Xr rup 1 ,
-.Xr rwho 1 ,
-.Xr uptime 1 ,
-.Xr rwhod 8
-.Sh HISTORY
-The
-.Nm
-command appeared in
-.Bx 4.2 .
+++ /dev/null
-/* $OpenBSD: ruptime.c,v 1.17 2013/11/27 13:32:02 okan Exp $ */
-
-/*
- * Copyright (c) 1983 The Regents of the University of California.
- * 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. 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/param.h>
-#include <sys/file.h>
-#include <dirent.h>
-#include <protocols/rwhod.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <err.h>
-
-size_t nhosts, hspace = 20;
-struct hs {
- struct whod *hs_wd;
- int hs_nusers;
-} *hs;
-struct whod awhod;
-
-#define ISDOWN(h) (now - (h)->hs_wd->wd_recvtime > 11 * 60)
-#define WHDRSIZE (sizeof (awhod) - sizeof (awhod.wd_we))
-
-time_t now;
-int rflg = 1;
-int hscmp(const void *, const void *);
-int ucmp(const void *, const void *);
-int lcmp(const void *, const void *);
-int tcmp(const void *, const void *);
-char *interval(time_t, char *);
-
-void morehosts(void);
-
-int
-main(int argc, char *argv[])
-{
- extern char *__progname;
- struct hs *hsp;
- struct whod *wd;
- struct whoent *we;
- DIR *dirp;
- struct dirent *dp;
- int aflg, cc, ch, f, i, maxloadav;
- char buf[sizeof(struct whod)];
- int (*cmp)(const void *, const void *) = hscmp;
-
- aflg = 0;
- while ((ch = getopt(argc, argv, "alrut")) != -1)
- switch(ch) {
- case 'a':
- aflg = 1;
- break;
- case 'l':
- cmp = lcmp;
- break;
- case 'r':
- rflg = -1;
- break;
- case 't':
- cmp = tcmp;
- break;
- case 'u':
- cmp = ucmp;
- break;
- default:
- fprintf(stderr, "usage: %s [-alrtu]\n", __progname);
- exit(1);
- }
-
- if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL)
- err(1, "%s", _PATH_RWHODIR);
- morehosts();
- hsp = hs;
- maxloadav = -1;
- while ((dp = readdir(dirp))) {
- if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5))
- continue;
- if ((f = open(dp->d_name, O_RDONLY, 0)) < 0) {
- warn("%s", dp->d_name);
- continue;
- }
- cc = read(f, buf, sizeof(struct whod));
- (void)close(f);
- if (cc < WHDRSIZE)
- continue;
- if (nhosts == hspace) {
- morehosts();
- hsp = hs + nhosts;
- }
- /* NOSTRICT */
- hsp->hs_wd = malloc((size_t)WHDRSIZE);
- wd = (struct whod *)buf;
- bcopy((char *)wd, (char *)hsp->hs_wd, (size_t)WHDRSIZE);
- hsp->hs_nusers = 0;
- for (i = 0; i < 2; i++)
- if (wd->wd_loadav[i] > maxloadav)
- maxloadav = wd->wd_loadav[i];
- we = (struct whoent *)(buf+cc);
- while (--we >= wd->wd_we)
- if (aflg || we->we_idle < 3600)
- hsp->hs_nusers++;
- nhosts++;
- hsp++;
- }
- if (!nhosts)
- errx(1, "no hosts in %s.", _PATH_RWHODIR);
- (void)time(&now);
- qsort((char *)hs, nhosts, sizeof (hs[0]), cmp);
- for (i = 0; i < nhosts; i++) {
- hsp = &hs[i];
- if (ISDOWN(hsp)) {
- (void)printf("%-12.12s%s\n", hsp->hs_wd->wd_hostname,
- interval(now - hsp->hs_wd->wd_recvtime, "down"));
- continue;
- }
- (void)printf(
- "%-12.12s%s, %4d user%s load %*.2f, %*.2f, %*.2f\n",
- hsp->hs_wd->wd_hostname,
- interval((time_t)hsp->hs_wd->wd_sendtime -
- (time_t)hsp->hs_wd->wd_boottime, " up"),
- hsp->hs_nusers,
- hsp->hs_nusers == 1 ? ", " : "s,",
- maxloadav >= 1000 ? 5 : 4,
- hsp->hs_wd->wd_loadav[0] / 100.0,
- maxloadav >= 1000 ? 5 : 4,
- hsp->hs_wd->wd_loadav[1] / 100.0,
- maxloadav >= 1000 ? 5 : 4,
- hsp->hs_wd->wd_loadav[2] / 100.0);
- free((void *)hsp->hs_wd);
- }
- exit(0);
-}
-
-char *
-interval(time_t tval, char *updown)
-{
- static char resbuf[32];
- int days, hours, minutes;
-
- if (tval < 0 || tval > 999*24*60*60) {
- (void)snprintf(resbuf, sizeof resbuf, "%s ??:??", updown);
- return(resbuf);
- }
- minutes = (tval + 59) / 60; /* round to minutes */
- hours = minutes / 60; minutes %= 60;
- days = hours / 24; hours %= 24;
- if (days)
- (void)snprintf(resbuf, sizeof resbuf, "%s %3d+%02d:%02d",
- updown, days, hours, minutes);
- else
- (void)snprintf(resbuf, sizeof resbuf, "%s %2d:%02d",
- updown, hours, minutes);
- return(resbuf);
-}
-
-/* alphabetical comparison */
-int
-hscmp(const void *a1, const void *a2)
-{
- const struct hs *h1 = a1, *h2 = a2;
-
- return(rflg * strcmp(h1->hs_wd->wd_hostname, h2->hs_wd->wd_hostname));
-}
-
-/* load average comparison */
-int
-lcmp(const void *a1, const void *a2)
-{
- const struct hs *h1 = a1, *h2 = a2;
-
- if (ISDOWN(h1))
- if (ISDOWN(h2))
- return(tcmp(a1, a2));
- else
- return(rflg);
- else if (ISDOWN(h2))
- return(-rflg);
- else
- return(rflg *
- (h2->hs_wd->wd_loadav[0] - h1->hs_wd->wd_loadav[0]));
-}
-
-/* number of users comparison */
-int
-ucmp(const void *a1, const void *a2)
-{
- const struct hs *h1 = a1, *h2 = a2;
-
- if (ISDOWN(h1))
- if (ISDOWN(h2))
- return(tcmp(a1, a2));
- else
- return(rflg);
- else if (ISDOWN(h2))
- return(-rflg);
- else
- return(rflg * (h2->hs_nusers - h1->hs_nusers));
-}
-
-/* uptime comparison */
-int
-tcmp(const void *a1, const void *a2)
-{
- const struct hs *h1 = a1, *h2 = a2;
-
- return(rflg * (
- (ISDOWN(h2) ? h2->hs_wd->wd_recvtime - now
- : h2->hs_wd->wd_sendtime - h2->hs_wd->wd_boottime)
- -
- (ISDOWN(h1) ? h1->hs_wd->wd_recvtime - now
- : h1->hs_wd->wd_sendtime - h1->hs_wd->wd_boottime)
- ));
-}
-
-void
-morehosts(void)
-{
- hs = realloc((char *)hs, (hspace *= 2) * sizeof(*hs));
- if (hs == NULL)
- err(1, "realloc");
-}
+++ /dev/null
-# $OpenBSD: Makefile,v 1.2 1996/06/26 05:38:59 deraadt Exp $
-
-PROG= rwho
-
-.include <bsd.prog.mk>
+++ /dev/null
-.\" $OpenBSD: rwho.1,v 1.8 2007/05/31 19:20:15 jmc Exp $
-.\"
-.\" Copyright (c) 1983, 1990 The Regents of the University of California.
-.\" 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. 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.
-.\"
-.\" from: @(#)rwho.1 6.7 (Berkeley) 4/23/91
-.\"
-.Dd $Mdocdate: May 31 2007 $
-.Dt RWHO 1
-.Os
-.Sh NAME
-.Nm rwho
-.Nd who is logged in on local machines
-.Sh SYNOPSIS
-.Nm rwho
-.Op Fl a
-.Sh DESCRIPTION
-The
-.Nm
-command produces output similar to
-.Xr who 1 ,
-but for all machines on the local network.
-If no report has been
-received from a machine for 11 minutes then
-.Nm
-assumes the machine is down, and does not report users last known
-to be logged into that machine.
-.Pp
-If a user hasn't typed to the system for a minute or more, then
-.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
-unless the
-.Fl a
-flag is given.
-.Sh FILES
-.Bl -tag -width /var/rwho/rhowd.* -compact
-.It Pa /var/rwho/whod.*
-information about other machines
-.El
-.Sh SEE ALSO
-.Xr finger 1 ,
-.Xr rup 1 ,
-.Xr ruptime 1 ,
-.Xr rusers 1 ,
-.Xr who 1 ,
-.Xr rwhod 8
-.Sh HISTORY
-The
-.Nm
-command
-appeared in
-.Bx 4.3 .
-.Sh BUGS
-The
-.Nm
-protocol only supports up to eight character login names even though
-.Ox
-supports much longer ones.
-Long login names will be truncated.
-.Pp
-.Nm
-is unwieldy when the number of machines on the local net is large.
+++ /dev/null
-/* $OpenBSD: rwho.c,v 1.19 2014/01/09 05:07:37 martynas Exp $ */
-
-/*
- * Copyright (c) 1983 The Regents of the University of California.
- * 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. 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/file.h>
-#include <dirent.h>
-#include <protocols/rwhod.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <time.h>
-#include <utmp.h>
-#include <vis.h>
-#include <err.h>
-
-DIR *dirp;
-
-struct whod wd;
-#define NUSERS 1000
-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.
- */
-#define down(w,now) ((now) - (w)->wd_recvtime > 11 * 60)
-
-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;
-
- while ((ch = getopt(argc, argv, "a")) != -1)
- switch(ch) {
- case 'a':
- aflg = 1;
- break;
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
- if (argc != 0)
- usage();
-
- if (chdir(_PATH_RWHODIR) || (dirp = opendir(".")) == NULL)
- err(1, _PATH_RWHODIR);
- mp = myutmp;
- (void)time(&now);
- while ((dp = readdir(dirp))) {
- if (dp->d_ino == 0 || strncmp(dp->d_name, "whod.", 5))
- continue;
- 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");
- strncpy(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++) {
- int j = strlen(mp->myhost) + 1 + strlen(mp->myutmp.out_line);
- if (j > width)
- width = j;
- mp++;
- }
- mp = myutmp;
- for (i = 0; i < nusers; i++) {
- char buf[BUFSIZ], vis_user[4 * sizeof(mp->myutmp.out_name) + 1];
- time_t t;
-
- (void)snprintf(buf, sizeof(buf), "%s:%s", mp->myhost,
- mp->myutmp.out_line);
- strnvis(vis_user, mp->myutmp.out_name, sizeof vis_user,
- VIS_CSTYLE);
- t = mp->myutmp.out_time; /* XXX 2038 */
- printf("%-*.*s %-*s %.12s",
- UT_NAMESIZE, UT_NAMESIZE, vis_user, width, buf,
- ctime(&t)+4);
- mp->myidle /= 60;
- if (mp->myidle) {
- if (aflg) {
- if (mp->myidle >= 100*60)
- mp->myidle = 100*60 - 1;
- if (mp->myidle >= 60)
- printf(" %2d", mp->myidle / 60);
- else
- printf(" ");
- } else
- printf(" ");
- printf(":%02d", mp->myidle % 60);
- }
- printf("\n");
- mp++;
- }
- exit(0);
-}
-
-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)
- return (rc);
- rc = strncmp(u1->myhost, u2->myhost, 8);
- 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);
-}