aboutsummaryrefslogtreecommitdiff
path: root/coreutils/who.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/who.c')
-rw-r--r--coreutils/who.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/coreutils/who.c b/coreutils/who.c
index e6179bb00..4adead77e 100644
--- a/coreutils/who.c
+++ b/coreutils/who.c
@@ -23,6 +23,14 @@
23//config: help 23//config: help
24//config: who is used to show who is logged on. 24//config: who is used to show who is logged on.
25//config: 25//config:
26// procps-ng has this variation of "who":
27//config:config W
28//config: bool "w"
29//config: default y
30//config: depends on FEATURE_UTMP
31//config: help
32//config: w is used to show who is logged on.
33//config:
26//config:config USERS 34//config:config USERS
27//config: bool "users" 35//config: bool "users"
28//config: default y 36//config: default y
@@ -32,10 +40,12 @@
32 40
33// APPLET_ODDNAME:name main location suid_type help 41// APPLET_ODDNAME:name main location suid_type help
34//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users)) 42//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users))
35//applet:IF_WHO(APPLET(who, BB_DIR_USR_BIN, BB_SUID_DROP)) 43//applet:IF_W( APPLET_ODDNAME(w, who, BB_DIR_USR_BIN, BB_SUID_DROP, w))
44//applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP))
36 45
37//kbuild:lib-$(CONFIG_USERS) += who.o 46//kbuild:lib-$(CONFIG_USERS) += who.o
38//kbuild:lib-$(CONFIG_WHO) += who.o 47//kbuild:lib-$(CONFIG_W) += who.o
48//kbuild:lib-$(CONFIG_WHO) += who.o
39 49
40/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */ 50/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
41 51
@@ -44,6 +54,31 @@
44//usage:#define users_full_usage "\n\n" 54//usage:#define users_full_usage "\n\n"
45//usage: "Print the users currently logged on" 55//usage: "Print the users currently logged on"
46 56
57//usage:#define w_trivial_usage
58//usage: ""
59//usage:#define w_full_usage "\n\n"
60//usage: "Show who is logged on"
61//
62// procps-ng 3.3.10:
63// "\n -h, --no-header"
64// "\n -u, --no-current"
65// Ignores the username while figuring out the current process
66// and cpu times. To demonstrate this, do a "su" and do a "w" and a "w -u".
67// "\n -s, --short"
68// Short format. Don't print the login time, JCPU or PCPU times.
69// "\n -f, --from"
70// Toggle printing the from (remote hostname) field.
71// The default is for the from field to not be printed
72// "\n -i, --ip-addr"
73// Display IP address instead of hostname for from field.
74// "\n -o, --old-style"
75// Old style output. Prints blank space for idle times less than one minute.
76// Example output:
77// 17:28:00 up 4 days, 22:41, 4 users, load average: 0.84, 0.97, 0.90
78// USER TTY LOGIN@ IDLE JCPU PCPU WHAT
79// root tty1 Thu18 4days 4:33m 0.07s /bin/sh /etc/xdg/xfce4/xinitrc -- vt
80// root pts/1 Mon13 3:24m 1:01 0.01s w
81
47//usage:#define who_trivial_usage 82//usage:#define who_trivial_usage
48//usage: "[-a]" 83//usage: "[-a]"
49//usage:#define who_full_usage "\n\n" 84//usage:#define who_full_usage "\n\n"
@@ -74,14 +109,17 @@ static void idle_string(char *str6, time_t t)
74int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 109int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
75int who_main(int argc UNUSED_PARAM, char **argv) 110int who_main(int argc UNUSED_PARAM, char **argv)
76{ 111{
112#define CNT_APPLET (ENABLE_USERS + ENABLE_W + ENABLE_WHO)
113 int do_users = (ENABLE_USERS && (CNT_APPLET == 1 || applet_name[0] == 'u'));
114 int do_w = (ENABLE_W && (CNT_APPLET == 1 || applet_name[1] == '\0'));
115 int do_who = (ENABLE_WHO && (CNT_APPLET == 1 || applet_name[1] == 'h'));
77 struct utmpx *ut; 116 struct utmpx *ut;
78 unsigned opt; 117 unsigned opt;
79 int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
80 const char *fmt = "%s"; 118 const char *fmt = "%s";
81 119
82 opt_complementary = "=0"; 120 opt_complementary = "=0";
83 opt = getopt32(argv, do_users ? "" : "aH"); 121 opt = getopt32(argv, do_who ? "aH" : "");
84 if (opt & 2) // -H 122 if ((opt & 2) || do_w) /* -H or we are w */
85 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); 123 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
86 124
87 setutxent(); 125 setutxent();
@@ -115,6 +153,9 @@ int who_main(int argc UNUSED_PARAM, char **argv)
115 (int)sizeof(ut->ut_user), ut->ut_user, 153 (int)sizeof(ut->ut_user), ut->ut_user,
116 (int)sizeof(ut->ut_line), ut->ut_line, 154 (int)sizeof(ut->ut_line), ut->ut_line,
117 str6, 155 str6,
156// TODO: with LANG=en_US.UTF-8, who from coreutils 8.25 shows
157// TIME col as "2017-04-06 18:47" (the default format is "Apr 6 18:47").
158// The former format looks saner to me. Switch to it unconditionally?
118 ctime(&seconds) + 4, 159 ctime(&seconds) + 4,
119 (int)sizeof(ut->ut_host), ut->ut_host 160 (int)sizeof(ut->ut_host), ut->ut_host
120 ); 161 );