numfmt: prefer signed types
[coreutils.git] / src / who.c
blobec0dff7923963a7df19d1421ce4c15741d112eda
1 /* GNU's who.
2 Copyright (C) 1992-2023 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 <stdckdint.h>
29 #include <stdio.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 "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 #ifdef RUN_LVL
53 # define UT_TYPE_RUN_LVL(U) UT_TYPE_EQ (U, RUN_LVL)
54 #else
55 # define UT_TYPE_RUN_LVL(U) false
56 #endif
58 #ifdef INIT_PROCESS
59 # define UT_TYPE_INIT_PROCESS(U) UT_TYPE_EQ (U, INIT_PROCESS)
60 #else
61 # define UT_TYPE_INIT_PROCESS(U) false
62 #endif
64 #ifdef LOGIN_PROCESS
65 # define UT_TYPE_LOGIN_PROCESS(U) UT_TYPE_EQ (U, LOGIN_PROCESS)
66 #else
67 # define UT_TYPE_LOGIN_PROCESS(U) false
68 #endif
70 #ifdef DEAD_PROCESS
71 # define UT_TYPE_DEAD_PROCESS(U) UT_TYPE_EQ (U, DEAD_PROCESS)
72 #else
73 # define UT_TYPE_DEAD_PROCESS(U) false
74 #endif
76 #ifdef NEW_TIME
77 # define UT_TYPE_NEW_TIME(U) UT_TYPE_EQ (U, NEW_TIME)
78 #else
79 # define UT_TYPE_NEW_TIME(U) false
80 #endif
82 #define IDLESTR_LEN 6
84 #if HAVE_STRUCT_XTMP_UT_PID
85 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
86 char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
87 sprintf (Var, "%ld", (long int) (Utmp_ent->ut_pid))
88 #else
89 # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
90 char const *Var = ""
91 #endif
93 #if HAVE_STRUCT_XTMP_UT_ID
94 # define UT_ID(U) ((U)->ut_id)
95 #else
96 # define UT_ID(U) "??"
97 #endif
99 /* If true, attempt to canonicalize hostnames via a DNS lookup. */
100 static bool do_lookup;
102 /* If true, display only a list of usernames and count of
103 the users logged on.
104 Ignored for 'who am i'. */
105 static bool short_list;
107 /* If true, display only name, line, and time fields. */
108 static bool short_output;
110 /* If true, display the hours:minutes since each user has touched
111 the keyboard, or "." if within the last minute, or "old" if
112 not within the last day. */
113 static bool include_idle;
115 /* If true, display a line at the top describing each field. */
116 static bool include_heading;
118 /* If true, display a '+' for each user if mesg y, a '-' if mesg n,
119 or a '?' if their tty cannot be statted. */
120 static bool include_mesg;
122 /* If true, display process termination & exit status. */
123 static bool include_exit;
125 /* If true, display the last boot time. */
126 static bool need_boottime;
128 /* If true, display dead processes. */
129 static bool need_deadprocs;
131 /* If true, display processes waiting for user login. */
132 static bool need_login;
134 /* If true, display processes started by init. */
135 static bool need_initspawn;
137 /* If true, display the last clock change. */
138 static bool need_clockchange;
140 /* If true, display the current runlevel. */
141 static bool need_runlevel;
143 /* If true, display user processes. */
144 static bool need_users;
146 /* If true, display info only for the controlling tty. */
147 static bool my_line_only;
149 /* The strftime format to use for login times, and its expected
150 output width. */
151 static char const *time_format;
152 static int time_format_width;
154 /* for long options with no corresponding short option, use enum */
155 enum
157 LOOKUP_OPTION = CHAR_MAX + 1
160 static struct option const longopts[] =
162 {"all", no_argument, nullptr, 'a'},
163 {"boot", no_argument, nullptr, 'b'},
164 {"count", no_argument, nullptr, 'q'},
165 {"dead", no_argument, nullptr, 'd'},
166 {"heading", no_argument, nullptr, 'H'},
167 {"login", no_argument, nullptr, 'l'},
168 {"lookup", no_argument, nullptr, LOOKUP_OPTION},
169 {"message", no_argument, nullptr, 'T'},
170 {"mesg", no_argument, nullptr, 'T'},
171 {"process", no_argument, nullptr, 'p'},
172 {"runlevel", no_argument, nullptr, 'r'},
173 {"short", no_argument, nullptr, 's'},
174 {"time", no_argument, nullptr, 't'},
175 {"users", no_argument, nullptr, 'u'},
176 {"writable", no_argument, nullptr, 'T'},
177 {GETOPT_HELP_OPTION_DECL},
178 {GETOPT_VERSION_OPTION_DECL},
179 {nullptr, 0, nullptr, 0}
182 /* Return a string representing the time between WHEN and now.
183 BOOTTIME is the time of last reboot.
184 FIXME: locale? */
185 static char const *
186 idle_string (time_t when, time_t boottime)
188 static time_t now = TYPE_MINIMUM (time_t);
190 if (now == TYPE_MINIMUM (time_t))
191 time (&now);
193 int seconds_idle;
194 if (boottime < when && when <= now
195 && ! ckd_sub (&seconds_idle, now, when)
196 && seconds_idle < 24 * 60 * 60)
198 if (seconds_idle < 60)
199 return " . ";
200 else
202 static char idle_hhmm[IDLESTR_LEN];
203 sprintf (idle_hhmm, "%02d:%02d",
204 seconds_idle / (60 * 60),
205 (seconds_idle % (60 * 60)) / 60);
206 return idle_hhmm;
210 return _(" old ");
213 /* Return a time string. */
214 static char const *
215 time_string (const STRUCT_UTMP *utmp_ent)
217 static char buf[INT_STRLEN_BOUND (intmax_t) + sizeof "-%m-%d %H:%M"];
219 /* Don't take the address of UT_TIME_MEMBER directly.
220 Ulrich Drepper wrote:
221 "... GNU libc (and perhaps other libcs as well) have extended
222 utmp file formats which do not use a simple time_t ut_time field.
223 In glibc, ut_time is a macro which selects for backward compatibility
224 the tv_sec member of a struct timeval value." */
225 time_t t = UT_TIME_MEMBER (utmp_ent);
226 struct tm *tmp = localtime (&t);
228 if (tmp)
230 strftime (buf, sizeof buf, time_format, tmp);
231 return buf;
233 else
234 return timetostr (t, buf);
237 /* Print formatted output line. Uses mostly arbitrary field sizes, probably
238 will need tweaking if any of the localization stuff is done, or for 64 bit
239 pids, etc. */
240 static void
241 print_line (int userlen, char const *user, const char state,
242 int linelen, char const *line,
243 char const *time_str, char const *idle, char const *pid,
244 char const *comment, char const *exitstr)
246 static char mesg[3] = { ' ', 'x', '\0' };
247 char *buf;
248 char x_idle[1 + IDLESTR_LEN + 1];
249 char x_pid[1 + INT_STRLEN_BOUND (pid_t) + 1];
250 char *x_exitstr;
251 int err;
253 mesg[1] = state;
255 if (include_idle && !short_output && strlen (idle) < sizeof x_idle - 1)
256 sprintf (x_idle, " %-6s", idle);
257 else
258 *x_idle = '\0';
260 if (!short_output && strlen (pid) < sizeof x_pid - 1)
261 sprintf (x_pid, " %10s", pid);
262 else
263 *x_pid = '\0';
265 x_exitstr = xmalloc (include_exit ? 1 + MAX (12, strlen (exitstr)) + 1 : 1);
266 if (include_exit)
267 sprintf (x_exitstr, " %-12s", exitstr);
268 else
269 *x_exitstr = '\0';
271 err = asprintf (&buf,
272 "%-8.*s"
273 "%s"
274 " %-12.*s"
275 " %-*s"
276 "%s"
277 "%s"
278 " %-8s"
279 "%s"
281 userlen, user ? user : " .",
282 include_mesg ? mesg : "",
283 linelen, line,
284 time_format_width,
285 time_str,
286 x_idle,
287 x_pid,
288 /* FIXME: it's not really clear whether the following
289 field should be in the short_output. A strict reading
290 of SUSv2 would suggest not, but I haven't seen any
291 implementations that actually work that way... */
292 comment,
293 x_exitstr
295 if (err == -1)
296 xalloc_die ();
299 /* Remove any trailing spaces. */
300 char *p = buf + strlen (buf);
301 while (*--p == ' ')
302 /* empty */;
303 *(p + 1) = '\0';
306 puts (buf);
307 free (buf);
308 free (x_exitstr);
311 /* Return true if a terminal device given as PSTAT allows other users
312 to send messages to; false otherwise */
313 static bool
314 is_tty_writable (struct stat const *pstat)
316 #ifdef TTY_GROUP_NAME
317 /* Ensure the group of the TTY device matches TTY_GROUP_NAME, more info at
318 https://bugzilla.redhat.com/454261 */
319 struct group *ttygr = getgrnam (TTY_GROUP_NAME);
320 if (!ttygr || (pstat->st_gid != ttygr->gr_gid))
321 return false;
322 #endif
324 return pstat->st_mode & S_IWGRP;
327 /* Send properly parsed USER_PROCESS info to print_line. The most
328 recent boot time is BOOTTIME. */
329 static void
330 print_user (const STRUCT_UTMP *utmp_ent, time_t boottime)
332 struct stat stats;
333 time_t last_change;
334 char mesg;
335 char idlestr[IDLESTR_LEN + 1];
336 static char *hoststr;
337 #if HAVE_UT_HOST
338 static size_t hostlen;
339 #endif
341 #define DEV_DIR_WITH_TRAILING_SLASH "/dev/"
342 #define DEV_DIR_LEN (sizeof (DEV_DIR_WITH_TRAILING_SLASH) - 1)
344 char line[sizeof (utmp_ent->ut_line) + DEV_DIR_LEN + 1];
345 char *p = line;
346 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
348 /* Copy ut_line into LINE, prepending '/dev/' if ut_line is not
349 already an absolute file name. Some systems may put the full,
350 absolute file name in ut_line. */
351 if ( ! IS_ABSOLUTE_FILE_NAME (utmp_ent->ut_line))
352 p = stpcpy (p, DEV_DIR_WITH_TRAILING_SLASH);
353 stzncpy (p, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
355 if (stat (line, &stats) == 0)
357 mesg = is_tty_writable (&stats) ? '+' : '-';
358 last_change = stats.st_atime;
360 else
362 mesg = '?';
363 last_change = 0;
366 if (last_change)
367 sprintf (idlestr, "%.*s", IDLESTR_LEN, idle_string (last_change, boottime));
368 else
369 sprintf (idlestr, " ?");
371 #if HAVE_UT_HOST
372 if (utmp_ent->ut_host[0])
374 char ut_host[sizeof (utmp_ent->ut_host) + 1];
375 char *host = nullptr;
376 char *display = nullptr;
378 /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
379 stzncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
381 /* Look for an X display. */
382 display = strchr (ut_host, ':');
383 if (display)
384 *display++ = '\0';
386 if (*ut_host && do_lookup)
388 /* See if we can canonicalize it. */
389 host = canon_host (ut_host);
392 if (! host)
393 host = ut_host;
395 if (display)
397 if (hostlen < strlen (host) + strlen (display) + 4)
399 hostlen = strlen (host) + strlen (display) + 4;
400 free (hoststr);
401 hoststr = xmalloc (hostlen);
403 sprintf (hoststr, "(%s:%s)", host, display);
405 else
407 if (hostlen < strlen (host) + 3)
409 hostlen = strlen (host) + 3;
410 free (hoststr);
411 hoststr = xmalloc (hostlen);
413 sprintf (hoststr, "(%s)", host);
416 if (host != ut_host)
417 free (host);
419 else
421 if (hostlen < 1)
423 hostlen = 1;
424 free (hoststr);
425 hoststr = xmalloc (hostlen);
427 *hoststr = '\0';
429 #endif
431 print_line (sizeof UT_USER (utmp_ent), UT_USER (utmp_ent), mesg,
432 sizeof utmp_ent->ut_line, utmp_ent->ut_line,
433 time_string (utmp_ent), idlestr, pidstr,
434 hoststr ? hoststr : "", "");
437 static void
438 print_boottime (const STRUCT_UTMP *utmp_ent)
440 print_line (-1, "", ' ', -1, _("system boot"),
441 time_string (utmp_ent), "", "", "", "");
444 static char *
445 make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
447 size_t utmpsize = sizeof UT_ID (utmp_ent);
448 char *comment = xmalloc (strlen (_("id=")) + utmpsize + 1);
450 char *p = stpcpy (comment, _("id="));
451 stzncpy (p, UT_ID (utmp_ent), utmpsize);
452 return comment;
455 static void
456 print_deadprocs (const STRUCT_UTMP *utmp_ent)
458 static char *exitstr;
459 char *comment = make_id_equals_comment (utmp_ent);
460 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
462 if (!exitstr)
463 exitstr = xmalloc (strlen (_("term="))
464 + INT_STRLEN_BOUND (UT_EXIT_E_TERMINATION (utmp_ent)) + 1
465 + strlen (_("exit="))
466 + INT_STRLEN_BOUND (UT_EXIT_E_EXIT (utmp_ent))
467 + 1);
468 sprintf (exitstr, "%s%d %s%d", _("term="), UT_EXIT_E_TERMINATION (utmp_ent),
469 _("exit="), UT_EXIT_E_EXIT (utmp_ent));
471 /* FIXME: add idle time? */
473 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
474 time_string (utmp_ent), "", pidstr, comment, exitstr);
475 free (comment);
478 static void
479 print_login (const STRUCT_UTMP *utmp_ent)
481 char *comment = make_id_equals_comment (utmp_ent);
482 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
484 /* FIXME: add idle time? */
486 print_line (-1, _("LOGIN"), ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
487 time_string (utmp_ent), "", pidstr, comment, "");
488 free (comment);
491 static void
492 print_initspawn (const STRUCT_UTMP *utmp_ent)
494 char *comment = make_id_equals_comment (utmp_ent);
495 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
497 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
498 time_string (utmp_ent), "", pidstr, comment, "");
499 free (comment);
502 static void
503 print_clockchange (const STRUCT_UTMP *utmp_ent)
505 /* FIXME: handle NEW_TIME & OLD_TIME both */
506 print_line (-1, "", ' ', -1, _("clock change"),
507 time_string (utmp_ent), "", "", "", "");
510 static void
511 print_runlevel (const STRUCT_UTMP *utmp_ent)
513 static char *runlevline, *comment;
514 unsigned char last = UT_PID (utmp_ent) / 256;
515 unsigned char curr = UT_PID (utmp_ent) % 256;
517 if (!runlevline)
518 runlevline = xmalloc (strlen (_("run-level")) + 3);
519 sprintf (runlevline, "%s %c", _("run-level"), curr);
521 if (!comment)
522 comment = xmalloc (strlen (_("last=")) + 2);
523 sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);
525 print_line (-1, "", ' ', -1, runlevline, time_string (utmp_ent),
526 "", "", c_isprint (last) ? comment : "", "");
528 return;
531 /* Print the username of each valid entry and the number of valid entries
532 in UTMP_BUF, which should have N elements. */
533 static void
534 list_entries_who (size_t n, const STRUCT_UTMP *utmp_buf)
536 unsigned long int entries = 0;
537 char const *separator = "";
539 while (n--)
541 if (IS_USER_PROCESS (utmp_buf))
543 char *trimmed_name;
545 trimmed_name = extract_trimmed_name (utmp_buf);
547 printf ("%s%s", separator, trimmed_name);
548 free (trimmed_name);
549 separator = " ";
550 entries++;
552 utmp_buf++;
554 printf (_("\n# users=%lu\n"), entries);
557 static void
558 print_heading (void)
560 print_line (-1, _("NAME"), ' ', -1, _("LINE"), _("TIME"), _("IDLE"),
561 _("PID"), _("COMMENT"), _("EXIT"));
564 /* Display UTMP_BUF, which should have N entries. */
565 static void
566 scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
568 char *ttyname_b IF_LINT ( = nullptr);
569 time_t boottime = TYPE_MINIMUM (time_t);
571 if (include_heading)
572 print_heading ();
574 if (my_line_only)
576 ttyname_b = ttyname (STDIN_FILENO);
577 if (!ttyname_b)
578 return;
579 if (STRNCMP_LIT (ttyname_b, DEV_DIR_WITH_TRAILING_SLASH) == 0)
580 ttyname_b += DEV_DIR_LEN; /* Discard /dev/ prefix. */
583 while (n--)
585 if (!my_line_only
586 || STREQ_LEN (ttyname_b, utmp_buf->ut_line,
587 sizeof (utmp_buf->ut_line)))
589 if (need_users && IS_USER_PROCESS (utmp_buf))
590 print_user (utmp_buf, boottime);
591 else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
592 print_runlevel (utmp_buf);
593 else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
594 print_boottime (utmp_buf);
595 /* I've never seen one of these, so I don't know what it should
596 look like :^)
597 FIXME: handle OLD_TIME also, perhaps show the delta? */
598 else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
599 print_clockchange (utmp_buf);
600 else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
601 print_initspawn (utmp_buf);
602 else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
603 print_login (utmp_buf);
604 else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
605 print_deadprocs (utmp_buf);
608 if (UT_TYPE_BOOT_TIME (utmp_buf))
609 boottime = UT_TIME_MEMBER (utmp_buf);
611 utmp_buf++;
615 /* Display a list of who is on the system, according to utmp file FILENAME.
616 Use read_utmp OPTIONS to read the file. */
617 static void
618 who (char const *filename, int options)
620 size_t n_users;
621 STRUCT_UTMP *utmp_buf;
623 if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
624 error (EXIT_FAILURE, errno, "%s", quotef (filename));
626 if (short_list)
627 list_entries_who (n_users, utmp_buf);
628 else
629 scan_entries (n_users, utmp_buf);
631 free (utmp_buf);
634 void
635 usage (int status)
637 if (status != EXIT_SUCCESS)
638 emit_try_help ();
639 else
641 printf (_("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n"), program_name);
642 fputs (_("\
643 Print information about users who are currently logged in.\n\
644 "), stdout);
645 fputs (_("\
647 -a, --all same as -b -d --login -p -r -t -T -u\n\
648 -b, --boot time of last system boot\n\
649 -d, --dead print dead processes\n\
650 -H, --heading print line of column headings\n\
651 "), stdout);
652 fputs (_("\
653 -l, --login print system login processes\n\
654 "), stdout);
655 fputs (_("\
656 --lookup attempt to canonicalize hostnames via DNS\n\
657 -m only hostname and user associated with stdin\n\
658 -p, --process print active processes spawned by init\n\
659 "), stdout);
660 fputs (_("\
661 -q, --count all login names and number of users logged on\n\
662 -r, --runlevel print current runlevel\n\
663 -s, --short print only name, line, and time (default)\n\
664 -t, --time print last system clock change\n\
665 "), stdout);
666 fputs (_("\
667 -T, -w, --mesg add user's message status as +, - or ?\n\
668 -u, --users list users logged in\n\
669 --message same as -T\n\
670 --writable same as -T\n\
671 "), stdout);
672 fputs (HELP_OPTION_DESCRIPTION, stdout);
673 fputs (VERSION_OPTION_DESCRIPTION, stdout);
674 printf (_("\
676 If FILE is not specified, use %s. %s as FILE is common.\n\
677 If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.\n\
678 "), UTMP_FILE, WTMP_FILE);
679 emit_ancillary_info (PROGRAM_NAME);
681 exit (status);
685 main (int argc, char **argv)
687 int optc;
688 bool assumptions = true;
690 initialize_main (&argc, &argv);
691 set_program_name (argv[0]);
692 setlocale (LC_ALL, "");
693 bindtextdomain (PACKAGE, LOCALEDIR);
694 textdomain (PACKAGE);
696 atexit (close_stdout);
698 while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, nullptr))
699 != -1)
701 switch (optc)
703 case 'a':
704 need_boottime = true;
705 need_deadprocs = true;
706 need_login = true;
707 need_initspawn = true;
708 need_runlevel = true;
709 need_clockchange = true;
710 need_users = true;
711 include_mesg = true;
712 include_idle = true;
713 include_exit = true;
714 assumptions = false;
715 break;
717 case 'b':
718 need_boottime = true;
719 assumptions = false;
720 break;
722 case 'd':
723 need_deadprocs = true;
724 include_idle = true;
725 include_exit = true;
726 assumptions = false;
727 break;
729 case 'H':
730 include_heading = true;
731 break;
733 case 'l':
734 need_login = true;
735 include_idle = true;
736 assumptions = false;
737 break;
739 case 'm':
740 my_line_only = true;
741 break;
743 case 'p':
744 need_initspawn = true;
745 assumptions = false;
746 break;
748 case 'q':
749 short_list = true;
750 break;
752 case 'r':
753 need_runlevel = true;
754 include_idle = true;
755 assumptions = false;
756 break;
758 case 's':
759 short_output = true;
760 break;
762 case 't':
763 need_clockchange = true;
764 assumptions = false;
765 break;
767 case 'T':
768 case 'w':
769 include_mesg = true;
770 break;
772 case 'u':
773 need_users = true;
774 include_idle = true;
775 assumptions = false;
776 break;
778 case LOOKUP_OPTION:
779 do_lookup = true;
780 break;
782 case_GETOPT_HELP_CHAR;
784 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
786 default:
787 usage (EXIT_FAILURE);
791 if (assumptions)
793 need_users = true;
794 short_output = true;
797 if (include_exit)
799 short_output = false;
802 if (hard_locale (LC_TIME))
804 time_format = "%Y-%m-%d %H:%M";
805 time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
807 else
809 time_format = "%b %e %H:%M";
810 time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;
813 switch (argc - optind)
815 case 2: /* who <blurf> <glop> */
816 my_line_only = true;
817 FALLTHROUGH;
818 case -1:
819 case 0: /* who */
820 who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
821 break;
823 case 1: /* who <utmp file> */
824 who (argv[optind], 0);
825 break;
827 default: /* lose */
828 error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
829 usage (EXIT_FAILURE);
832 return EXIT_SUCCESS;