global: convert indentation-TABs to spaces
[coreutils.git] / src / who.c
blobf162fab58a64e6002b00a480e6992d4d90f46519
1 /* GNU's who.
2 Copyright (C) 1992-2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by jla; revised by djm; revised again by mstone */
19 /* Output format:
20 name [state] line time [activity] [pid] [comment] [exit]
21 state: -T
22 name, line, time: not -q
23 idle: -u
26 #include <config.h>
27 #include <getopt.h>
28 #include <stdio.h>
30 #include <sys/types.h>
31 #include "system.h"
33 #include "c-ctype.h"
34 #include "canon-host.h"
35 #include "readutmp.h"
36 #include "error.h"
37 #include "quote.h"
39 /* The official name of this program (e.g., no `g' prefix). */
40 #define PROGRAM_NAME "who"
42 #define AUTHORS \
43 proper_name ("Joseph Arceneaux"), \
44 proper_name ("David MacKenzie"), \
45 proper_name ("Michael Stone")
47 #ifndef MAXHOSTNAMELEN
48 # define MAXHOSTNAMELEN 64
49 #endif
51 #ifdef RUN_LVL
52 # define UT_TYPE_RUN_LVL(U) UT_TYPE_EQ (U, RUN_LVL)
53 #else
54 # define UT_TYPE_RUN_LVL(U) false
55 #endif
57 #ifdef INIT_PROCESS
58 # define UT_TYPE_INIT_PROCESS(U) UT_TYPE_EQ (U, INIT_PROCESS)
59 #else
60 # define UT_TYPE_INIT_PROCESS(U) false
61 #endif
63 #ifdef LOGIN_PROCESS
64 # define UT_TYPE_LOGIN_PROCESS(U) UT_TYPE_EQ (U, LOGIN_PROCESS)
65 #else
66 # define UT_TYPE_LOGIN_PROCESS(U) false
67 #endif
69 #ifdef DEAD_PROCESS
70 # define UT_TYPE_DEAD_PROCESS(U) UT_TYPE_EQ (U, DEAD_PROCESS)
71 #else
72 # define UT_TYPE_DEAD_PROCESS(U) false
73 #endif
75 #ifdef NEW_TIME
76 # define UT_TYPE_NEW_TIME(U) UT_TYPE_EQ (U, NEW_TIME)
77 #else
78 # define UT_TYPE_NEW_TIME(U) false
79 #endif
81 #define IDLESTR_LEN 6
83 #if HAVE_STRUCT_XTMP_UT_PID
84 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
85 char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
86 sprintf (Var, "%ld", (long int) (Utmp_ent->ut_pid))
87 #else
88 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
89 const char *Var = ""
90 #endif
92 #if HAVE_STRUCT_XTMP_UT_ID
93 # define UT_ID(U) ((U)->ut_id)
94 #else
95 # define UT_ID(U) "??"
96 #endif
98 char *ttyname (int);
100 /* If true, attempt to canonicalize hostnames via a DNS lookup. */
101 static bool do_lookup;
103 /* If true, display only a list of usernames and count of
104 the users logged on.
105 Ignored for `who am i'. */
106 static bool short_list;
108 /* If true, display only name, line, and time fields. */
109 static bool short_output;
111 /* If true, display the hours:minutes since each user has touched
112 the keyboard, or "." if within the last minute, or "old" if
113 not within the last day. */
114 static bool include_idle;
116 /* If true, display a line at the top describing each field. */
117 static bool include_heading;
119 /* If true, display a `+' for each user if mesg y, a `-' if mesg n,
120 or a `?' if their tty cannot be statted. */
121 static bool include_mesg;
123 /* If true, display process termination & exit status. */
124 static bool include_exit;
126 /* If true, display the last boot time. */
127 static bool need_boottime;
129 /* If true, display dead processes. */
130 static bool need_deadprocs;
132 /* If true, display processes waiting for user login. */
133 static bool need_login;
135 /* If true, display processes started by init. */
136 static bool need_initspawn;
138 /* If true, display the last clock change. */
139 static bool need_clockchange;
141 /* If true, display the current runlevel. */
142 static bool need_runlevel;
144 /* If true, display user processes. */
145 static bool need_users;
147 /* If true, display info only for the controlling tty. */
148 static bool my_line_only;
150 /* The strftime format to use for login times, and its expected
151 output width. */
152 static char const *time_format;
153 static int time_format_width;
155 /* for long options with no corresponding short option, use enum */
156 enum
158 LOOKUP_OPTION = CHAR_MAX + 1
161 static struct option const longopts[] =
163 {"all", no_argument, NULL, 'a'},
164 {"boot", no_argument, NULL, 'b'},
165 {"count", no_argument, NULL, 'q'},
166 {"dead", no_argument, NULL, 'd'},
167 {"heading", no_argument, NULL, 'H'},
168 {"login", no_argument, NULL, 'l'},
169 {"lookup", no_argument, NULL, LOOKUP_OPTION},
170 {"message", no_argument, NULL, 'T'},
171 {"mesg", no_argument, NULL, 'T'},
172 {"process", no_argument, NULL, 'p'},
173 {"runlevel", no_argument, NULL, 'r'},
174 {"short", no_argument, NULL, 's'},
175 {"time", no_argument, NULL, 't'},
176 {"users", no_argument, NULL, 'u'},
177 {"writable", no_argument, NULL, 'T'},
178 {GETOPT_HELP_OPTION_DECL},
179 {GETOPT_VERSION_OPTION_DECL},
180 {NULL, 0, NULL, 0}
183 /* Return a string representing the time between WHEN and now.
184 BOOTTIME is the time of last reboot.
185 FIXME: locale? */
186 static const char *
187 idle_string (time_t when, time_t boottime)
189 static time_t now = TYPE_MINIMUM (time_t);
191 if (now == TYPE_MINIMUM (time_t))
192 time (&now);
194 if (boottime < when && now - 24 * 60 * 60 < when && when <= now)
196 int seconds_idle = now - when;
197 if (seconds_idle < 60)
198 return " . ";
199 else
201 static char idle_hhmm[IDLESTR_LEN];
202 sprintf (idle_hhmm, "%02d:%02d",
203 seconds_idle / (60 * 60),
204 (seconds_idle % (60 * 60)) / 60);
205 return idle_hhmm;
209 return _(" old ");
212 /* Return a time string. */
213 static const char *
214 time_string (const STRUCT_UTMP *utmp_ent)
216 static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];
218 /* Don't take the address of UT_TIME_MEMBER directly.
219 Ulrich Drepper wrote:
220 ``... GNU libc (and perhaps other libcs as well) have extended
221 utmp file formats which do not use a simple time_t ut_time field.
222 In glibc, ut_time is a macro which selects for backward compatibility
223 the tv_sec member of a struct timeval value.'' */
224 time_t t = UT_TIME_MEMBER (utmp_ent);
225 struct tm *tmp = localtime (&t);
227 if (tmp)
229 strftime (buf, sizeof buf, time_format, tmp);
230 return buf;
232 else
233 return timetostr (t, buf);
236 /* Print formatted output line. Uses mostly arbitrary field sizes, probably
237 will need tweaking if any of the localization stuff is done, or for 64 bit
238 pids, etc. */
239 static void
240 print_line (int userlen, const char *user, const char state,
241 int linelen, const char *line,
242 const char *time_str, const char *idle, const char *pid,
243 const char *comment, const char *exitstr)
245 static char mesg[3] = { ' ', 'x', '\0' };
246 char *buf;
247 char x_idle[1 + IDLESTR_LEN + 1];
248 char x_pid[1 + INT_STRLEN_BOUND (pid_t) + 1];
249 char *x_exitstr;
250 int err;
252 mesg[1] = state;
254 if (include_idle && !short_output && strlen (idle) < sizeof x_idle - 1)
255 sprintf (x_idle, " %-6s", idle);
256 else
257 *x_idle = '\0';
259 if (!short_output && strlen (pid) < sizeof x_pid - 1)
260 sprintf (x_pid, " %10s", pid);
261 else
262 *x_pid = '\0';
264 x_exitstr = xmalloc (include_exit ? 1 + MAX (12, strlen (exitstr)) + 1 : 1);
265 if (include_exit)
266 sprintf (x_exitstr, " %-12s", exitstr);
267 else
268 *x_exitstr = '\0';
270 err = asprintf (&buf,
271 "%-8.*s"
272 "%s"
273 " %-12.*s"
274 " %-*s"
275 "%s"
276 "%s"
277 " %-8s"
278 "%s"
280 userlen, user ? user : " .",
281 include_mesg ? mesg : "",
282 linelen, line,
283 time_format_width,
284 time_str,
285 x_idle,
286 x_pid,
287 /* FIXME: it's not really clear whether the following
288 field should be in the short_output. A strict reading
289 of SUSv2 would suggest not, but I haven't seen any
290 implementations that actually work that way... */
291 comment,
292 x_exitstr
294 if (err == -1)
295 xalloc_die ();
298 /* Remove any trailing spaces. */
299 char *p = buf + strlen (buf);
300 while (*--p == ' ')
301 /* empty */;
302 *(p + 1) = '\0';
305 puts (buf);
306 free (buf);
307 free (x_exitstr);
310 /* Send properly parsed USER_PROCESS info to print_line. The most
311 recent boot time is BOOTTIME. */
312 static void
313 print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
315 struct stat stats;
316 time_t last_change;
317 char mesg;
318 char idlestr[IDLESTR_LEN + 1];
319 static char *hoststr;
320 #if HAVE_UT_HOST
321 static size_t hostlen;
322 #endif
324 #define DEV_DIR_WITH_TRAILING_SLASH "/dev/"
325 #define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
327 char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
328 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
330 /* Copy ut_line into LINE, prepending `/dev/' if ut_line is not
331 already an absolute file name. Some systems may put the full,
332 absolute file name in ut_line. */
333 if (utmp_ent->ut_line[0] == '/')
335 strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
336 line[sizeof (utmp_ent->ut_line)] = '\0';
338 else
340 strcpy (line, DEV_DIR_WITH_TRAILING_SLASH);
341 strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line,
342 sizeof (utmp_ent->ut_line));
343 line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0';
346 if (stat (line, &stats) == 0)
348 mesg = (stats.st_mode & S_IWGRP) ? '+' : '-';
349 last_change = stats.st_atime;
351 else
353 mesg = '?';
354 last_change = 0;
357 if (last_change)
358 sprintf (idlestr, "%.*s", IDLESTR_LEN, idle_string (last_change, boottime));
359 else
360 sprintf (idlestr, " ?");
362 #if HAVE_UT_HOST
363 if (utmp_ent->ut_host[0])
365 char ut_host[sizeof (utmp_ent->ut_host) + 1];
366 char *host = NULL;
367 char *display = NULL;
369 /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
370 strncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
371 ut_host[sizeof (utmp_ent->ut_host)] = '\0';
373 /* Look for an X display. */
374 display = strchr (ut_host, ':');
375 if (display)
376 *display++ = '\0';
378 if (*ut_host && do_lookup)
380 /* See if we can canonicalize it. */
381 host = canon_host (ut_host);
384 if (! host)
385 host = ut_host;
387 if (display)
389 if (hostlen < strlen (host) + strlen (display) + 4)
391 hostlen = strlen (host) + strlen (display) + 4;
392 hoststr = xrealloc (hoststr, hostlen);
394 sprintf (hoststr, "(%s:%s)", host, display);
396 else
398 if (hostlen < strlen (host) + 3)
400 hostlen = strlen (host) + 3;
401 hoststr = xrealloc (hoststr, hostlen);
403 sprintf (hoststr, "(%s)", host);
406 if (host != ut_host)
407 free (host);
409 else
411 if (hostlen < 1)
413 hostlen = 1;
414 hoststr = xrealloc (hoststr, hostlen);
416 *hoststr = '\0';
418 #endif
420 print_line (sizeof UT_USER (utmp_ent), UT_USER (utmp_ent), mesg,
421 sizeof utmp_ent->ut_line, utmp_ent->ut_line,
422 time_string (utmp_ent), idlestr, pidstr,
423 hoststr ? hoststr : "", "");
426 static void
427 print_boottime (const STRUCT_UTMP *utmp_ent)
429 print_line (-1, "", ' ', -1, _("system boot"),
430 time_string (utmp_ent), "", "", "", "");
433 static char *
434 make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
436 char *comment = xmalloc (strlen (_("id=")) + sizeof UT_ID (utmp_ent) + 1);
438 strcpy (comment, _("id="));
439 strncat (comment, UT_ID (utmp_ent), sizeof UT_ID (utmp_ent));
440 return comment;
443 static void
444 print_deadprocs (const STRUCT_UTMP *utmp_ent)
446 static char *exitstr;
447 char *comment = make_id_equals_comment (utmp_ent);
448 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
450 if (!exitstr)
451 exitstr = xmalloc (strlen (_("term="))
452 + INT_STRLEN_BOUND (UT_EXIT_E_TERMINATION (utmp_ent)) + 1
453 + strlen (_("exit="))
454 + INT_STRLEN_BOUND (UT_EXIT_E_EXIT (utmp_ent))
455 + 1);
456 sprintf (exitstr, "%s%d %s%d", _("term="), UT_EXIT_E_TERMINATION (utmp_ent),
457 _("exit="), UT_EXIT_E_EXIT (utmp_ent));
459 /* FIXME: add idle time? */
461 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
462 time_string (utmp_ent), "", pidstr, comment, exitstr);
463 free (comment);
466 static void
467 print_login (const STRUCT_UTMP *utmp_ent)
469 char *comment = make_id_equals_comment (utmp_ent);
470 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
472 /* FIXME: add idle time? */
474 print_line (-1, _("LOGIN"), ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
475 time_string (utmp_ent), "", pidstr, comment, "");
476 free (comment);
479 static void
480 print_initspawn (const STRUCT_UTMP *utmp_ent)
482 char *comment = make_id_equals_comment (utmp_ent);
483 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
485 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
486 time_string (utmp_ent), "", pidstr, comment, "");
487 free (comment);
490 static void
491 print_clockchange (const STRUCT_UTMP *utmp_ent)
493 /* FIXME: handle NEW_TIME & OLD_TIME both */
494 print_line (-1, "", ' ', -1, _("clock change"),
495 time_string (utmp_ent), "", "", "", "");
498 static void
499 print_runlevel (const STRUCT_UTMP *utmp_ent)
501 static char *runlevline, *comment;
502 unsigned char last = UT_PID (utmp_ent) / 256;
503 unsigned char curr = UT_PID (utmp_ent) % 256;
505 if (!runlevline)
506 runlevline = xmalloc (strlen (_("run-level")) + 3);
507 sprintf (runlevline, "%s %c", _("run-level"), curr);
509 if (!comment)
510 comment = xmalloc (strlen (_("last=")) + 2);
511 sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);
513 print_line (-1, "", ' ', -1, runlevline, time_string (utmp_ent),
514 "", "", c_isprint (last) ? comment : "", "");
516 return;
519 /* Print the username of each valid entry and the number of valid entries
520 in UTMP_BUF, which should have N elements. */
521 static void
522 list_entries_who (size_t n, const STRUCT_UTMP *utmp_buf)
524 unsigned long int entries = 0;
525 char const *separator = "";
527 while (n--)
529 if (IS_USER_PROCESS (utmp_buf))
531 char *trimmed_name;
533 trimmed_name = extract_trimmed_name (utmp_buf);
535 printf ("%s%s", separator, trimmed_name);
536 free (trimmed_name);
537 separator = " ";
538 entries++;
540 utmp_buf++;
542 printf (_("\n# users=%lu\n"), entries);
545 static void
546 print_heading (void)
548 print_line (-1, _("NAME"), ' ', -1, _("LINE"), _("TIME"), _("IDLE"),
549 _("PID"), _("COMMENT"), _("EXIT"));
552 /* Display UTMP_BUF, which should have N entries. */
553 static void
554 scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
556 char *ttyname_b IF_LINT ( = NULL);
557 time_t boottime = TYPE_MINIMUM (time_t);
559 if (include_heading)
560 print_heading ();
562 if (my_line_only)
564 ttyname_b = ttyname (STDIN_FILENO);
565 if (!ttyname_b)
566 return;
567 if (strncmp (ttyname_b, DEV_DIR_WITH_TRAILING_SLASH, DEV_DIR_LEN) == 0)
568 ttyname_b += DEV_DIR_LEN; /* Discard /dev/ prefix. */
571 while (n--)
573 if (!my_line_only ||
574 strncmp (ttyname_b, utmp_buf->ut_line,
575 sizeof (utmp_buf->ut_line)) == 0)
577 if (need_users && IS_USER_PROCESS (utmp_buf))
578 print_user (utmp_buf, boottime);
579 else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
580 print_runlevel (utmp_buf);
581 else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
582 print_boottime (utmp_buf);
583 /* I've never seen one of these, so I don't know what it should
584 look like :^)
585 FIXME: handle OLD_TIME also, perhaps show the delta? */
586 else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
587 print_clockchange (utmp_buf);
588 else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
589 print_initspawn (utmp_buf);
590 else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
591 print_login (utmp_buf);
592 else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
593 print_deadprocs (utmp_buf);
596 if (UT_TYPE_BOOT_TIME (utmp_buf))
597 boottime = UT_TIME_MEMBER (utmp_buf);
599 utmp_buf++;
603 /* Display a list of who is on the system, according to utmp file FILENAME.
604 Use read_utmp OPTIONS to read the file. */
605 static void
606 who (const char *filename, int options)
608 size_t n_users;
609 STRUCT_UTMP *utmp_buf;
611 if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
612 error (EXIT_FAILURE, errno, "%s", filename);
614 if (short_list)
615 list_entries_who (n_users, utmp_buf);
616 else
617 scan_entries (n_users, utmp_buf);
619 free (utmp_buf);
622 void
623 usage (int status)
625 if (status != EXIT_SUCCESS)
626 fprintf (stderr, _("Try `%s --help' for more information.\n"),
627 program_name);
628 else
630 printf (_("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n"), program_name);
631 fputs (_("\
632 Print information about users who are currently logged in.\n\
633 "), stdout);
634 fputs (_("\
636 -a, --all same as -b -d --login -p -r -t -T -u\n\
637 -b, --boot time of last system boot\n\
638 -d, --dead print dead processes\n\
639 -H, --heading print line of column headings\n\
640 "), stdout);
641 fputs (_("\
642 -l, --login print system login processes\n\
643 "), stdout);
644 fputs (_("\
645 --lookup attempt to canonicalize hostnames via DNS\n\
646 -m only hostname and user associated with stdin\n\
647 -p, --process print active processes spawned by init\n\
648 "), stdout);
649 fputs (_("\
650 -q, --count all login names and number of users logged on\n\
651 -r, --runlevel print current runlevel\n\
652 -s, --short print only name, line, and time (default)\n\
653 -t, --time print last system clock change\n\
654 "), stdout);
655 fputs (_("\
656 -T, -w, --mesg add user's message status as +, - or ?\n\
657 -u, --users list users logged in\n\
658 --message same as -T\n\
659 --writable same as -T\n\
660 "), stdout);
661 fputs (HELP_OPTION_DESCRIPTION, stdout);
662 fputs (VERSION_OPTION_DESCRIPTION, stdout);
663 printf (_("\
665 If FILE is not specified, use %s. %s as FILE is common.\n\
666 If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.\n\
667 "), UTMP_FILE, WTMP_FILE);
668 emit_bug_reporting_address ();
670 exit (status);
674 main (int argc, char **argv)
676 int optc;
677 bool assumptions = true;
679 initialize_main (&argc, &argv);
680 set_program_name (argv[0]);
681 setlocale (LC_ALL, "");
682 bindtextdomain (PACKAGE, LOCALEDIR);
683 textdomain (PACKAGE);
685 atexit (close_stdout);
687 while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, NULL))
688 != -1)
690 switch (optc)
692 case 'a':
693 need_boottime = true;
694 need_deadprocs = true;
695 need_login = true;
696 need_initspawn = true;
697 need_runlevel = true;
698 need_clockchange = true;
699 need_users = true;
700 include_mesg = true;
701 include_idle = true;
702 include_exit = true;
703 assumptions = false;
704 break;
706 case 'b':
707 need_boottime = true;
708 assumptions = false;
709 break;
711 case 'd':
712 need_deadprocs = true;
713 include_idle = true;
714 include_exit = true;
715 assumptions = false;
716 break;
718 case 'H':
719 include_heading = true;
720 break;
722 case 'l':
723 need_login = true;
724 include_idle = true;
725 assumptions = false;
726 break;
728 case 'm':
729 my_line_only = true;
730 break;
732 case 'p':
733 need_initspawn = true;
734 assumptions = false;
735 break;
737 case 'q':
738 short_list = true;
739 break;
741 case 'r':
742 need_runlevel = true;
743 include_idle = true;
744 assumptions = false;
745 break;
747 case 's':
748 short_output = true;
749 break;
751 case 't':
752 need_clockchange = true;
753 assumptions = false;
754 break;
756 case 'T':
757 case 'w':
758 include_mesg = true;
759 break;
761 case 'u':
762 need_users = true;
763 include_idle = true;
764 assumptions = false;
765 break;
767 case LOOKUP_OPTION:
768 do_lookup = true;
769 break;
771 case_GETOPT_HELP_CHAR;
773 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
775 default:
776 usage (EXIT_FAILURE);
780 if (assumptions)
782 need_users = true;
783 short_output = true;
786 if (include_exit)
788 short_output = false;
791 if (hard_locale (LC_TIME))
793 time_format = "%Y-%m-%d %H:%M";
794 time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
796 else
798 time_format = "%b %e %H:%M";
799 time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;
802 switch (argc - optind)
804 case 2: /* who <blurf> <glop> */
805 my_line_only = true;
806 /* Fall through. */
807 case -1:
808 case 0: /* who */
809 who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
810 break;
812 case 1: /* who <utmp file> */
813 who (argv[optind], 0);
814 break;
816 default: /* lose */
817 error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
818 usage (EXIT_FAILURE);
821 exit (EXIT_SUCCESS);