1*0a6a1f1dSLionel Sambuc /* $NetBSD: who.c,v 1.24 2014/06/08 09:53:43 mlelstv Exp $ */
2b6d4a4c1SThomas Cort
3b6d4a4c1SThomas Cort /*
4b6d4a4c1SThomas Cort * Copyright (c) 1989, 1993
5b6d4a4c1SThomas Cort * The Regents of the University of California. All rights reserved.
6b6d4a4c1SThomas Cort *
7b6d4a4c1SThomas Cort * This code is derived from software contributed to Berkeley by
8b6d4a4c1SThomas Cort * Michael Fischbein.
9b6d4a4c1SThomas Cort *
10b6d4a4c1SThomas Cort * Redistribution and use in source and binary forms, with or without
11b6d4a4c1SThomas Cort * modification, are permitted provided that the following conditions
12b6d4a4c1SThomas Cort * are met:
13b6d4a4c1SThomas Cort * 1. Redistributions of source code must retain the above copyright
14b6d4a4c1SThomas Cort * notice, this list of conditions and the following disclaimer.
15b6d4a4c1SThomas Cort * 2. Redistributions in binary form must reproduce the above copyright
16b6d4a4c1SThomas Cort * notice, this list of conditions and the following disclaimer in the
17b6d4a4c1SThomas Cort * documentation and/or other materials provided with the distribution.
18b6d4a4c1SThomas Cort * 3. Neither the name of the University nor the names of its contributors
19b6d4a4c1SThomas Cort * may be used to endorse or promote products derived from this software
20b6d4a4c1SThomas Cort * without specific prior written permission.
21b6d4a4c1SThomas Cort *
22b6d4a4c1SThomas Cort * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23b6d4a4c1SThomas Cort * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24b6d4a4c1SThomas Cort * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25b6d4a4c1SThomas Cort * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26b6d4a4c1SThomas Cort * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27b6d4a4c1SThomas Cort * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28b6d4a4c1SThomas Cort * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29b6d4a4c1SThomas Cort * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30b6d4a4c1SThomas Cort * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31b6d4a4c1SThomas Cort * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32b6d4a4c1SThomas Cort * SUCH DAMAGE.
33b6d4a4c1SThomas Cort */
34b6d4a4c1SThomas Cort
35b6d4a4c1SThomas Cort #include <sys/cdefs.h>
36b6d4a4c1SThomas Cort #ifndef lint
37b6d4a4c1SThomas Cort __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
38b6d4a4c1SThomas Cort The Regents of the University of California. All rights reserved.");
39b6d4a4c1SThomas Cort #endif /* not lint */
40b6d4a4c1SThomas Cort
41b6d4a4c1SThomas Cort #ifndef lint
42b6d4a4c1SThomas Cort #if 0
43b6d4a4c1SThomas Cort static char sccsid[] = "@(#)who.c 8.1 (Berkeley) 6/6/93";
44b6d4a4c1SThomas Cort #endif
45*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: who.c,v 1.24 2014/06/08 09:53:43 mlelstv Exp $");
46b6d4a4c1SThomas Cort #endif /* not lint */
47b6d4a4c1SThomas Cort
48b6d4a4c1SThomas Cort #include <sys/types.h>
49b6d4a4c1SThomas Cort #include <sys/stat.h>
50b6d4a4c1SThomas Cort
51b6d4a4c1SThomas Cort #include <err.h>
52b6d4a4c1SThomas Cort #include <locale.h>
53b6d4a4c1SThomas Cort #include <pwd.h>
54b6d4a4c1SThomas Cort #include <stdio.h>
55b6d4a4c1SThomas Cort #include <stdlib.h>
56b6d4a4c1SThomas Cort #include <string.h>
57b6d4a4c1SThomas Cort #include <time.h>
58b6d4a4c1SThomas Cort #include <unistd.h>
59b6d4a4c1SThomas Cort #ifdef SUPPORT_UTMP
60b6d4a4c1SThomas Cort #include <utmp.h>
61b6d4a4c1SThomas Cort #endif
62b6d4a4c1SThomas Cort #ifdef SUPPORT_UTMPX
63b6d4a4c1SThomas Cort #include <utmpx.h>
64b6d4a4c1SThomas Cort #endif
65b6d4a4c1SThomas Cort
66b6d4a4c1SThomas Cort #include "utmpentry.h"
67b6d4a4c1SThomas Cort
68b6d4a4c1SThomas Cort static void output_labels(void);
69b6d4a4c1SThomas Cort static void who_am_i(const char *, int);
70b6d4a4c1SThomas Cort static void usage(void) __dead;
71b6d4a4c1SThomas Cort static void process(const char *, int);
72b6d4a4c1SThomas Cort static void eprint(const struct utmpentry *);
73b6d4a4c1SThomas Cort static void print(const char *, const char *, time_t, const char *, pid_t pid,
74b6d4a4c1SThomas Cort uint16_t term, uint16_t xit, uint16_t sess, uint16_t type);
75b6d4a4c1SThomas Cort static void quick(const char *);
76b6d4a4c1SThomas Cort
77b6d4a4c1SThomas Cort static int show_term; /* show term state */
78b6d4a4c1SThomas Cort static int show_idle; /* show idle time */
79b6d4a4c1SThomas Cort static int show_details; /* show exit status etc. */
80b6d4a4c1SThomas Cort
81b6d4a4c1SThomas Cort struct ut_type_names {
82b6d4a4c1SThomas Cort int type;
83b6d4a4c1SThomas Cort const char *name;
84b6d4a4c1SThomas Cort } ut_type_names[] = {
85b6d4a4c1SThomas Cort #ifdef SUPPORT_UTMPX
86b6d4a4c1SThomas Cort { EMPTY, "empty" },
87b6d4a4c1SThomas Cort { RUN_LVL, "run level" },
88b6d4a4c1SThomas Cort { BOOT_TIME, "boot time" },
89b6d4a4c1SThomas Cort { OLD_TIME, "old time" },
90b6d4a4c1SThomas Cort { NEW_TIME, "new time" },
91b6d4a4c1SThomas Cort { INIT_PROCESS, "init process" },
92b6d4a4c1SThomas Cort { LOGIN_PROCESS, "login process" },
93b6d4a4c1SThomas Cort { USER_PROCESS, "user process" },
94b6d4a4c1SThomas Cort { DEAD_PROCESS, "dead process" },
95b6d4a4c1SThomas Cort #if defined(_NETBSD_SOURCE)
96b6d4a4c1SThomas Cort { ACCOUNTING, "accounting" },
97b6d4a4c1SThomas Cort { SIGNATURE, "signature" },
98b6d4a4c1SThomas Cort { DOWN_TIME, "down time" },
99b6d4a4c1SThomas Cort #endif /* _NETBSD_SOURCE */
100b6d4a4c1SThomas Cort #endif /* SUPPORT_UTMPX */
101b6d4a4c1SThomas Cort { -1, "unknown" }
102b6d4a4c1SThomas Cort };
103b6d4a4c1SThomas Cort
104b6d4a4c1SThomas Cort int
main(int argc,char * argv[])105b6d4a4c1SThomas Cort main(int argc, char *argv[])
106b6d4a4c1SThomas Cort {
107b6d4a4c1SThomas Cort int c, only_current_term, show_labels, quick_mode, default_mode;
108b6d4a4c1SThomas Cort int et = 0;
109b6d4a4c1SThomas Cort
110b6d4a4c1SThomas Cort setlocale(LC_ALL, "");
111b6d4a4c1SThomas Cort
112b6d4a4c1SThomas Cort only_current_term = show_term = show_idle = show_labels = 0;
113b6d4a4c1SThomas Cort quick_mode = default_mode = 0;
114b6d4a4c1SThomas Cort
115b6d4a4c1SThomas Cort while ((c = getopt(argc, argv, "abdHlmpqrsTtuv")) != -1) {
116b6d4a4c1SThomas Cort switch (c) {
117b6d4a4c1SThomas Cort case 'a':
118b6d4a4c1SThomas Cort et = -1;
119b6d4a4c1SThomas Cort show_idle = show_details = 1;
120b6d4a4c1SThomas Cort break;
121b6d4a4c1SThomas Cort case 'b':
122b6d4a4c1SThomas Cort et |= (1 << BOOT_TIME);
123b6d4a4c1SThomas Cort break;
124b6d4a4c1SThomas Cort case 'd':
125b6d4a4c1SThomas Cort et |= (1 << DEAD_PROCESS);
126b6d4a4c1SThomas Cort break;
127b6d4a4c1SThomas Cort case 'H':
128b6d4a4c1SThomas Cort show_labels = 1;
129b6d4a4c1SThomas Cort break;
130b6d4a4c1SThomas Cort case 'l':
131b6d4a4c1SThomas Cort et |= (1 << LOGIN_PROCESS);
132b6d4a4c1SThomas Cort break;
133b6d4a4c1SThomas Cort case 'm':
134b6d4a4c1SThomas Cort only_current_term = 1;
135b6d4a4c1SThomas Cort break;
136b6d4a4c1SThomas Cort case 'p':
137b6d4a4c1SThomas Cort et |= (1 << INIT_PROCESS);
138b6d4a4c1SThomas Cort break;
139b6d4a4c1SThomas Cort case 'q':
140b6d4a4c1SThomas Cort quick_mode = 1;
141b6d4a4c1SThomas Cort break;
142b6d4a4c1SThomas Cort case 'r':
143b6d4a4c1SThomas Cort et |= (1 << RUN_LVL);
144b6d4a4c1SThomas Cort break;
145b6d4a4c1SThomas Cort case 's':
146b6d4a4c1SThomas Cort default_mode = 1;
147b6d4a4c1SThomas Cort break;
148b6d4a4c1SThomas Cort case 'T':
149b6d4a4c1SThomas Cort show_term = 1;
150b6d4a4c1SThomas Cort break;
151b6d4a4c1SThomas Cort case 't':
152b6d4a4c1SThomas Cort et |= (1 << NEW_TIME);
153b6d4a4c1SThomas Cort break;
154b6d4a4c1SThomas Cort case 'u':
155b6d4a4c1SThomas Cort show_idle = 1;
156b6d4a4c1SThomas Cort break;
157b6d4a4c1SThomas Cort case 'v':
158b6d4a4c1SThomas Cort show_details = 1;
159b6d4a4c1SThomas Cort break;
160b6d4a4c1SThomas Cort default:
161b6d4a4c1SThomas Cort usage();
162b6d4a4c1SThomas Cort /* NOTREACHED */
163b6d4a4c1SThomas Cort }
164b6d4a4c1SThomas Cort }
165b6d4a4c1SThomas Cort argc -= optind;
166b6d4a4c1SThomas Cort argv += optind;
167b6d4a4c1SThomas Cort
168b6d4a4c1SThomas Cort if (et != 0)
169b6d4a4c1SThomas Cort etype = et;
170b6d4a4c1SThomas Cort
171b6d4a4c1SThomas Cort if (chdir("/dev")) {
172b6d4a4c1SThomas Cort err(EXIT_FAILURE, "cannot change directory to /dev");
173b6d4a4c1SThomas Cort /* NOTREACHED */
174b6d4a4c1SThomas Cort }
175b6d4a4c1SThomas Cort
176b6d4a4c1SThomas Cort if (default_mode)
177b6d4a4c1SThomas Cort only_current_term = show_term = show_idle = 0;
178b6d4a4c1SThomas Cort
179b6d4a4c1SThomas Cort switch (argc) {
180b6d4a4c1SThomas Cort case 0: /* who */
181b6d4a4c1SThomas Cort if (quick_mode) {
182b6d4a4c1SThomas Cort quick(NULL);
183b6d4a4c1SThomas Cort } else if (only_current_term) {
184b6d4a4c1SThomas Cort who_am_i(NULL, show_labels);
185b6d4a4c1SThomas Cort } else {
186b6d4a4c1SThomas Cort process(NULL, show_labels);
187b6d4a4c1SThomas Cort }
188b6d4a4c1SThomas Cort break;
189b6d4a4c1SThomas Cort case 1: /* who utmp_file */
190b6d4a4c1SThomas Cort if (quick_mode) {
191b6d4a4c1SThomas Cort quick(*argv);
192b6d4a4c1SThomas Cort } else if (only_current_term) {
193b6d4a4c1SThomas Cort who_am_i(*argv, show_labels);
194b6d4a4c1SThomas Cort } else {
195b6d4a4c1SThomas Cort process(*argv, show_labels);
196b6d4a4c1SThomas Cort }
197b6d4a4c1SThomas Cort break;
198b6d4a4c1SThomas Cort case 2: /* who am i */
199b6d4a4c1SThomas Cort who_am_i(NULL, show_labels);
200b6d4a4c1SThomas Cort break;
201b6d4a4c1SThomas Cort default:
202b6d4a4c1SThomas Cort usage();
203b6d4a4c1SThomas Cort /* NOTREACHED */
204b6d4a4c1SThomas Cort }
205b6d4a4c1SThomas Cort
206b6d4a4c1SThomas Cort return 0;
207b6d4a4c1SThomas Cort }
208b6d4a4c1SThomas Cort
209b6d4a4c1SThomas Cort static char *
strrstr(const char * str,const char * pat)210b6d4a4c1SThomas Cort strrstr(const char *str, const char *pat)
211b6d4a4c1SThomas Cort {
212b6d4a4c1SThomas Cort const char *estr;
213b6d4a4c1SThomas Cort size_t len;
214b6d4a4c1SThomas Cort if (*pat == '\0')
215b6d4a4c1SThomas Cort return __UNCONST(str);
216b6d4a4c1SThomas Cort
217b6d4a4c1SThomas Cort len = strlen(pat);
218b6d4a4c1SThomas Cort
219b6d4a4c1SThomas Cort for (estr = str + strlen(str); str < estr; estr--)
220b6d4a4c1SThomas Cort if (strncmp(estr, pat, len) == 0)
221b6d4a4c1SThomas Cort return __UNCONST(estr);
222b6d4a4c1SThomas Cort return NULL;
223b6d4a4c1SThomas Cort }
224b6d4a4c1SThomas Cort
225b6d4a4c1SThomas Cort static void
who_am_i(const char * fname,int show_labels)226b6d4a4c1SThomas Cort who_am_i(const char *fname, int show_labels)
227b6d4a4c1SThomas Cort {
228b6d4a4c1SThomas Cort struct passwd *pw;
229b6d4a4c1SThomas Cort const char *p;
230b6d4a4c1SThomas Cort char *t;
231b6d4a4c1SThomas Cort time_t now;
232b6d4a4c1SThomas Cort struct utmpentry *ehead, *ep;
233b6d4a4c1SThomas Cort
234b6d4a4c1SThomas Cort /* search through the utmp and find an entry for this tty */
235b6d4a4c1SThomas Cort if ((p = ttyname(STDIN_FILENO)) != NULL) {
236b6d4a4c1SThomas Cort
237b6d4a4c1SThomas Cort /* strip directory prefixes for ttys */
238b6d4a4c1SThomas Cort if ((t = strrstr(p, "/pts/")) != NULL ||
239b6d4a4c1SThomas Cort (t = strrchr(p, '/')) != NULL)
240b6d4a4c1SThomas Cort p = t + 1;
241b6d4a4c1SThomas Cort
242b6d4a4c1SThomas Cort (void)getutentries(fname, &ehead);
243b6d4a4c1SThomas Cort for (ep = ehead; ep; ep = ep->next)
244b6d4a4c1SThomas Cort if (strcmp(ep->line, p) == 0) {
245b6d4a4c1SThomas Cort if (show_labels)
246b6d4a4c1SThomas Cort output_labels();
247b6d4a4c1SThomas Cort eprint(ep);
248b6d4a4c1SThomas Cort return;
249b6d4a4c1SThomas Cort }
250b6d4a4c1SThomas Cort } else
251b6d4a4c1SThomas Cort p = "tty??";
252b6d4a4c1SThomas Cort
253b6d4a4c1SThomas Cort (void)time(&now);
254b6d4a4c1SThomas Cort pw = getpwuid(getuid());
255b6d4a4c1SThomas Cort if (show_labels)
256b6d4a4c1SThomas Cort output_labels();
257b6d4a4c1SThomas Cort print(pw ? pw->pw_name : "?", p, now, "", getpid(), 0, 0, 0, 0);
258b6d4a4c1SThomas Cort }
259b6d4a4c1SThomas Cort
260b6d4a4c1SThomas Cort static void
process(const char * fname,int show_labels)261b6d4a4c1SThomas Cort process(const char *fname, int show_labels)
262b6d4a4c1SThomas Cort {
263b6d4a4c1SThomas Cort struct utmpentry *ehead, *ep;
264b6d4a4c1SThomas Cort (void)getutentries(fname, &ehead);
265b6d4a4c1SThomas Cort if (show_labels)
266b6d4a4c1SThomas Cort output_labels();
267b6d4a4c1SThomas Cort for (ep = ehead; ep != NULL; ep = ep->next)
268b6d4a4c1SThomas Cort eprint(ep);
269b6d4a4c1SThomas Cort }
270b6d4a4c1SThomas Cort
271b6d4a4c1SThomas Cort static void
eprint(const struct utmpentry * ep)272b6d4a4c1SThomas Cort eprint(const struct utmpentry *ep)
273b6d4a4c1SThomas Cort {
274b6d4a4c1SThomas Cort print(ep->name, ep->line, (time_t)ep->tv.tv_sec, ep->host, ep->pid,
275b6d4a4c1SThomas Cort ep->term, ep->exit, ep->sess, ep->type);
276b6d4a4c1SThomas Cort }
277b6d4a4c1SThomas Cort
278b6d4a4c1SThomas Cort static void
print(const char * name,const char * line,time_t t,const char * host,pid_t pid,uint16_t term,uint16_t xit,uint16_t sess,uint16_t type)279b6d4a4c1SThomas Cort print(const char *name, const char *line, time_t t, const char *host,
280b6d4a4c1SThomas Cort pid_t pid, uint16_t term, uint16_t xit, uint16_t sess, uint16_t type)
281b6d4a4c1SThomas Cort {
282b6d4a4c1SThomas Cort struct stat sb;
283b6d4a4c1SThomas Cort char state;
284b6d4a4c1SThomas Cort static time_t now = 0;
285b6d4a4c1SThomas Cort time_t idle;
286b6d4a4c1SThomas Cort const char *types = NULL;
287b6d4a4c1SThomas Cort size_t i;
288*0a6a1f1dSLionel Sambuc char *tstr;
289b6d4a4c1SThomas Cort
290b6d4a4c1SThomas Cort state = '?';
291b6d4a4c1SThomas Cort idle = 0;
292b6d4a4c1SThomas Cort
293b6d4a4c1SThomas Cort for (i = 0; ut_type_names[i].type >= 0; i++) {
294b6d4a4c1SThomas Cort types = ut_type_names[i].name;
295b6d4a4c1SThomas Cort if (ut_type_names[i].type == type)
296b6d4a4c1SThomas Cort break;
297b6d4a4c1SThomas Cort }
298b6d4a4c1SThomas Cort
299b6d4a4c1SThomas Cort if (show_term || show_idle) {
300b6d4a4c1SThomas Cort if (now == 0)
301b6d4a4c1SThomas Cort time(&now);
302b6d4a4c1SThomas Cort
303b6d4a4c1SThomas Cort if (stat(line, &sb) == 0) {
304b6d4a4c1SThomas Cort state = (sb.st_mode & 020) ? '+' : '-';
305b6d4a4c1SThomas Cort idle = now - sb.st_atime;
306b6d4a4c1SThomas Cort }
307b6d4a4c1SThomas Cort
308b6d4a4c1SThomas Cort }
309b6d4a4c1SThomas Cort
310b6d4a4c1SThomas Cort (void)printf("%-*.*s ", maxname, maxname, name);
311b6d4a4c1SThomas Cort
312b6d4a4c1SThomas Cort if (show_term)
313b6d4a4c1SThomas Cort (void)printf("%c ", state);
314b6d4a4c1SThomas Cort
315b6d4a4c1SThomas Cort (void)printf("%-*.*s ", maxline, maxline, line);
316*0a6a1f1dSLionel Sambuc tstr = ctime(&t);
317*0a6a1f1dSLionel Sambuc (void)printf("%.12s ", tstr ? tstr + 4 : "?");
318b6d4a4c1SThomas Cort
319b6d4a4c1SThomas Cort if (show_idle) {
320b6d4a4c1SThomas Cort if (idle < 60)
321b6d4a4c1SThomas Cort (void)printf(" . ");
322b6d4a4c1SThomas Cort else if (idle < (24 * 60 * 60))
323b6d4a4c1SThomas Cort (void)printf("%02ld:%02ld ",
324b6d4a4c1SThomas Cort (long)(idle / (60 * 60)),
325b6d4a4c1SThomas Cort (long)(idle % (60 * 60)) / 60);
326b6d4a4c1SThomas Cort else
327b6d4a4c1SThomas Cort (void)printf(" old ");
328b6d4a4c1SThomas Cort
329b6d4a4c1SThomas Cort (void)printf("\t%6d", pid);
330b6d4a4c1SThomas Cort
331b6d4a4c1SThomas Cort if (show_details) {
332b6d4a4c1SThomas Cort if (type == RUN_LVL)
333b6d4a4c1SThomas Cort (void)printf("\tnew=%c old=%c", term, xit);
334b6d4a4c1SThomas Cort else
335b6d4a4c1SThomas Cort (void)printf("\tterm=%d exit=%d", term, xit);
336b6d4a4c1SThomas Cort (void)printf(" sess=%d", sess);
337b6d4a4c1SThomas Cort (void)printf(" type=%s ", types);
338b6d4a4c1SThomas Cort }
339b6d4a4c1SThomas Cort }
340b6d4a4c1SThomas Cort
341b6d4a4c1SThomas Cort if (*host)
342b6d4a4c1SThomas Cort (void)printf("\t(%.*s)", maxhost, host);
343b6d4a4c1SThomas Cort (void)putchar('\n');
344b6d4a4c1SThomas Cort }
345b6d4a4c1SThomas Cort
346b6d4a4c1SThomas Cort static void
output_labels(void)347b6d4a4c1SThomas Cort output_labels(void)
348b6d4a4c1SThomas Cort {
349b6d4a4c1SThomas Cort (void)printf("%-*.*s ", maxname, maxname, "USER");
350b6d4a4c1SThomas Cort
351b6d4a4c1SThomas Cort if (show_term)
352b6d4a4c1SThomas Cort (void)printf("S ");
353b6d4a4c1SThomas Cort
354b6d4a4c1SThomas Cort (void)printf("%-*.*s ", maxline, maxline, "LINE");
355b6d4a4c1SThomas Cort (void)printf("WHEN ");
356b6d4a4c1SThomas Cort
357b6d4a4c1SThomas Cort if (show_idle) {
358b6d4a4c1SThomas Cort (void)printf("IDLE ");
359b6d4a4c1SThomas Cort (void)printf("\t PID");
360b6d4a4c1SThomas Cort
361b6d4a4c1SThomas Cort (void)printf("\tCOMMENT");
362b6d4a4c1SThomas Cort }
363b6d4a4c1SThomas Cort
364b6d4a4c1SThomas Cort (void)putchar('\n');
365b6d4a4c1SThomas Cort }
366b6d4a4c1SThomas Cort
367b6d4a4c1SThomas Cort static void
quick(const char * fname)368b6d4a4c1SThomas Cort quick(const char *fname)
369b6d4a4c1SThomas Cort {
370b6d4a4c1SThomas Cort struct utmpentry *ehead, *ep;
371b6d4a4c1SThomas Cort int num = 0;
372b6d4a4c1SThomas Cort
373b6d4a4c1SThomas Cort (void)getutentries(fname, &ehead);
374b6d4a4c1SThomas Cort for (ep = ehead; ep != NULL; ep = ep->next) {
375b6d4a4c1SThomas Cort (void)printf("%-*s ", maxname, ep->name);
376b6d4a4c1SThomas Cort if ((++num % 8) == 0)
377b6d4a4c1SThomas Cort (void)putchar('\n');
378b6d4a4c1SThomas Cort }
379b6d4a4c1SThomas Cort if (num % 8)
380b6d4a4c1SThomas Cort (void)putchar('\n');
381b6d4a4c1SThomas Cort
382b6d4a4c1SThomas Cort (void)printf("# users = %d\n", num);
383b6d4a4c1SThomas Cort }
384b6d4a4c1SThomas Cort
385b6d4a4c1SThomas Cort static void
usage(void)386b6d4a4c1SThomas Cort usage(void)
387b6d4a4c1SThomas Cort {
388b6d4a4c1SThomas Cort (void)fprintf(stderr, "Usage: %s [-abdHlmqrsTtuv] [file]\n\t%s am i\n",
389b6d4a4c1SThomas Cort getprogname(), getprogname());
390b6d4a4c1SThomas Cort exit(EXIT_FAILURE);
391b6d4a4c1SThomas Cort }
392