build: ensure sys/select.h is included
[coreutils.git] / src / who.c
blobd78fef0aa6d4115c8a667308bc290edf6aa64599
1 /* GNU's who.
2 Copyright (C) 1992-2019 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 <https://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>
29 #include <assert.h>
31 #include <sys/types.h>
32 #include "system.h"
34 #include "c-ctype.h"
35 #include "canon-host.h"
36 #include "readutmp.h"
37 #include "die.h"
38 #include "error.h"
39 #include "hard-locale.h"
40 #include "quote.h"
42 #ifdef TTY_GROUP_NAME
43 # include <grp.h>
44 #endif
46 /* The official name of this program (e.g., no 'g' prefix). */
47 #define PROGRAM_NAME "who"
49 #define AUTHORS \
50 proper_name ("Joseph Arceneaux"), \
51 proper_name ("David MacKenzie"), \
52 proper_name ("Michael Stone")
54 #ifdef RUN_LVL
55 # define UT_TYPE_RUN_LVL(U) UT_TYPE_EQ (U, RUN_LVL)
56 #else
57 # define UT_TYPE_RUN_LVL(U) false
58 #endif
60 #ifdef INIT_PROCESS
61 # define UT_TYPE_INIT_PROCESS(U) UT_TYPE_EQ (U, INIT_PROCESS)
62 #else
63 # define UT_TYPE_INIT_PROCESS(U) false
64 #endif
66 #ifdef LOGIN_PROCESS
67 # define UT_TYPE_LOGIN_PROCESS(U) UT_TYPE_EQ (U, LOGIN_PROCESS)
68 #else
69 # define UT_TYPE_LOGIN_PROCESS(U) false
70 #endif
72 #ifdef DEAD_PROCESS
73 # define UT_TYPE_DEAD_PROCESS(U) UT_TYPE_EQ (U, DEAD_PROCESS)
74 #else
75 # define UT_TYPE_DEAD_PROCESS(U) false
76 #endif
78 #ifdef NEW_TIME
79 # define UT_TYPE_NEW_TIME(U) UT_TYPE_EQ (U, NEW_TIME)
80 #else
81 # define UT_TYPE_NEW_TIME(U) false
82 #endif
84 #define IDLESTR_LEN 6
86 #if HAVE_STRUCT_XTMP_UT_PID
87 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
88 char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
89 sprintf (Var, "%ld", (long int) (Utmp_ent->ut_pid))
90 #else
91 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
92 const char *Var = ""
93 #endif
95 #if HAVE_STRUCT_XTMP_UT_ID
96 # define UT_ID(U) ((U)->ut_id)
97 #else
98 # define UT_ID(U) "??"
99 #endif
101 /* If true, attempt to canonicalize hostnames via a DNS lookup. */
102 static bool do_lookup;
104 /* If true, display only a list of usernames and count of
105 the users logged on.
106 Ignored for 'who am i'. */
107 static bool short_list;
109 /* If true, display only name, line, and time fields. */
110 static bool short_output;
112 /* If true, display the hours:minutes since each user has touched
113 the keyboard, or "." if within the last minute, or "old" if
114 not within the last day. */
115 static bool include_idle;
117 /* If true, display a line at the top describing each field. */
118 static bool include_heading;
120 /* If true, display a '+' for each user if mesg y, a '-' if mesg n,
121 or a '?' if their tty cannot be statted. */
122 static bool include_mesg;
124 /* If true, display process termination & exit status. */
125 static bool include_exit;
127 /* If true, display the last boot time. */
128 static bool need_boottime;
130 /* If true, display dead processes. */
131 static bool need_deadprocs;
133 /* If true, display processes waiting for user login. */
134 static bool need_login;
136 /* If true, display processes started by init. */
137 static bool need_initspawn;
139 /* If true, display the last clock change. */
140 static bool need_clockchange;
142 /* If true, display the current runlevel. */
143 static bool need_runlevel;
145 /* If true, display user processes. */
146 static bool need_users;
148 /* If true, display info only for the controlling tty. */
149 static bool my_line_only;
151 /* The strftime format to use for login times, and its expected
152 output width. */
153 static char const *time_format;
154 static int time_format_width;
156 /* for long options with no corresponding short option, use enum */
157 enum
159 LOOKUP_OPTION = CHAR_MAX + 1
162 static struct option const longopts[] =
164 {"all", no_argument, NULL, 'a'},
165 {"boot", no_argument, NULL, 'b'},
166 {"count", no_argument, NULL, 'q'},
167 {"dead", no_argument, NULL, 'd'},
168 {"heading", no_argument, NULL, 'H'},
169 {"login", no_argument, NULL, 'l'},
170 {"lookup", no_argument, NULL, LOOKUP_OPTION},
171 {"message", no_argument, NULL, 'T'},
172 {"mesg", no_argument, NULL, 'T'},
173 {"process", no_argument, NULL, 'p'},
174 {"runlevel", no_argument, NULL, 'r'},
175 {"short", no_argument, NULL, 's'},
176 {"time", no_argument, NULL, 't'},
177 {"users", no_argument, NULL, 'u'},
178 {"writable", no_argument, NULL, 'T'},
179 {GETOPT_HELP_OPTION_DECL},
180 {GETOPT_VERSION_OPTION_DECL},
181 {NULL, 0, NULL, 0}
184 /* Return a string representing the time between WHEN and now.
185 BOOTTIME is the time of last reboot.
186 FIXME: locale? */
187 static const char *
188 idle_string (time_t when, time_t boottime)
190 static time_t now = TYPE_MINIMUM (time_t);
192 if (now == TYPE_MINIMUM (time_t))
193 time (&now);
195 if (boottime < when && now - 24 * 60 * 60 < when && when <= now)
197 int seconds_idle = now - when;
198 if (seconds_idle < 60)
199 return " . ";
200 else
202 static char idle_hhmm[IDLESTR_LEN];
203 /* FIXME-in-2018: see if this assert is still required in order
204 to suppress gcc's unwarranted -Wformat-length= warning. */
205 assert (seconds_idle / (60 * 60) < 24);
206 sprintf (idle_hhmm, "%02d:%02d",
207 seconds_idle / (60 * 60),
208 (seconds_idle % (60 * 60)) / 60);
209 return idle_hhmm;
213 return _(" old ");
216 /* Return a time string. */
217 static const char *
218 time_string (const STRUCT_UTMP *utmp_ent)
220 static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];
222 /* Don't take the address of UT_TIME_MEMBER directly.
223 Ulrich Drepper wrote:
224 "... GNU libc (and perhaps other libcs as well) have extended
225 utmp file formats which do not use a simple time_t ut_time field.
226 In glibc, ut_time is a macro which selects for backward compatibility
227 the tv_sec member of a struct timeval value." */
228 time_t t = UT_TIME_MEMBER (utmp_ent);
229 struct tm *tmp = localtime (&t);
231 if (tmp)
233 strftime (buf, sizeof buf, time_format, tmp);
234 return buf;
236 else
237 return timetostr (t, buf);
240 /* Print formatted output line. Uses mostly arbitrary field sizes, probably
241 will need tweaking if any of the localization stuff is done, or for 64 bit
242 pids, etc. */
243 static void
244 print_line (int userlen, const char *user, const char state,
245 int linelen, const char *line,
246 const char *time_str, const char *idle, const char *pid,
247 const char *comment, const char *exitstr)
249 static char mesg[3] = { ' ', 'x', '\0' };
250 char *buf;
251 char x_idle[1 + IDLESTR_LEN + 1];
252 char x_pid[1 + INT_STRLEN_BOUND (pid_t) + 1];
253 char *x_exitstr;
254 int err;
256 mesg[1] = state;
258 if (include_idle && !short_output && strlen (idle) < sizeof x_idle - 1)
259 sprintf (x_idle, " %-6s", idle);
260 else
261 *x_idle = '\0';
263 if (!short_output && strlen (pid) < sizeof x_pid - 1)
264 sprintf (x_pid, " %10s", pid);
265 else
266 *x_pid = '\0';
268 x_exitstr = xmalloc (include_exit ? 1 + MAX (12, strlen (exitstr)) + 1 : 1);
269 if (include_exit)
270 sprintf (x_exitstr, " %-12s", exitstr);
271 else
272 *x_exitstr = '\0';
274 err = asprintf (&buf,
275 "%-8.*s"
276 "%s"
277 " %-12.*s"
278 " %-*s"
279 "%s"
280 "%s"
281 " %-8s"
282 "%s"
284 userlen, user ? user : " .",
285 include_mesg ? mesg : "",
286 linelen, line,
287 time_format_width,
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
298 if (err == -1)
299 xalloc_die ();
302 /* Remove any trailing spaces. */
303 char *p = buf + strlen (buf);
304 while (*--p == ' ')
305 /* empty */;
306 *(p + 1) = '\0';
309 puts (buf);
310 free (buf);
311 free (x_exitstr);
314 /* Return true if a terminal device given as PSTAT allows other users
315 to send messages to; false otherwise */
316 static bool
317 is_tty_writable (struct stat const *pstat)
319 #ifdef TTY_GROUP_NAME
320 /* Ensure the group of the TTY device matches TTY_GROUP_NAME, more info at
321 https://bugzilla.redhat.com/454261 */
322 struct group *ttygr = getgrnam (TTY_GROUP_NAME);
323 if (!ttygr || (pstat->st_gid != ttygr->gr_gid))
324 return false;
325 #endif
327 return pstat->st_mode & S_IWGRP;
330 /* Send properly parsed USER_PROCESS info to print_line. The most
331 recent boot time is BOOTTIME. */
332 static void
333 print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
335 struct stat stats;
336 time_t last_change;
337 char mesg;
338 char idlestr[IDLESTR_LEN + 1];
339 static char *hoststr;
340 #if HAVE_UT_HOST
341 static size_t hostlen;
342 #endif
344 #define DEV_DIR_WITH_TRAILING_SLASH "/dev/"
345 #define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
347 char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
348 char *p = line;
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 ( ! IS_ABSOLUTE_FILE_NAME (utmp_ent->ut_line))
355 p = stpcpy (p, DEV_DIR_WITH_TRAILING_SLASH);
356 stzncpy (p, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
358 if (stat (line, &stats) == 0)
360 mesg = is_tty_writable (&stats) ? '+' : '-';
361 last_change = stats.st_atime;
363 else
365 mesg = '?';
366 last_change = 0;
369 if (last_change)
370 sprintf (idlestr, "%.*s", IDLESTR_LEN, idle_string (last_change, boottime));
371 else
372 sprintf (idlestr, " ?");
374 #if HAVE_UT_HOST
375 if (utmp_ent->ut_host[0])
377 char ut_host[sizeof (utmp_ent->ut_host) + 1];
378 char *host = NULL;
379 char *display = NULL;
381 /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
382 stzncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
384 /* Look for an X display. */
385 display = strchr (ut_host, ':');
386 if (display)
387 *display++ = '\0';
389 if (*ut_host && do_lookup)
391 /* See if we can canonicalize it. */
392 host = canon_host (ut_host);
395 if (! host)
396 host = ut_host;
398 if (display)
400 if (hostlen < strlen (host) + strlen (display) + 4)
402 hostlen = strlen (host) + strlen (display) + 4;
403 free (hoststr);
404 hoststr = xmalloc (hostlen);
406 sprintf (hoststr, "(%s:%s)", host, display);
408 else
410 if (hostlen < strlen (host) + 3)
412 hostlen = strlen (host) + 3;
413 free (hoststr);
414 hoststr = xmalloc (hostlen);
416 sprintf (hoststr, "(%s)", host);
419 if (host != ut_host)
420 free (host);
422 else
424 if (hostlen < 1)
426 hostlen = 1;
427 free (hoststr);
428 hoststr = xmalloc (hostlen);
430 *hoststr = '\0';
432 #endif
434 print_line (sizeof UT_USER (utmp_ent), UT_USER (utmp_ent), mesg,
435 sizeof utmp_ent->ut_line, utmp_ent->ut_line,
436 time_string (utmp_ent), idlestr, pidstr,
437 hoststr ? hoststr : "", "");
440 static void
441 print_boottime (const STRUCT_UTMP *utmp_ent)
443 print_line (-1, "", ' ', -1, _("system boot"),
444 time_string (utmp_ent), "", "", "", "");
447 static char *
448 make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
450 size_t utmpsize = sizeof UT_ID (utmp_ent);
451 char *comment = xmalloc (strlen (_("id=")) + utmpsize + 1);
453 strcpy (comment, _("id="));
454 strncat (comment, UT_ID (utmp_ent), utmpsize);
455 return comment;
458 static void
459 print_deadprocs (const STRUCT_UTMP *utmp_ent)
461 static char *exitstr;
462 char *comment = make_id_equals_comment (utmp_ent);
463 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
465 if (!exitstr)
466 exitstr = xmalloc (strlen (_("term="))
467 + INT_STRLEN_BOUND (UT_EXIT_E_TERMINATION (utmp_ent)) + 1
468 + strlen (_("exit="))
469 + INT_STRLEN_BOUND (UT_EXIT_E_EXIT (utmp_ent))
470 + 1);
471 sprintf (exitstr, "%s%d %s%d", _("term="), UT_EXIT_E_TERMINATION (utmp_ent),
472 _("exit="), UT_EXIT_E_EXIT (utmp_ent));
474 /* FIXME: add idle time? */
476 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
477 time_string (utmp_ent), "", pidstr, comment, exitstr);
478 free (comment);
481 static void
482 print_login (const STRUCT_UTMP *utmp_ent)
484 char *comment = make_id_equals_comment (utmp_ent);
485 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
487 /* FIXME: add idle time? */
489 print_line (-1, _("LOGIN"), ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
490 time_string (utmp_ent), "", pidstr, comment, "");
491 free (comment);
494 static void
495 print_initspawn (const STRUCT_UTMP *utmp_ent)
497 char *comment = make_id_equals_comment (utmp_ent);
498 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
500 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
501 time_string (utmp_ent), "", pidstr, comment, "");
502 free (comment);
505 static void
506 print_clockchange (const STRUCT_UTMP *utmp_ent)
508 /* FIXME: handle NEW_TIME & OLD_TIME both */
509 print_line (-1, "", ' ', -1, _("clock change"),
510 time_string (utmp_ent), "", "", "", "");
513 static void
514 print_runlevel (const STRUCT_UTMP *utmp_ent)
516 static char *runlevline, *comment;
517 unsigned char last = UT_PID (utmp_ent) / 256;
518 unsigned char curr = UT_PID (utmp_ent) % 256;
520 if (!runlevline)
521 runlevline = xmalloc (strlen (_("run-level")) + 3);
522 sprintf (runlevline, "%s %c", _("run-level"), curr);
524 if (!comment)
525 comment = xmalloc (strlen (_("last=")) + 2);
526 sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);
528 print_line (-1, "", ' ', -1, runlevline, time_string (utmp_ent),
529 "", "", c_isprint (last) ? comment : "", "");
531 return;
534 /* Print the username of each valid entry and the number of valid entries
535 in UTMP_BUF, which should have N elements. */
536 static void
537 list_entries_who (size_t n, const STRUCT_UTMP *utmp_buf)
539 unsigned long int entries = 0;
540 char const *separator = "";
542 while (n--)
544 if (IS_USER_PROCESS (utmp_buf))
546 char *trimmed_name;
548 trimmed_name = extract_trimmed_name (utmp_buf);
550 printf ("%s%s", separator, trimmed_name);
551 free (trimmed_name);
552 separator = " ";
553 entries++;
555 utmp_buf++;
557 printf (_("\n# users=%lu\n"), entries);
560 static void
561 print_heading (void)
563 print_line (-1, _("NAME"), ' ', -1, _("LINE"), _("TIME"), _("IDLE"),
564 _("PID"), _("COMMENT"), _("EXIT"));
567 /* Display UTMP_BUF, which should have N entries. */
568 static void
569 scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
571 char *ttyname_b IF_LINT ( = NULL);
572 time_t boottime = TYPE_MINIMUM (time_t);
574 if (include_heading)
575 print_heading ();
577 if (my_line_only)
579 ttyname_b = ttyname (STDIN_FILENO);
580 if (!ttyname_b)
581 return;
582 if (STRNCMP_LIT (ttyname_b, DEV_DIR_WITH_TRAILING_SLASH) == 0)
583 ttyname_b += DEV_DIR_LEN; /* Discard /dev/ prefix. */
586 while (n--)
588 if (!my_line_only
589 || STREQ_LEN (ttyname_b, utmp_buf->ut_line,
590 sizeof (utmp_buf->ut_line)))
592 if (need_users && IS_USER_PROCESS (utmp_buf))
593 print_user (utmp_buf, boottime);
594 else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
595 print_runlevel (utmp_buf);
596 else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
597 print_boottime (utmp_buf);
598 /* I've never seen one of these, so I don't know what it should
599 look like :^)
600 FIXME: handle OLD_TIME also, perhaps show the delta? */
601 else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
602 print_clockchange (utmp_buf);
603 else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
604 print_initspawn (utmp_buf);
605 else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
606 print_login (utmp_buf);
607 else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
608 print_deadprocs (utmp_buf);
611 if (UT_TYPE_BOOT_TIME (utmp_buf))
612 boottime = UT_TIME_MEMBER (utmp_buf);
614 utmp_buf++;
618 /* Display a list of who is on the system, according to utmp file FILENAME.
619 Use read_utmp OPTIONS to read the file. */
620 static void
621 who (const char *filename, int options)
623 size_t n_users;
624 STRUCT_UTMP *utmp_buf;
626 if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
627 die (EXIT_FAILURE, errno, "%s", quotef (filename));
629 if (short_list)
630 list_entries_who (n_users, utmp_buf);
631 else
632 scan_entries (n_users, utmp_buf);
634 free (utmp_buf);
637 void
638 usage (int status)
640 if (status != EXIT_SUCCESS)
641 emit_try_help ();
642 else
644 printf (_("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n"), program_name);
645 fputs (_("\
646 Print information about users who are currently logged in.\n\
647 "), stdout);
648 fputs (_("\
650 -a, --all same as -b -d --login -p -r -t -T -u\n\
651 -b, --boot time of last system boot\n\
652 -d, --dead print dead processes\n\
653 -H, --heading print line of column headings\n\
654 "), stdout);
655 fputs (_("\
656 -l, --login print system login processes\n\
657 "), stdout);
658 fputs (_("\
659 --lookup attempt to canonicalize hostnames via DNS\n\
660 -m only hostname and user associated with stdin\n\
661 -p, --process print active processes spawned by init\n\
662 "), stdout);
663 fputs (_("\
664 -q, --count all login names and number of users logged on\n\
665 -r, --runlevel print current runlevel\n\
666 -s, --short print only name, line, and time (default)\n\
667 -t, --time print last system clock change\n\
668 "), stdout);
669 fputs (_("\
670 -T, -w, --mesg add user's message status as +, - or ?\n\
671 -u, --users list users logged in\n\
672 --message same as -T\n\
673 --writable same as -T\n\
674 "), stdout);
675 fputs (HELP_OPTION_DESCRIPTION, stdout);
676 fputs (VERSION_OPTION_DESCRIPTION, stdout);
677 printf (_("\
679 If FILE is not specified, use %s. %s as FILE is common.\n\
680 If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.\n\
681 "), UTMP_FILE, WTMP_FILE);
682 emit_ancillary_info (PROGRAM_NAME);
684 exit (status);
688 main (int argc, char **argv)
690 int optc;
691 bool assumptions = true;
693 initialize_main (&argc, &argv);
694 set_program_name (argv[0]);
695 setlocale (LC_ALL, "");
696 bindtextdomain (PACKAGE, LOCALEDIR);
697 textdomain (PACKAGE);
699 atexit (close_stdout);
701 while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, NULL))
702 != -1)
704 switch (optc)
706 case 'a':
707 need_boottime = true;
708 need_deadprocs = true;
709 need_login = true;
710 need_initspawn = true;
711 need_runlevel = true;
712 need_clockchange = true;
713 need_users = true;
714 include_mesg = true;
715 include_idle = true;
716 include_exit = true;
717 assumptions = false;
718 break;
720 case 'b':
721 need_boottime = true;
722 assumptions = false;
723 break;
725 case 'd':
726 need_deadprocs = true;
727 include_idle = true;
728 include_exit = true;
729 assumptions = false;
730 break;
732 case 'H':
733 include_heading = true;
734 break;
736 case 'l':
737 need_login = true;
738 include_idle = true;
739 assumptions = false;
740 break;
742 case 'm':
743 my_line_only = true;
744 break;
746 case 'p':
747 need_initspawn = true;
748 assumptions = false;
749 break;
751 case 'q':
752 short_list = true;
753 break;
755 case 'r':
756 need_runlevel = true;
757 include_idle = true;
758 assumptions = false;
759 break;
761 case 's':
762 short_output = true;
763 break;
765 case 't':
766 need_clockchange = true;
767 assumptions = false;
768 break;
770 case 'T':
771 case 'w':
772 include_mesg = true;
773 break;
775 case 'u':
776 need_users = true;
777 include_idle = true;
778 assumptions = false;
779 break;
781 case LOOKUP_OPTION:
782 do_lookup = true;
783 break;
785 case_GETOPT_HELP_CHAR;
787 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
789 default:
790 usage (EXIT_FAILURE);
794 if (assumptions)
796 need_users = true;
797 short_output = true;
800 if (include_exit)
802 short_output = false;
805 if (hard_locale (LC_TIME))
807 time_format = "%Y-%m-%d %H:%M";
808 time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
810 else
812 time_format = "%b %e %H:%M";
813 time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;
816 switch (argc - optind)
818 case 2: /* who <blurf> <glop> */
819 my_line_only = true;
820 FALLTHROUGH;
821 case -1:
822 case 0: /* who */
823 who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
824 break;
826 case 1: /* who <utmp file> */
827 who (argv[optind], 0);
828 break;
830 default: /* lose */
831 error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
832 usage (EXIT_FAILURE);
835 return EXIT_SUCCESS;