Most .c files (AUTHORS): Revert the WRITTEN_BY/AUTHORS change
[platform/upstream/coreutils.git] / src / who.c
1 /* GNU's who.
2    Copyright (C) 1992-2003 Free Software Foundation, Inc.
3
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 2, or (at your option)
7    any later version.
8
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.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 /* Written by jla; revised by djm; revised again by mstone */
19
20 /* Output format:
21    name [state] line time [activity] [pid] [comment] [exit]
22    state: -T
23    name, line, time: not -q
24    idle: -u
25 */
26
27 #include <config.h>
28 #include <getopt.h>
29 #include <stdio.h>
30
31 #include <sys/types.h>
32 #include "system.h"
33
34 #include "readutmp.h"
35 #include "error.h"
36
37 /* The official name of this program (e.g., no `g' prefix).  */
38 #define PROGRAM_NAME "who"
39
40 #define AUTHORS "Joseph Arceneaux", "David MacKenzie", "Michael Stone"
41
42 #ifndef MAXHOSTNAMELEN
43 # define MAXHOSTNAMELEN 64
44 #endif
45
46 #ifndef S_IWGRP
47 # define S_IWGRP 020
48 #endif
49
50 #ifndef USER_PROCESS
51 # define USER_PROCESS INT_MAX
52 #endif
53
54 #ifndef RUN_LVL
55 # define RUN_LVL INT_MAX
56 #endif
57
58 #ifndef INIT_PROCESS
59 # define INIT_PROCESS INT_MAX
60 #endif
61
62 #ifndef LOGIN_PROCESS
63 # define LOGIN_PROCESS INT_MAX
64 #endif
65
66 #ifndef DEAD_PROCESS
67 # define DEAD_PROCESS INT_MAX
68 #endif
69
70 #ifndef BOOT_TIME
71 # define BOOT_TIME 0
72 #endif
73
74 #ifndef NEW_TIME
75 # define NEW_TIME 0
76 #endif
77
78 #define IDLESTR_LEN 6
79
80 #if HAVE_STRUCT_XTMP_UT_PID
81 # define UT_PID(U) ((U)->ut_pid)
82 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
83   char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
84   sprintf (Var, "%d", (int) (Utmp_ent->ut_pid))
85 #else
86 # define UT_PID(U) 0
87 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
88   const char *Var = ""
89 #endif
90
91 #if HAVE_STRUCT_XTMP_UT_ID
92 # define UT_ID(U) ((U)->ut_id)
93 #else
94   /* Of course, sizeof "whatever" is the size of a pointer (often 4),
95      but that's ok, since the actual string has a length of only 2.  */
96 # define UT_ID(U) "??"
97 #endif
98
99 #define UT_TYPE_UNDEF 255
100
101 #if HAVE_STRUCT_XTMP_UT_TYPE
102 # define UT_TYPE(U) ((U)->ut_type)
103 #else
104 # define UT_TYPE(U) UT_TYPE_UNDEF
105 #endif
106
107 #define IS_USER_PROCESS(U)                      \
108   (UT_USER (utmp_buf)[0]                        \
109    && (UT_TYPE (utmp_buf) == USER_PROCESS       \
110        || (UT_TYPE (utmp_buf) == UT_TYPE_UNDEF  \
111            && UT_TIME_MEMBER (utmp_buf) != 0)))
112
113 int gethostname ();
114 char *ttyname ();
115 char *canon_host ();
116
117 /* The name this program was run with. */
118 char *program_name;
119
120 /* If nonzero, attempt to canonicalize hostnames via a DNS lookup. */
121 static int do_lookup;
122
123 /* If nonzero, display only a list of usernames and count of
124    the users logged on.
125    Ignored for `who am i'. */
126 static int short_list;
127
128 /* If nonzero, display only name, line, and time fields */
129 static int short_output;
130
131 /* If nonzero, display the hours:minutes since each user has touched
132    the keyboard, or "." if within the last minute, or "old" if
133    not within the last day. */
134 static int include_idle;
135
136 /* If nonzero, display a line at the top describing each field. */
137 static int include_heading;
138
139 /* If nonzero, display a `+' for each user if mesg y, a `-' if mesg n,
140    or a `?' if their tty cannot be statted. */
141 static int include_mesg;
142
143 /* If nonzero, display process termination & exit status */
144 static int include_exit;
145
146 /* If nonzero, display the last boot time */
147 static int need_boottime;
148
149 /* If nonzero, display dead processes */
150 static int need_deadprocs;
151
152 /* If nonzero, display processes waiting for user login */
153 static int need_login;
154
155 /* If nonzero, display processes started by init */
156 static int need_initspawn;
157
158 /* If nonzero, display the last clock change */
159 static int need_clockchange;
160
161 /* If nonzero, display the current runlevel */
162 static int need_runlevel;
163
164 /* If nonzero, display user processes */
165 static int need_users;
166
167 /* If nonzero, display info only for the controlling tty */
168 static int my_line_only;
169
170 /* for long options with no corresponding short option, use enum */
171 enum
172 {
173   LOOKUP_OPTION = CHAR_MAX + 1
174 };
175
176 static struct option const longopts[] = {
177   {"all", no_argument, NULL, 'a'},
178   {"boot", no_argument, NULL, 'b'},
179   {"count", no_argument, NULL, 'q'},
180   {"dead", no_argument, NULL, 'd'},
181   {"heading", no_argument, NULL, 'H'},
182   {"idle", no_argument, NULL, 'i'},
183   {"login", no_argument, NULL, 'l'},
184   {"lookup", no_argument, NULL, LOOKUP_OPTION},
185   {"message", no_argument, NULL, 'T'},
186   {"mesg", no_argument, NULL, 'T'},
187   {"process", no_argument, NULL, 'p'},
188   {"runlevel", no_argument, NULL, 'r'},
189   {"short", no_argument, NULL, 's'},
190   {"time", no_argument, NULL, 't'},
191   {"users", no_argument, NULL, 'u'},
192   {"writable", no_argument, NULL, 'T'},
193   {GETOPT_HELP_OPTION_DECL},
194   {GETOPT_VERSION_OPTION_DECL},
195   {NULL, 0, NULL, 0}
196 };
197
198 /* Return a string representing the time between WHEN and the time
199    that this function is first run.
200    FIXME: locale? */
201 static const char *
202 idle_string (time_t when)
203 {
204   static time_t now = 0;
205   static char idle_hhmm[IDLESTR_LEN];
206   time_t seconds_idle;
207
208   if (now == 0)
209     time (&now);
210
211   seconds_idle = now - when;
212   if (seconds_idle < 60)        /* One minute. */
213     return "  .  ";
214   if (seconds_idle < (24 * 60 * 60))    /* One day. */
215     {
216       sprintf (idle_hhmm, "%02d:%02d",
217                (int) (seconds_idle / (60 * 60)),
218                (int) ((seconds_idle % (60 * 60)) / 60));
219       return (const char *) idle_hhmm;
220     }
221   return _(" old ");
222 }
223
224 /* Return a standard time string, "mon dd hh:mm"
225    FIXME: handle localization */
226 static const char *
227 time_string (const STRUCT_UTMP *utmp_ent)
228 {
229   /* Don't take the address of UT_TIME_MEMBER directly.
230      Ulrich Drepper wrote:
231      ``... GNU libc (and perhaps other libcs as well) have extended
232      utmp file formats which do not use a simple time_t ut_time field.
233      In glibc, ut_time is a macro which selects for backward compatibility
234      the tv_sec member of a struct timeval value.''  */
235   time_t tm = UT_TIME_MEMBER (utmp_ent);
236
237   char *ptr = ctime (&tm) + 4;
238   ptr[12] = '\0';
239   return ptr;
240 }
241
242 /* Print formatted output line. Uses mostly arbitrary field sizes, probably
243    will need tweaking if any of the localization stuff is done, or for 64 bit
244    pids, etc. */
245 static void
246 print_line (const char *user, const char state, const char *line,
247             const char *time_str, const char *idle, const char *pid,
248             const char *comment, const char *exitstr)
249 {
250   static char mesg[3] = { ' ', 'x', '\0' };
251   char *buf;
252   char x_idle[1 + IDLESTR_LEN + 1];
253   char x_pid[1 + INT_STRLEN_BOUND (pid_t) + 1];
254   char *x_exitstr;
255   int err;
256
257   mesg[1] = state;
258
259   if (include_idle && !short_output)
260     sprintf (x_idle, " %-6s", idle);
261   else
262     *x_idle = '\0';
263
264   if (!short_output)
265     sprintf (x_pid, " %10s", pid);
266   else
267     *x_pid = '\0';
268
269   x_exitstr = xmalloc (include_exit ? 1 + MAX (12, strlen (exitstr)) + 1 : 1);
270   if (include_exit)
271     sprintf (x_exitstr, " %-12s", exitstr);
272   else
273     *x_exitstr = '\0';
274
275   err = asprintf (&buf,
276                   "%-8.8s"
277                   "%s"
278                   " %-12s"
279                   " %-12s"
280                   "%s"
281                   "%s"
282                   " %-8s"
283                   "%s"
284                   ,
285                   user ? user : "   .",
286                   include_mesg ? mesg : "",
287                   line,
288                   time_str,
289                   x_idle,
290                   x_pid,
291                   /* FIXME: it's not really clear whether the following
292                      field should be in the short_output.  A strict reading
293                      of SUSv2 would suggest not, but I haven't seen any
294                      implementations that actually work that way... */
295                   comment,
296                   x_exitstr
297                   );
298   if (err == -1)
299     xalloc_die ();
300
301   {
302     /* Remove any trailing spaces.  */
303     char *p = buf + strlen (buf);
304     while (*--p == ' ')
305       /* empty */;
306     *(p + 1) = '\0';
307   }
308
309   puts (buf);
310   free (buf);
311   free (x_exitstr);
312 }
313
314 /* Send properly parsed USER_PROCESS info to print_line */
315 static void
316 print_user (const STRUCT_UTMP *utmp_ent)
317 {
318   struct stat stats;
319   time_t last_change;
320   char mesg;
321   char idlestr[IDLESTR_LEN];
322   static char *hoststr;
323   static size_t hostlen;
324
325 #define DEV_DIR_WITH_TRAILING_SLASH "/dev/"
326 #define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
327
328   char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
329   PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
330
331   /* Copy ut_line into LINE, prepending `/dev/' if ut_line is not
332      already an absolute pathname.  Some system may put the full,
333      absolute pathname in ut_line.  */
334   if (utmp_ent->ut_line[0] == '/')
335     {
336       strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
337       line[sizeof (utmp_ent->ut_line)] = '\0';
338     }
339   else
340     {
341       strcpy (line, DEV_DIR_WITH_TRAILING_SLASH);
342       strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line,
343                sizeof (utmp_ent->ut_line));
344       line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0';
345     }
346
347   if (stat (line, &stats) == 0)
348     {
349       mesg = (stats.st_mode & S_IWGRP) ? '+' : '-';
350       last_change = stats.st_atime;
351     }
352   else
353     {
354       mesg = '?';
355       last_change = 0;
356     }
357
358   if (last_change)
359     sprintf (idlestr, "%.6s", idle_string (last_change));
360   else
361     sprintf (idlestr, "  ?");
362
363 #if HAVE_UT_HOST
364   if (utmp_ent->ut_host[0])
365     {
366       char ut_host[sizeof (utmp_ent->ut_host) + 1];
367       char *host = 0, *display = 0;
368
369       /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
370       strncpy (ut_host, utmp_ent->ut_host, (int) sizeof (utmp_ent->ut_host));
371       ut_host[sizeof (utmp_ent->ut_host)] = '\0';
372
373       /* Look for an X display.  */
374       display = strchr (ut_host, ':');
375       if (display)
376         *display++ = '\0';
377
378       if (*ut_host && do_lookup)
379         {
380           /* See if we can canonicalize it.  */
381           host = canon_host (ut_host);
382         }
383
384       if (! host)
385         host = ut_host;
386
387       if (display)
388         {
389           if (hostlen < strlen (host) + strlen (display) + 4)
390             {
391               hostlen = strlen (host) + strlen (display) + 4;
392               hoststr = (char *) realloc (hoststr, hostlen);
393             }
394           sprintf (hoststr, "(%s:%s)", host, display);
395         }
396       else
397         {
398           if (hostlen < strlen (host) + 3)
399             {
400               hostlen = strlen (host) + 3;
401               hoststr = (char *) realloc (hoststr, hostlen);
402             }
403           sprintf (hoststr, "(%s)", host);
404         }
405     }
406   else
407     {
408       if (hostlen < 1)
409         {
410           hostlen = 1;
411           hoststr = (char *) realloc (hoststr, hostlen);
412         }
413       stpcpy (hoststr, "");
414     }
415 #endif
416
417   print_line (UT_USER (utmp_ent), mesg, utmp_ent->ut_line,
418               time_string (utmp_ent), idlestr, pidstr,
419               hoststr ? hoststr : "", "");
420 }
421
422 static void
423 print_boottime (const STRUCT_UTMP *utmp_ent)
424 {
425   print_line ("", ' ', "system boot", time_string (utmp_ent), "", "", "", "");
426 }
427
428 static char *
429 make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
430 {
431   char *comment = xmalloc (strlen (_("id=")) + sizeof UT_ID (utmp_ent) + 1);
432
433   /* Cast field width argument to `int' to avoid warning from gcc.  */
434   sprintf (comment, "%s%.*s", _("id="), (int) sizeof UT_ID (utmp_ent),
435            UT_ID (utmp_ent));
436   return comment;
437 }
438
439 static void
440 print_deadprocs (const STRUCT_UTMP *utmp_ent)
441 {
442   static char *exitstr;
443   char *comment = make_id_equals_comment (utmp_ent);
444   PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
445
446   if (!exitstr)
447     exitstr = xmalloc (strlen (_("term="))
448                        + INT_STRLEN_BOUND (UT_EXIT_E_TERMINATION (utmp_ent)) + 1
449                        + strlen (_("exit="))
450                        + INT_STRLEN_BOUND (UT_EXIT_E_EXIT (utmp_ent))
451                        + 1);
452   sprintf (exitstr, "%s%d %s%d", _("term="), UT_EXIT_E_TERMINATION (utmp_ent),
453            _("exit="), UT_EXIT_E_EXIT (utmp_ent));
454
455   /* FIXME: add idle time? */
456
457   print_line ("", ' ', utmp_ent->ut_line,
458               time_string (utmp_ent), "", pidstr, comment, exitstr);
459   free (comment);
460 }
461
462 static void
463 print_login (const STRUCT_UTMP *utmp_ent)
464 {
465   char *comment = make_id_equals_comment (utmp_ent);
466   PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
467
468   /* FIXME: add idle time? */
469
470   print_line ("LOGIN", ' ', utmp_ent->ut_line,
471               time_string (utmp_ent), "", pidstr, comment, "");
472   free (comment);
473 }
474
475 static void
476 print_initspawn (const STRUCT_UTMP *utmp_ent)
477 {
478   char *comment = make_id_equals_comment (utmp_ent);
479   PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
480
481   print_line ("", ' ', utmp_ent->ut_line,
482               time_string (utmp_ent), "", pidstr, comment, "");
483   free (comment);
484 }
485
486 static void
487 print_clockchange (const STRUCT_UTMP *utmp_ent)
488 {
489   /* FIXME: handle NEW_TIME & OLD_TIME both */
490   print_line ("", ' ', _("clock change"),
491               time_string (utmp_ent), "", "", "", "");
492 }
493
494 static void
495 print_runlevel (const STRUCT_UTMP *utmp_ent)
496 {
497   static char *runlevline, *comment;
498   int last = UT_PID (utmp_ent) / 256;
499   int curr = UT_PID (utmp_ent) % 256;
500
501   if (!runlevline)
502     runlevline = xmalloc (strlen (_("run-level")) + 3);
503   sprintf (runlevline, "%s %c", _("run-level"), curr);
504
505   if (!comment)
506     comment = xmalloc (strlen (_("last=")) + 2);
507   sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);
508
509   print_line ("", ' ', runlevline, time_string (utmp_ent),
510               "", "", comment, "");
511
512   return;
513 }
514
515 /* Print the username of each valid entry and the number of valid entries
516    in UTMP_BUF, which should have N elements. */
517 static void
518 list_entries_who (int n, const STRUCT_UTMP *utmp_buf)
519 {
520   int entries = 0;
521
522   while (n--)
523     {
524       if (UT_USER (utmp_buf)[0] && UT_TYPE (utmp_buf) == USER_PROCESS)
525         {
526           char *trimmed_name;
527
528           trimmed_name = extract_trimmed_name (utmp_buf);
529
530           printf ("%s ", trimmed_name);
531           free (trimmed_name);
532           entries++;
533         }
534       utmp_buf++;
535     }
536   printf (_("\n# users=%u\n"), entries);
537 }
538
539 static void
540 print_heading (void)
541 {
542   print_line (_("NAME"), ' ', _("LINE"), _("TIME"), _("IDLE"), _("PID"),
543               _("COMMENT"), _("EXIT"));
544 }
545
546 /* Display UTMP_BUF, which should have N entries. */
547 static void
548 scan_entries (int n, const STRUCT_UTMP *utmp_buf)
549 {
550   char *ttyname_b IF_LINT ( = NULL);
551
552   if (include_heading)
553     print_heading ();
554
555   if (my_line_only)
556     {
557       ttyname_b = ttyname (0);
558       if (!ttyname_b)
559         return;
560       if (strncmp (ttyname_b, DEV_DIR_WITH_TRAILING_SLASH, DEV_DIR_LEN) == 0)
561         ttyname_b += DEV_DIR_LEN;       /* Discard /dev/ prefix.  */
562     }
563
564   while (n--)
565     {
566       if (!my_line_only ||
567           strncmp (ttyname_b, utmp_buf->ut_line,
568                    sizeof (utmp_buf->ut_line)) == 0)
569         {
570           if (need_users && IS_USER_PROCESS (utmp_buf))
571             print_user (utmp_buf);
572           else if (need_runlevel && UT_TYPE (utmp_buf) == RUN_LVL)
573             print_runlevel (utmp_buf);
574           else if (need_boottime && UT_TYPE (utmp_buf) == BOOT_TIME)
575             print_boottime (utmp_buf);
576           /* I've never seen one of these, so I don't know what it should
577              look like :^)
578              FIXME: handle OLD_TIME also, perhaps show the delta? */
579           else if (need_clockchange && UT_TYPE (utmp_buf) == NEW_TIME)
580             print_clockchange (utmp_buf);
581           else if (need_initspawn && UT_TYPE (utmp_buf) == INIT_PROCESS)
582             print_initspawn (utmp_buf);
583           else if (need_login && UT_TYPE (utmp_buf) == LOGIN_PROCESS)
584             print_login (utmp_buf);
585           else if (need_deadprocs && UT_TYPE (utmp_buf) == DEAD_PROCESS)
586             print_deadprocs (utmp_buf);
587         }
588
589       utmp_buf++;
590     }
591 }
592
593 /* Display a list of who is on the system, according to utmp file filename. */
594 static void
595 who (const char *filename)
596 {
597   int n_users;
598   STRUCT_UTMP *utmp_buf;
599   int fail = read_utmp (filename, &n_users, &utmp_buf);
600
601   if (fail)
602     error (EXIT_FAILURE, errno, "%s", filename);
603
604   if (short_list)
605     list_entries_who (n_users, utmp_buf);
606   else
607     scan_entries (n_users, utmp_buf);
608 }
609
610 void
611 usage (int status)
612 {
613   if (status != 0)
614     fprintf (stderr, _("Try `%s --help' for more information.\n"),
615              program_name);
616   else
617     {
618       printf (_("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n"), program_name);
619       fputs (_("\
620 \n\
621   -a, --all         same as -b -d --login -p -r -t -T -u\n\
622   -b, --boot        time of last system boot\n\
623   -d, --dead        print dead processes\n\
624   -H, --heading     print line of column headings\n\
625 "), stdout);
626       fputs (_("\
627   -i, --idle        add idle time as HOURS:MINUTES, . or old\n\
628                     (deprecated, use -u)\n\
629   -l, --login       print system login processes\n\
630 "), stdout);
631       fputs (_("\
632       --lookup      attempt to canonicalize hostnames via DNS\n\
633   -m                only hostname and user associated with stdin\n\
634   -p, --process     print active processes spawned by init\n\
635 "), stdout);
636       fputs (_("\
637   -q, --count       all login names and number of users logged on\n\
638   -r, --runlevel    print current runlevel\n\
639   -s, --short       print only name, line, and time (default)\n\
640   -t, --time        print last system clock change\n\
641 "), stdout);
642       fputs (_("\
643   -T, -w, --mesg    add user's message status as +, - or ?\n\
644   -u, --users       list users logged in\n\
645       --message     same as -T\n\
646       --writable    same as -T\n\
647 "), stdout);
648       fputs (HELP_OPTION_DESCRIPTION, stdout);
649       fputs (VERSION_OPTION_DESCRIPTION, stdout);
650       printf (_("\
651 \n\
652 If FILE is not specified, use %s.  %s as FILE is common.\n\
653 If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.\n\
654 "), UTMP_FILE, WTMP_FILE);
655       printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
656     }
657   exit (status);
658 }
659
660 int
661 main (int argc, char **argv)
662 {
663   int optc, longind;
664   int assumptions = 1;
665
666   initialize_main (&argc, &argv);
667   program_name = argv[0];
668   setlocale (LC_ALL, "");
669   bindtextdomain (PACKAGE, LOCALEDIR);
670   textdomain (PACKAGE);
671
672   atexit (close_stdout);
673
674   while ((optc = getopt_long (argc, argv, "abdilmpqrstuwHT", longopts,
675                               &longind)) != -1)
676     {
677       switch (optc)
678         {
679         case 0:
680           break;
681
682         case 'a':
683           need_boottime = 1;
684           need_deadprocs = 1;
685           need_login = 1;
686           need_initspawn = 1;
687           need_runlevel = 1;
688           need_clockchange = 1;
689           need_users = 1;
690           include_mesg = 1;
691           include_idle = 1;
692           include_exit = 1;
693           assumptions = 0;
694           break;
695
696         case 'b':
697           need_boottime = 1;
698           assumptions = 0;
699           break;
700
701         case 'd':
702           need_deadprocs = 1;
703           include_idle = 1;
704           include_exit = 1;
705           assumptions = 0;
706           break;
707
708         case 'H':
709           include_heading = 1;
710           break;
711
712         case 'l':
713           need_login = 1;
714           include_idle = 1;
715           assumptions = 0;
716           break;
717
718         case 'm':
719           my_line_only = 1;
720           break;
721
722         case 'p':
723           need_initspawn = 1;
724           assumptions = 0;
725           break;
726
727         case 'q':
728           short_list = 1;
729           break;
730
731         case 'r':
732           need_runlevel = 1;
733           include_idle = 1;
734           assumptions = 0;
735           break;
736
737         case 's':
738           short_output = 1;
739           break;
740
741         case 't':
742           need_clockchange = 1;
743           assumptions = 0;
744           break;
745
746         case 'T':
747         case 'w':
748           include_mesg = 1;
749           break;
750
751         case 'i':
752           error (0, 0,
753                  _("Warning: -i will be removed in a future release; \
754   use -u instead"));
755           /* Fall through.  */
756         case 'u':
757           need_users = 1;
758           include_idle = 1;
759           assumptions = 0;
760           break;
761
762         case LOOKUP_OPTION:
763           do_lookup = 1;
764           break;
765
766           case_GETOPT_HELP_CHAR;
767
768           case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
769
770         default:
771           usage (EXIT_FAILURE);
772         }
773     }
774
775   if (assumptions)
776     {
777       need_users = 1;
778       short_output = 1;
779     }
780
781   if (include_exit)
782     {
783       short_output = 0;
784     }
785
786   switch (argc - optind)
787     {
788     case -1:
789     case 0:                     /* who */
790       who (UTMP_FILE);
791       break;
792
793     case 1:                     /* who <utmp file> */
794       who (argv[optind]);
795       break;
796
797     case 2:                     /* who <blurf> <glop> */
798       my_line_only = 1;
799       who (UTMP_FILE);
800       break;
801
802     default:                    /* lose */
803       error (0, 0, _("too many arguments"));
804       usage (EXIT_FAILURE);
805     }
806
807   exit (EXIT_SUCCESS);
808 }