4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 #include <sys/param.h>
52 #include <protocols/rwhod.h>
56 static struct whod wd
;
58 static struct myutmp
{
63 static int utmpcmp(const void *, const void *);
66 #define WHDRSIZE (sizeof (wd) - sizeof (wd.wd_we))
67 #define RWHODIR "/var/spool/rwho"
69 * this macro should be shared with ruptime.
71 #define down(w, now) ((now) - (w)->wd_recvtime > 11 * 60)
77 main(int argc
, char **argv
)
81 register struct whod
*w
= &wd
;
82 register struct whoent
*we
;
83 register struct myutmp
*mp
;
88 if (argc
> 0 && strcmp(argv
[0], "-a") == 0) {
94 if (chdir(RWHODIR
) < 0) {
96 return (EXIT_FAILURE
);
101 return (EXIT_FAILURE
);
104 while (dp
= readdir(dirp
)) {
107 if (strncmp(dp
->d_name
, "whod.", 5))
109 f
= open(dp
->d_name
, O_RDONLY
);
112 cc
= read(f
, (char *)&wd
, sizeof (struct whod
));
123 for (n
= cc
/ sizeof (struct whoent
); n
> 0; n
--) {
124 if (aflg
== 0 && we
->we_idle
>= 60*60) {
128 if (nusers
>= NUSERS
) {
129 (void) printf("too many users\n");
130 return (EXIT_FAILURE
);
132 mp
->myutmp
= we
->we_utmp
; mp
->myidle
= we
->we_idle
;
133 (void) strncpy(mp
->myhost
, w
->wd_hostname
,
134 sizeof (mp
->myhost
));
135 nusers
++; we
++; mp
++;
139 qsort((char *)myutmp
, nusers
, sizeof (struct myutmp
), utmpcmp
);
142 for (i
= 0; i
< nusers
; i
++) {
143 int j
= strlen(mp
->myhost
) + 1 + strlen(mp
->myutmp
.out_line
);
149 for (i
= 0; i
< nusers
; i
++) {
151 (void) snprintf(buf
, BUFSIZ
, "%.*s:%.*s",
152 sizeof (mp
->myhost
), mp
->myhost
,
153 sizeof (mp
->myutmp
.out_line
), mp
->myutmp
.out_line
);
154 (void) printf("%-8.*s %-*s %.12s",
155 sizeof (mp
->myutmp
.out_name
), mp
->myutmp
.out_name
,
157 ctime((time_t *)&mp
->myutmp
.out_time
) + 4);
161 if (mp
->myidle
>= 100*60)
162 mp
->myidle
= 100*60 - 1;
163 if (mp
->myidle
>= 60)
164 (void) printf(" %2d", mp
->myidle
/ 60);
166 (void) fputs(" ", stdout
);
169 (void) printf(":%02d", mp
->myidle
% 60);
174 return (EXIT_SUCCESS
);
178 utmpcmp(const void *p1
, const void *p2
)
180 const struct myutmp
*u1
= p1
, *u2
= p2
;
183 rc
= strncmp(u1
->myutmp
.out_name
, u2
->myutmp
.out_name
,
184 sizeof (u1
->myutmp
.out_name
));
187 rc
= strncmp(u1
->myhost
, u2
->myhost
, sizeof (u1
->myhost
));
190 return (strncmp(u1
->myutmp
.out_line
, u2
->myutmp
.out_line
,
191 sizeof (u1
->myutmp
.out_line
)));