base64: always treat input in binary mode
[coreutils.git] / src / who.c
blob48596942d3f48c9dbd4a25ea1337b46ef90e5859
1 /* GNU's who.
2 Copyright (C) 1992-2010 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 "hard-locale.h"
38 #include "quote.h"
40 #ifdef TTY_GROUP_NAME
41 # include <grp.h>
42 #endif
44 /* The official name of this program (e.g., no `g' prefix). */
45 #define PROGRAM_NAME "who"
47 #define AUTHORS \
48 proper_name ("Joseph Arceneaux"), \
49 proper_name ("David MacKenzie"), \
50 proper_name ("Michael Stone")
52 #ifndef MAXHOSTNAMELEN
53 # define MAXHOSTNAMELEN 64
54 #endif
56 #ifdef RUN_LVL
57 # define UT_TYPE_RUN_LVL(U) UT_TYPE_EQ (U, RUN_LVL)
58 #else
59 # define UT_TYPE_RUN_LVL(U) false
60 #endif
62 #ifdef INIT_PROCESS
63 # define UT_TYPE_INIT_PROCESS(U) UT_TYPE_EQ (U, INIT_PROCESS)
64 #else
65 # define UT_TYPE_INIT_PROCESS(U) false
66 #endif
68 #ifdef LOGIN_PROCESS
69 # define UT_TYPE_LOGIN_PROCESS(U) UT_TYPE_EQ (U, LOGIN_PROCESS)
70 #else
71 # define UT_TYPE_LOGIN_PROCESS(U) false
72 #endif
74 #ifdef DEAD_PROCESS
75 # define UT_TYPE_DEAD_PROCESS(U) UT_TYPE_EQ (U, DEAD_PROCESS)
76 #else
77 # define UT_TYPE_DEAD_PROCESS(U) false
78 #endif
80 #ifdef NEW_TIME
81 # define UT_TYPE_NEW_TIME(U) UT_TYPE_EQ (U, NEW_TIME)
82 #else
83 # define UT_TYPE_NEW_TIME(U) false
84 #endif
86 #define IDLESTR_LEN 6
88 #if HAVE_STRUCT_XTMP_UT_PID
89 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
90 char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
91 sprintf (Var, "%ld", (long int) (Utmp_ent->ut_pid))
92 #else
93 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
94 const char *Var = ""
95 #endif
97 #if HAVE_STRUCT_XTMP_UT_ID
98 # define UT_ID(U) ((U)->ut_id)
99 #else
100 # define UT_ID(U) "??"
101 #endif
103 char *ttyname (int);
105 /* If true, attempt to canonicalize hostnames via a DNS lookup. */
106 static bool do_lookup;
108 /* If true, display only a list of usernames and count of
109 the users logged on.
110 Ignored for `who am i'. */
111 static bool short_list;
113 /* If true, display only name, line, and time fields. */
114 static bool short_output;
116 /* If true, display the hours:minutes since each user has touched
117 the keyboard, or "." if within the last minute, or "old" if
118 not within the last day. */
119 static bool include_idle;
121 /* If true, display a line at the top describing each field. */
122 static bool include_heading;
124 /* If true, display a `+' for each user if mesg y, a `-' if mesg n,
125 or a `?' if their tty cannot be statted. */
126 static bool include_mesg;
128 /* If true, display process termination & exit status. */
129 static bool include_exit;
131 /* If true, display the last boot time. */
132 static bool need_boottime;
134 /* If true, display dead processes. */
135 static bool need_deadprocs;
137 /* If true, display processes waiting for user login. */
138 static bool need_login;
140 /* If true, display processes started by init. */
141 static bool need_initspawn;
143 /* If true, display the last clock change. */
144 static bool need_clockchange;
146 /* If true, display the current runlevel. */
147 static bool need_runlevel;
149 /* If true, display user processes. */
150 static bool need_users;
152 /* If true, display info only for the controlling tty. */
153 static bool my_line_only;
155 /* The strftime format to use for login times, and its expected
156 output width. */
157 static char const *time_format;
158 static int time_format_width;
160 /* for long options with no corresponding short option, use enum */
161 enum
163 LOOKUP_OPTION = CHAR_MAX + 1
166 static struct option const longopts[] =
168 {"all", no_argument, NULL, 'a'},
169 {"boot", no_argument, NULL, 'b'},
170 {"count", no_argument, NULL, 'q'},
171 {"dead", no_argument, NULL, 'd'},
172 {"heading", no_argument, NULL, 'H'},
173 {"login", no_argument, NULL, 'l'},
174 {"lookup", no_argument, NULL, LOOKUP_OPTION},
175 {"message", no_argument, NULL, 'T'},
176 {"mesg", no_argument, NULL, 'T'},
177 {"process", no_argument, NULL, 'p'},
178 {"runlevel", no_argument, NULL, 'r'},
179 {"short", no_argument, NULL, 's'},
180 {"time", no_argument, NULL, 't'},
181 {"users", no_argument, NULL, 'u'},
182 {"writable", no_argument, NULL, 'T'},
183 {GETOPT_HELP_OPTION_DECL},
184 {GETOPT_VERSION_OPTION_DECL},
185 {NULL, 0, NULL, 0}
188 /* Return a string representing the time between WHEN and now.
189 BOOTTIME is the time of last reboot.
190 FIXME: locale? */
191 static const char *
192 idle_string (time_t when, time_t boottime)
194 static time_t now = TYPE_MINIMUM (time_t);
196 if (now == TYPE_MINIMUM (time_t))
197 time (&now);
199 if (boottime < when && now - 24 * 60 * 60 < when && when <= now)
201 int seconds_idle = now - when;
202 if (seconds_idle < 60)
203 return " . ";
204 else
206 static char idle_hhmm[IDLESTR_LEN];
207 sprintf (idle_hhmm, "%02d:%02d",
208 seconds_idle / (60 * 60),
209 (seconds_idle % (60 * 60)) / 60);
210 return idle_hhmm;
214 return _(" old ");
217 /* Return a time string. */
218 static const char *
219 time_string (const STRUCT_UTMP *utmp_ent)
221 static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];
223 /* Don't take the address of UT_TIME_MEMBER directly.
224 Ulrich Drepper wrote:
225 ``... GNU libc (and perhaps other libcs as well) have extended
226 utmp file formats which do not use a simple time_t ut_time field.
227 In glibc, ut_time is a macro which selects for backward compatibility
228 the tv_sec member of a struct timeval value.'' */
229 time_t t = UT_TIME_MEMBER (utmp_ent);
230 struct tm *tmp = localtime (&t);
232 if (tmp)
234 strftime (buf, sizeof buf, time_format, tmp);
235 return buf;
237 else
238 return timetostr (t, buf);
241 /* Print formatted output line. Uses mostly arbitrary field sizes, probably
242 will need tweaking if any of the localization stuff is done, or for 64 bit
243 pids, etc. */
244 static void
245 print_line (int userlen, const char *user, const char state,
246 int linelen, const char *line,
247 const char *time_str, const char *idle, const char *pid,
248 const char *comment, const char *exitstr)
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;
257 mesg[1] = state;
259 if (include_idle && !short_output && strlen (idle) < sizeof x_idle - 1)
260 sprintf (x_idle, " %-6s", idle);
261 else
262 *x_idle = '\0';
264 if (!short_output && strlen (pid) < sizeof x_pid - 1)
265 sprintf (x_pid, " %10s", pid);
266 else
267 *x_pid = '\0';
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';
275 err = asprintf (&buf,
276 "%-8.*s"
277 "%s"
278 " %-12.*s"
279 " %-*s"
280 "%s"
281 "%s"
282 " %-8s"
283 "%s"
285 userlen, user ? user : " .",
286 include_mesg ? mesg : "",
287 linelen, line,
288 time_format_width,
289 time_str,
290 x_idle,
291 x_pid,
292 /* FIXME: it's not really clear whether the following
293 field should be in the short_output. A strict reading
294 of SUSv2 would suggest not, but I haven't seen any
295 implementations that actually work that way... */
296 comment,
297 x_exitstr
299 if (err == -1)
300 xalloc_die ();
303 /* Remove any trailing spaces. */
304 char *p = buf + strlen (buf);
305 while (*--p == ' ')
306 /* empty */;
307 *(p + 1) = '\0';
310 puts (buf);
311 free (buf);
312 free (x_exitstr);
315 /* Return true if a terminal device given as PSTAT allows other users
316 to send messages to; false otherwise */
317 static bool
318 is_tty_writable (struct stat const *pstat)
320 #ifdef TTY_GROUP_NAME
321 /* Ensure the group of the TTY device matches TTY_GROUP_NAME, more info at
322 https://bugzilla.redhat.com/454261 */
323 struct group *ttygr = getgrnam (TTY_GROUP_NAME);
324 if (!ttygr || (pstat->st_gid != ttygr->gr_gid))
325 return false;
326 #endif
328 return pstat->st_mode & S_IWGRP;
331 /* Send properly parsed USER_PROCESS info to print_line. The most
332 recent boot time is BOOTTIME. */
333 static void
334 print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
336 struct stat stats;
337 time_t last_change;
338 char mesg;
339 char idlestr[IDLESTR_LEN + 1];
340 static char *hoststr;
341 #if HAVE_UT_HOST
342 static size_t hostlen;
343 #endif
345 #define DEV_DIR_WITH_TRAILING_SLASH "/dev/"
346 #define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
348 char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
349 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
351 /* Copy ut_line into LINE, prepending `/dev/' if ut_line is not
352 already an absolute file name. Some systems may put the full,
353 absolute file name in ut_line. */
354 if (utmp_ent->ut_line[0] == '/')
356 strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
357 line[sizeof (utmp_ent->ut_line)] = '\0';
359 else
361 strcpy (line, DEV_DIR_WITH_TRAILING_SLASH);
362 strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line,
363 sizeof (utmp_ent->ut_line));
364 line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0';
367 if (stat (line, &stats) == 0)
369 mesg = is_tty_writable (&stats) ? '+' : '-';
370 last_change = stats.st_atime;
372 else
374 mesg = '?';
375 last_change = 0;
378 if (last_change)
379 sprintf (idlestr, "%.*s", IDLESTR_LEN, idle_string (last_change, boottime));
380 else
381 sprintf (idlestr, " ?");
383 #if HAVE_UT_HOST
384 if (utmp_ent->ut_host[0])
386 char ut_host[sizeof (utmp_ent->ut_host) + 1];
387 char *host = NULL;
388 char *display = NULL;
390 /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
391 strncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
392 ut_host[sizeof (utmp_ent->ut_host)] = '\0';
394 /* Look for an X display. */
395 display = strchr (ut_host, ':');
396 if (display)
397 *display++ = '\0';
399 if (*ut_host && do_lookup)
401 /* See if we can canonicalize it. */
402 host = canon_host (ut_host);
405 if (! host)
406 host = ut_host;
408 if (display)
410 if (hostlen < strlen (host) + strlen (display) + 4)
412 hostlen = strlen (host) + strlen (display) + 4;
413 hoststr = xrealloc (hoststr, hostlen);
415 sprintf (hoststr, "(%s:%s)", host, display);
417 else
419 if (hostlen < strlen (host) + 3)
421 hostlen = strlen (host) + 3;
422 hoststr = xrealloc (hoststr, hostlen);
424 sprintf (hoststr, "(%s)", host);
427 if (host != ut_host)
428 free (host);
430 else
432 if (hostlen < 1)
434 hostlen = 1;
435 hoststr = xrealloc (hoststr, hostlen);
437 *hoststr = '\0';
439 #endif
441 print_line (sizeof UT_USER (utmp_ent), UT_USER (utmp_ent), mesg,
442 sizeof utmp_ent->ut_line, utmp_ent->ut_line,
443 time_string (utmp_ent), idlestr, pidstr,
444 hoststr ? hoststr : "", "");
447 static void
448 print_boottime (const STRUCT_UTMP *utmp_ent)
450 print_line (-1, "", ' ', -1, _("system boot"),
451 time_string (utmp_ent), "", "", "", "");
454 static char *
455 make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
457 char *comment = xmalloc (strlen (_("id=")) + sizeof UT_ID (utmp_ent) + 1);
459 strcpy (comment, _("id="));
460 strncat (comment, UT_ID (utmp_ent), sizeof UT_ID (utmp_ent));
461 return comment;
464 static void
465 print_deadprocs (const STRUCT_UTMP *utmp_ent)
467 static char *exitstr;
468 char *comment = make_id_equals_comment (utmp_ent);
469 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
471 if (!exitstr)
472 exitstr = xmalloc (strlen (_("term="))
473 + INT_STRLEN_BOUND (UT_EXIT_E_TERMINATION (utmp_ent)) + 1
474 + strlen (_("exit="))
475 + INT_STRLEN_BOUND (UT_EXIT_E_EXIT (utmp_ent))
476 + 1);
477 sprintf (exitstr, "%s%d %s%d", _("term="), UT_EXIT_E_TERMINATION (utmp_ent),
478 _("exit="), UT_EXIT_E_EXIT (utmp_ent));
480 /* FIXME: add idle time? */
482 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
483 time_string (utmp_ent), "", pidstr, comment, exitstr);
484 free (comment);
487 static void
488 print_login (const STRUCT_UTMP *utmp_ent)
490 char *comment = make_id_equals_comment (utmp_ent);
491 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
493 /* FIXME: add idle time? */
495 print_line (-1, _("LOGIN"), ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
496 time_string (utmp_ent), "", pidstr, comment, "");
497 free (comment);
500 static void
501 print_initspawn (const STRUCT_UTMP *utmp_ent)
503 char *comment = make_id_equals_comment (utmp_ent);
504 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
506 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
507 time_string (utmp_ent), "", pidstr, comment, "");
508 free (comment);
511 static void
512 print_clockchange (const STRUCT_UTMP *utmp_ent)
514 /* FIXME: handle NEW_TIME & OLD_TIME both */
515 print_line (-1, "", ' ', -1, _("clock change"),
516 time_string (utmp_ent), "", "", "", "");
519 static void
520 print_runlevel (const STRUCT_UTMP *utmp_ent)
522 static char *runlevline, *comment;
523 unsigned char last = UT_PID (utmp_ent) / 256;
524 unsigned char curr = UT_PID (utmp_ent) % 256;
526 if (!runlevline)
527 runlevline = xmalloc (strlen (_("run-level")) + 3);
528 sprintf (runlevline, "%s %c", _("run-level"), curr);
530 if (!comment)
531 comment = xmalloc (strlen (_("last=")) + 2);
532 sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);
534 print_line (-1, "", ' ', -1, runlevline, time_string (utmp_ent),
535 "", "", c_isprint (last) ? comment : "", "");
537 return;
540 /* Print the username of each valid entry and the number of valid entries
541 in UTMP_BUF, which should have N elements. */
542 static void
543 list_entries_who (size_t n, const STRUCT_UTMP *utmp_buf)
545 unsigned long int entries = 0;
546 char const *separator = "";
548 while (n--)
550 if (IS_USER_PROCESS (utmp_buf))
552 char *trimmed_name;
554 trimmed_name = extract_trimmed_name (utmp_buf);
556 printf ("%s%s", separator, trimmed_name);
557 free (trimmed_name);
558 separator = " ";
559 entries++;
561 utmp_buf++;
563 printf (_("\n# users=%lu\n"), entries);
566 static void
567 print_heading (void)
569 print_line (-1, _("NAME"), ' ', -1, _("LINE"), _("TIME"), _("IDLE"),
570 _("PID"), _("COMMENT"), _("EXIT"));
573 /* Display UTMP_BUF, which should have N entries. */
574 static void
575 scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
577 char *ttyname_b IF_LINT ( = NULL);
578 time_t boottime = TYPE_MINIMUM (time_t);
580 if (include_heading)
581 print_heading ();
583 if (my_line_only)
585 ttyname_b = ttyname (STDIN_FILENO);
586 if (!ttyname_b)
587 return;
588 if (strncmp (ttyname_b, DEV_DIR_WITH_TRAILING_SLASH, DEV_DIR_LEN) == 0)
589 ttyname_b += DEV_DIR_LEN; /* Discard /dev/ prefix. */
592 while (n--)
594 if (!my_line_only ||
595 strncmp (ttyname_b, utmp_buf->ut_line,
596 sizeof (utmp_buf->ut_line)) == 0)
598 if (need_users && IS_USER_PROCESS (utmp_buf))
599 print_user (utmp_buf, boottime);
600 else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
601 print_runlevel (utmp_buf);
602 else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
603 print_boottime (utmp_buf);
604 /* I've never seen one of these, so I don't know what it should
605 look like :^)
606 FIXME: handle OLD_TIME also, perhaps show the delta? */
607 else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
608 print_clockchange (utmp_buf);
609 else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
610 print_initspawn (utmp_buf);
611 else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
612 print_login (utmp_buf);
613 else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
614 print_deadprocs (utmp_buf);
617 if (UT_TYPE_BOOT_TIME (utmp_buf))
618 boottime = UT_TIME_MEMBER (utmp_buf);
620 utmp_buf++;
624 /* Display a list of who is on the system, according to utmp file FILENAME.
625 Use read_utmp OPTIONS to read the file. */
626 static void
627 who (const char *filename, int options)
629 size_t n_users;
630 STRUCT_UTMP *utmp_buf;
632 if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
633 error (EXIT_FAILURE, errno, "%s", filename);
635 if (short_list)
636 list_entries_who (n_users, utmp_buf);
637 else
638 scan_entries (n_users, utmp_buf);
640 free (utmp_buf);
643 void
644 usage (int status)
646 if (status != EXIT_SUCCESS)
647 fprintf (stderr, _("Try `%s --help' for more information.\n"),
648 program_name);
649 else
651 printf (_("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n"), program_name);
652 fputs (_("\
653 Print information about users who are currently logged in.\n\
654 "), stdout);
655 fputs (_("\
657 -a, --all same as -b -d --login -p -r -t -T -u\n\
658 -b, --boot time of last system boot\n\
659 -d, --dead print dead processes\n\
660 -H, --heading print line of column headings\n\
661 "), stdout);
662 fputs (_("\
663 -l, --login print system login processes\n\
664 "), stdout);
665 fputs (_("\
666 --lookup attempt to canonicalize hostnames via DNS\n\
667 -m only hostname and user associated with stdin\n\
668 -p, --process print active processes spawned by init\n\
669 "), stdout);
670 fputs (_("\
671 -q, --count all login names and number of users logged on\n\
672 -r, --runlevel print current runlevel\n\
673 -s, --short print only name, line, and time (default)\n\
674 -t, --time print last system clock change\n\
675 "), stdout);
676 fputs (_("\
677 -T, -w, --mesg add user's message status as +, - or ?\n\
678 -u, --users list users logged in\n\
679 --message same as -T\n\
680 --writable same as -T\n\
681 "), stdout);
682 fputs (HELP_OPTION_DESCRIPTION, stdout);
683 fputs (VERSION_OPTION_DESCRIPTION, stdout);
684 printf (_("\
686 If FILE is not specified, use %s. %s as FILE is common.\n\
687 If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.\n\
688 "), UTMP_FILE, WTMP_FILE);
689 emit_ancillary_info ();
691 exit (status);
695 main (int argc, char **argv)
697 int optc;
698 bool assumptions = true;
700 initialize_main (&argc, &argv);
701 set_program_name (argv[0]);
702 setlocale (LC_ALL, "");
703 bindtextdomain (PACKAGE, LOCALEDIR);
704 textdomain (PACKAGE);
706 atexit (close_stdout);
708 while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, NULL))
709 != -1)
711 switch (optc)
713 case 'a':
714 need_boottime = true;
715 need_deadprocs = true;
716 need_login = true;
717 need_initspawn = true;
718 need_runlevel = true;
719 need_clockchange = true;
720 need_users = true;
721 include_mesg = true;
722 include_idle = true;
723 include_exit = true;
724 assumptions = false;
725 break;
727 case 'b':
728 need_boottime = true;
729 assumptions = false;
730 break;
732 case 'd':
733 need_deadprocs = true;
734 include_idle = true;
735 include_exit = true;
736 assumptions = false;
737 break;
739 case 'H':
740 include_heading = true;
741 break;
743 case 'l':
744 need_login = true;
745 include_idle = true;
746 assumptions = false;
747 break;
749 case 'm':
750 my_line_only = true;
751 break;
753 case 'p':
754 need_initspawn = true;
755 assumptions = false;
756 break;
758 case 'q':
759 short_list = true;
760 break;
762 case 'r':
763 need_runlevel = true;
764 include_idle = true;
765 assumptions = false;
766 break;
768 case 's':
769 short_output = true;
770 break;
772 case 't':
773 need_clockchange = true;
774 assumptions = false;
775 break;
777 case 'T':
778 case 'w':
779 include_mesg = true;
780 break;
782 case 'u':
783 need_users = true;
784 include_idle = true;
785 assumptions = false;
786 break;
788 case LOOKUP_OPTION:
789 do_lookup = true;
790 break;
792 case_GETOPT_HELP_CHAR;
794 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
796 default:
797 usage (EXIT_FAILURE);
801 if (assumptions)
803 need_users = true;
804 short_output = true;
807 if (include_exit)
809 short_output = false;
812 if (hard_locale (LC_TIME))
814 time_format = "%Y-%m-%d %H:%M";
815 time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
817 else
819 time_format = "%b %e %H:%M";
820 time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;
823 switch (argc - optind)
825 case 2: /* who <blurf> <glop> */
826 my_line_only = true;
827 /* Fall through. */
828 case -1:
829 case 0: /* who */
830 who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
831 break;
833 case 1: /* who <utmp file> */
834 who (argv[optind], 0);
835 break;
837 default: /* lose */
838 error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
839 usage (EXIT_FAILURE);
842 exit (EXIT_SUCCESS);