* Copyright (c) 1983 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)ruptime.c 5.5 (Berkeley) 8/25/88";
#include <protocols/rwhod.h>
#define WHDRSIZE (sizeof (awhod) - sizeof (awhod.wd_we))
#define RWHODIR "/usr/spool/rwho"
#define down(h) (now - (h)->hs_wd->wd_recvtime > 11 * 60)
int hscmp(), ucmp(), lcmp(), tcmp();
register struct hs
*hsp
= hs
;
register struct whod
*wd
;
register struct whoent
*we
;
int aflg
, cc
, ch
, f
, i
, maxloadav
;
char buf
[sizeof(struct whod
)];
char *interval(), *malloc();
while ((ch
= getopt(argc
, argv
, "alrut")) != EOF
)
fprintf(stderr
, "usage: ruptime [-alrut]\n");
if (chdir(RWHODIR
) || (dirp
= opendir(".")) == NULL
) {
while (dp
= readdir(dirp
)) {
if (dp
->d_ino
== 0 || strncmp(dp
->d_name
, "whod.", 5))
fprintf(stderr
, "ruptime: too many hosts\n");
f
= open(dp
->d_name
, O_RDONLY
, 0);
cc
= read(f
, buf
, sizeof(struct whod
));
hsp
->hs_wd
= (struct whod
*)malloc(WHDRSIZE
);
bcopy(wd
, hsp
->hs_wd
, 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)
printf("ruptime: no hosts!?!\n");
qsort((char *)hs
, nhosts
, sizeof (hs
[0]), cmp
);
for (i
= 0; i
< nhosts
; i
++) {
printf("%-12.12s%s\n", hsp
->hs_wd
->wd_hostname
,
interval(now
- hsp
->hs_wd
->wd_recvtime
, "down"));
printf("%-12.12s%s, %4d user%s load %*.2f, %*.2f, %*.2f\n",
interval(hsp
->hs_wd
->wd_sendtime
-
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);
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",
return(rflg
* strcmp(h1
->hs_wd
->wd_hostname
, h2
->hs_wd
->wd_hostname
));
* Compare according to load average.
(h2
->hs_wd
->wd_loadav
[0] - h1
->hs_wd
->wd_loadav
[0]));
* Compare according to number of users.
return(rflg
* (h2
->hs_nusers
- h1
->hs_nusers
));
* Compare according to uptime.
(down(h2
) ? h2
->hs_wd
->wd_recvtime
- now
: h2
->hs_wd
->wd_sendtime
- h2
->hs_wd
->wd_boottime
)
(down(h1
) ? h1
->hs_wd
->wd_recvtime
- now
: h1
->hs_wd
->wd_sendtime
- h1
->hs_wd
->wd_boottime
)