build: update gnulib submodule to latest
[coreutils.git] / src / who.c
blob7449ab1b447cb5adf1e93ff256b07b6a4a033c31
1 /* GNU's who.
2 Copyright (C) 1992-2011 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 #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 const char *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 char *ttyname (int);
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 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 const char *
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, const char *user, const char state,
242 int linelen, const char *line,
243 const char *time_str, const char *idle, const char *pid,
244 const char *comment, const char *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 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
347 /* Copy ut_line into LINE, prepending `/dev/' if ut_line is not
348 already an absolute file name. Some systems may put the full,
349 absolute file name in ut_line. */
350 if (utmp_ent->ut_line[0] == '/')
352 strncpy (line, utmp_ent->ut_line, sizeof (utmp_ent->ut_line));
353 line[sizeof (utmp_ent->ut_line)] = '\0';
355 else
357 strcpy (line, DEV_DIR_WITH_TRAILING_SLASH);
358 strncpy (line + DEV_DIR_LEN, utmp_ent->ut_line,
359 sizeof (utmp_ent->ut_line));
360 line[DEV_DIR_LEN + sizeof (utmp_ent->ut_line)] = '\0';
363 if (stat (line, &stats) == 0)
365 mesg = is_tty_writable (&stats) ? '+' : '-';
366 last_change = stats.st_atime;
368 else
370 mesg = '?';
371 last_change = 0;
374 if (last_change)
375 sprintf (idlestr, "%.*s", IDLESTR_LEN, idle_string (last_change, boottime));
376 else
377 sprintf (idlestr, " ?");
379 #if HAVE_UT_HOST
380 if (utmp_ent->ut_host[0])
382 char ut_host[sizeof (utmp_ent->ut_host) + 1];
383 char *host = NULL;
384 char *display = NULL;
386 /* Copy the host name into UT_HOST, and ensure it's nul terminated. */
387 strncpy (ut_host, utmp_ent->ut_host, sizeof (utmp_ent->ut_host));
388 ut_host[sizeof (utmp_ent->ut_host)] = '\0';
390 /* Look for an X display. */
391 display = strchr (ut_host, ':');
392 if (display)
393 *display++ = '\0';
395 if (*ut_host && do_lookup)
397 /* See if we can canonicalize it. */
398 host = canon_host (ut_host);
401 if (! host)
402 host = ut_host;
404 if (display)
406 if (hostlen < strlen (host) + strlen (display) + 4)
408 hostlen = strlen (host) + strlen (display) + 4;
409 free (hoststr);
410 hoststr = xmalloc (hostlen);
412 sprintf (hoststr, "(%s:%s)", host, display);
414 else
416 if (hostlen < strlen (host) + 3)
418 hostlen = strlen (host) + 3;
419 free (hoststr);
420 hoststr = xmalloc (hostlen);
422 sprintf (hoststr, "(%s)", host);
425 if (host != ut_host)
426 free (host);
428 else
430 if (hostlen < 1)
432 hostlen = 1;
433 free (hoststr);
434 hoststr = xmalloc (hostlen);
436 *hoststr = '\0';
438 #endif
440 print_line (sizeof UT_USER (utmp_ent), UT_USER (utmp_ent), mesg,
441 sizeof utmp_ent->ut_line, utmp_ent->ut_line,
442 time_string (utmp_ent), idlestr, pidstr,
443 hoststr ? hoststr : "", "");
446 static void
447 print_boottime (const STRUCT_UTMP *utmp_ent)
449 print_line (-1, "", ' ', -1, _("system boot"),
450 time_string (utmp_ent), "", "", "", "");
453 static char *
454 make_id_equals_comment (STRUCT_UTMP const *utmp_ent)
456 char *comment = xmalloc (strlen (_("id=")) + sizeof UT_ID (utmp_ent) + 1);
458 strcpy (comment, _("id="));
459 strncat (comment, UT_ID (utmp_ent), sizeof UT_ID (utmp_ent));
460 return comment;
463 static void
464 print_deadprocs (const STRUCT_UTMP *utmp_ent)
466 static char *exitstr;
467 char *comment = make_id_equals_comment (utmp_ent);
468 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
470 if (!exitstr)
471 exitstr = xmalloc (strlen (_("term="))
472 + INT_STRLEN_BOUND (UT_EXIT_E_TERMINATION (utmp_ent)) + 1
473 + strlen (_("exit="))
474 + INT_STRLEN_BOUND (UT_EXIT_E_EXIT (utmp_ent))
475 + 1);
476 sprintf (exitstr, "%s%d %s%d", _("term="), UT_EXIT_E_TERMINATION (utmp_ent),
477 _("exit="), UT_EXIT_E_EXIT (utmp_ent));
479 /* FIXME: add idle time? */
481 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
482 time_string (utmp_ent), "", pidstr, comment, exitstr);
483 free (comment);
486 static void
487 print_login (const STRUCT_UTMP *utmp_ent)
489 char *comment = make_id_equals_comment (utmp_ent);
490 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
492 /* FIXME: add idle time? */
494 print_line (-1, _("LOGIN"), ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
495 time_string (utmp_ent), "", pidstr, comment, "");
496 free (comment);
499 static void
500 print_initspawn (const STRUCT_UTMP *utmp_ent)
502 char *comment = make_id_equals_comment (utmp_ent);
503 PIDSTR_DECL_AND_INIT (pidstr, utmp_ent);
505 print_line (-1, "", ' ', sizeof utmp_ent->ut_line, utmp_ent->ut_line,
506 time_string (utmp_ent), "", pidstr, comment, "");
507 free (comment);
510 static void
511 print_clockchange (const STRUCT_UTMP *utmp_ent)
513 /* FIXME: handle NEW_TIME & OLD_TIME both */
514 print_line (-1, "", ' ', -1, _("clock change"),
515 time_string (utmp_ent), "", "", "", "");
518 static void
519 print_runlevel (const STRUCT_UTMP *utmp_ent)
521 static char *runlevline, *comment;
522 unsigned char last = UT_PID (utmp_ent) / 256;
523 unsigned char curr = UT_PID (utmp_ent) % 256;
525 if (!runlevline)
526 runlevline = xmalloc (strlen (_("run-level")) + 3);
527 sprintf (runlevline, "%s %c", _("run-level"), curr);
529 if (!comment)
530 comment = xmalloc (strlen (_("last=")) + 2);
531 sprintf (comment, "%s%c", _("last="), (last == 'N') ? 'S' : last);
533 print_line (-1, "", ' ', -1, runlevline, time_string (utmp_ent),
534 "", "", c_isprint (last) ? comment : "", "");
536 return;
539 /* Print the username of each valid entry and the number of valid entries
540 in UTMP_BUF, which should have N elements. */
541 static void
542 list_entries_who (size_t n, const STRUCT_UTMP *utmp_buf)
544 unsigned long int entries = 0;
545 char const *separator = "";
547 while (n--)
549 if (IS_USER_PROCESS (utmp_buf))
551 char *trimmed_name;
553 trimmed_name = extract_trimmed_name (utmp_buf);
555 printf ("%s%s", separator, trimmed_name);
556 free (trimmed_name);
557 separator = " ";
558 entries++;
560 utmp_buf++;
562 printf (_("\n# users=%lu\n"), entries);
565 static void
566 print_heading (void)
568 print_line (-1, _("NAME"), ' ', -1, _("LINE"), _("TIME"), _("IDLE"),
569 _("PID"), _("COMMENT"), _("EXIT"));
572 /* Display UTMP_BUF, which should have N entries. */
573 static void
574 scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
576 char *ttyname_b IF_LINT ( = NULL);
577 time_t boottime = TYPE_MINIMUM (time_t);
579 if (include_heading)
580 print_heading ();
582 if (my_line_only)
584 ttyname_b = ttyname (STDIN_FILENO);
585 if (!ttyname_b)
586 return;
587 if (STRNCMP_LIT (ttyname_b, DEV_DIR_WITH_TRAILING_SLASH) == 0)
588 ttyname_b += DEV_DIR_LEN; /* Discard /dev/ prefix. */
591 while (n--)
593 if (!my_line_only ||
594 strncmp (ttyname_b, utmp_buf->ut_line,
595 sizeof (utmp_buf->ut_line)) == 0)
597 if (need_users && IS_USER_PROCESS (utmp_buf))
598 print_user (utmp_buf, boottime);
599 else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
600 print_runlevel (utmp_buf);
601 else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
602 print_boottime (utmp_buf);
603 /* I've never seen one of these, so I don't know what it should
604 look like :^)
605 FIXME: handle OLD_TIME also, perhaps show the delta? */
606 else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
607 print_clockchange (utmp_buf);
608 else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
609 print_initspawn (utmp_buf);
610 else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
611 print_login (utmp_buf);
612 else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
613 print_deadprocs (utmp_buf);
616 if (UT_TYPE_BOOT_TIME (utmp_buf))
617 boottime = UT_TIME_MEMBER (utmp_buf);
619 utmp_buf++;
623 /* Display a list of who is on the system, according to utmp file FILENAME.
624 Use read_utmp OPTIONS to read the file. */
625 static void
626 who (const char *filename, int options)
628 size_t n_users;
629 STRUCT_UTMP *utmp_buf;
631 if (read_utmp (filename, &n_users, &utmp_buf, options) != 0)
632 error (EXIT_FAILURE, errno, "%s", filename);
634 if (short_list)
635 list_entries_who (n_users, utmp_buf);
636 else
637 scan_entries (n_users, utmp_buf);
639 free (utmp_buf);
642 void
643 usage (int status)
645 if (status != EXIT_SUCCESS)
646 fprintf (stderr, _("Try `%s --help' for more information.\n"),
647 program_name);
648 else
650 printf (_("Usage: %s [OPTION]... [ FILE | ARG1 ARG2 ]\n"), program_name);
651 fputs (_("\
652 Print information about users who are currently logged in.\n\
653 "), stdout);
654 fputs (_("\
656 -a, --all same as -b -d --login -p -r -t -T -u\n\
657 -b, --boot time of last system boot\n\
658 -d, --dead print dead processes\n\
659 -H, --heading print line of column headings\n\
660 "), stdout);
661 fputs (_("\
662 -l, --login print system login processes\n\
663 "), stdout);
664 fputs (_("\
665 --lookup attempt to canonicalize hostnames via DNS\n\
666 -m only hostname and user associated with stdin\n\
667 -p, --process print active processes spawned by init\n\
668 "), stdout);
669 fputs (_("\
670 -q, --count all login names and number of users logged on\n\
671 -r, --runlevel print current runlevel\n\
672 -s, --short print only name, line, and time (default)\n\
673 -t, --time print last system clock change\n\
674 "), stdout);
675 fputs (_("\
676 -T, -w, --mesg add user's message status as +, - or ?\n\
677 -u, --users list users logged in\n\
678 --message same as -T\n\
679 --writable same as -T\n\
680 "), stdout);
681 fputs (HELP_OPTION_DESCRIPTION, stdout);
682 fputs (VERSION_OPTION_DESCRIPTION, stdout);
683 printf (_("\
685 If FILE is not specified, use %s. %s as FILE is common.\n\
686 If ARG1 ARG2 given, -m presumed: `am i' or `mom likes' are usual.\n\
687 "), UTMP_FILE, WTMP_FILE);
688 emit_ancillary_info ();
690 exit (status);
694 main (int argc, char **argv)
696 int optc;
697 bool assumptions = true;
699 initialize_main (&argc, &argv);
700 set_program_name (argv[0]);
701 setlocale (LC_ALL, "");
702 bindtextdomain (PACKAGE, LOCALEDIR);
703 textdomain (PACKAGE);
705 atexit (close_stdout);
707 while ((optc = getopt_long (argc, argv, "abdlmpqrstuwHT", longopts, NULL))
708 != -1)
710 switch (optc)
712 case 'a':
713 need_boottime = true;
714 need_deadprocs = true;
715 need_login = true;
716 need_initspawn = true;
717 need_runlevel = true;
718 need_clockchange = true;
719 need_users = true;
720 include_mesg = true;
721 include_idle = true;
722 include_exit = true;
723 assumptions = false;
724 break;
726 case 'b':
727 need_boottime = true;
728 assumptions = false;
729 break;
731 case 'd':
732 need_deadprocs = true;
733 include_idle = true;
734 include_exit = true;
735 assumptions = false;
736 break;
738 case 'H':
739 include_heading = true;
740 break;
742 case 'l':
743 need_login = true;
744 include_idle = true;
745 assumptions = false;
746 break;
748 case 'm':
749 my_line_only = true;
750 break;
752 case 'p':
753 need_initspawn = true;
754 assumptions = false;
755 break;
757 case 'q':
758 short_list = true;
759 break;
761 case 'r':
762 need_runlevel = true;
763 include_idle = true;
764 assumptions = false;
765 break;
767 case 's':
768 short_output = true;
769 break;
771 case 't':
772 need_clockchange = true;
773 assumptions = false;
774 break;
776 case 'T':
777 case 'w':
778 include_mesg = true;
779 break;
781 case 'u':
782 need_users = true;
783 include_idle = true;
784 assumptions = false;
785 break;
787 case LOOKUP_OPTION:
788 do_lookup = true;
789 break;
791 case_GETOPT_HELP_CHAR;
793 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
795 default:
796 usage (EXIT_FAILURE);
800 if (assumptions)
802 need_users = true;
803 short_output = true;
806 if (include_exit)
808 short_output = false;
811 if (hard_locale (LC_TIME))
813 time_format = "%Y-%m-%d %H:%M";
814 time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
816 else
818 time_format = "%b %e %H:%M";
819 time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;
822 switch (argc - optind)
824 case 2: /* who <blurf> <glop> */
825 my_line_only = true;
826 /* Fall through. */
827 case -1:
828 case 0: /* who */
829 who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
830 break;
832 case 1: /* who <utmp file> */
833 who (argv[optind], 0);
834 break;
836 default: /* lose */
837 error (0, 0, _("extra operand %s"), quote (argv[optind + 2]));
838 usage (EXIT_FAILURE);
841 exit (EXIT_SUCCESS);