dcb2d11b6917507e598bb884e8a27f2acfdb070e
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)ruptime.c 8.1 (Berkeley) %G%";
#include <protocols/rwhod.h>
size_t nhosts
, hspace
= 20;
#define ISDOWN(h) (now - (h)->hs_wd->wd_recvtime > 11 * 60)
#define WHDRSIZE (sizeof (awhod) - sizeof (awhod.wd_we))
int hscmp(), ucmp(), lcmp(), tcmp();
register struct whod
*wd
;
register struct whoent
*we
;
int aflg
, cc
, ch
, f
, i
, maxloadav
;
char buf
[sizeof(struct whod
)];
while ((ch
= getopt(argc
, argv
, "alrut")) != EOF
)
(void)fprintf(stderr
, "usage: ruptime [-alrut]\n");
if (chdir(_PATH_RWHODIR
) || (dirp
= opendir(".")) == NULL
) {
(void)fprintf(stderr
, "ruptime: %s: %s.\n",
_PATH_RWHODIR
, strerror(errno
));
while (dp
= readdir(dirp
)) {
if (dp
->d_ino
== 0 || strncmp(dp
->d_name
, "whod.", 5))
if ((f
= open(dp
->d_name
, O_RDONLY
, 0)) < 0) {
(void)fprintf(stderr
, "ruptime: %s: %s\n",
dp
->d_name
, strerror(errno
));
cc
= read(f
, buf
, sizeof(struct whod
));
hsp
->hs_wd
= malloc((size_t)WHDRSIZE
);
bcopy((char *)wd
, (char *)hsp
->hs_wd
, (size_t)WHDRSIZE
);
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)
(void)printf("ruptime: no hosts in %s.\n", _PATH_RWHODIR
);
qsort((char *)hs
, nhosts
, sizeof (hs
[0]), cmp
);
for (i
= 0; i
< nhosts
; i
++) {
(void)printf("%-12.12s%s\n", hsp
->hs_wd
->wd_hostname
,
interval(now
- hsp
->hs_wd
->wd_recvtime
, "down"));
"%-12.12s%s, %4d user%s load %*.2f, %*.2f, %*.2f\n",
interval((time_t)hsp
->hs_wd
->wd_sendtime
-
(time_t)hsp
->hs_wd
->wd_boottime
, " up"),
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
);
int days
, hours
, minutes
;
if (tval
< 0 || tval
> 365*24*60*60) {
(void)sprintf(resbuf
, " %s ??:??", updown
);
minutes
= (tval
+ 59) / 60; /* round to minutes */
hours
= minutes
/ 60; minutes
%= 60;
days
= hours
/ 24; hours
%= 24;
(void)sprintf(resbuf
, "%s %2d+%02d:%02d",
updown
, days
, hours
, minutes
);
(void)sprintf(resbuf
, "%s %2d:%02d",
/* alphabetical comparison */
struct hs
*h1
= a1
, *h2
= a2
;
return(rflg
* strcmp(h1
->hs_wd
->wd_hostname
, h2
->hs_wd
->wd_hostname
));
/* load average comparison */
register struct hs
*h1
= a1
, *h2
= a2
;
(h2
->hs_wd
->wd_loadav
[0] - h1
->hs_wd
->wd_loadav
[0]));
/* number of users comparison */
register struct hs
*h1
= a1
, *h2
= a2
;
return(rflg
* (h2
->hs_nusers
- h1
->hs_nusers
));
register struct hs
*h1
= a1
, *h2
= a2
;
(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
)
hs
= realloc((char *)hs
, (hspace
*= 2) * sizeof(*hs
));
(void)fprintf(stderr
, "ruptime: %s.\n", strerror(ENOMEM
));