aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-11 18:17:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-11 18:17:03 +0200
commit1bc0bd13b5bdeb352db5261c1eec229fe4eb1651 (patch)
tree7f8dcd7743eec53eff24e6a720a7187cab7a11ee
parent67918b32abb55d9ba6b329cf77660204d2385aa8 (diff)
downloadbusybox-w32-1bc0bd13b5bdeb352db5261c1eec229fe4eb1651.tar.gz
busybox-w32-1bc0bd13b5bdeb352db5261c1eec229fe4eb1651.tar.bz2
busybox-w32-1bc0bd13b5bdeb352db5261c1eec229fe4eb1651.zip
w: new applet, alias to "who -H"
function old new delta who_main 451 463 +12 packed_usage 31477 31485 +8 applet_main 1508 1512 +4 applet_names 2606 2608 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 26/0) Total: 26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/who.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/coreutils/who.c b/coreutils/who.c
index e6179bb00..ec9d25159 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,7 +40,8 @@
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_USERS(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_WHO) += who.o
@@ -44,6 +53,31 @@
44//usage:#define users_full_usage "\n\n" 53//usage:#define users_full_usage "\n\n"
45//usage: "Print the users currently logged on" 54//usage: "Print the users currently logged on"
46 55
56//usage:#define w_trivial_usage
57//usage: ""
58//usage:#define w_full_usage "\n\n"
59//usage: "Show who is logged on"
60//
61// procps-ng 3.3.10:
62// "\n -h, --no-header"
63// "\n -u, --no-current"
64// Ignores the username while figuring out the current process
65// and cpu times. To demonstrate this, do a "su" and do a "w" and a "w -u".
66// "\n -s, --short"
67// Short format. Don't print the login time, JCPU or PCPU times.
68// "\n -f, --from"
69// Toggle printing the from (remote hostname) field.
70// The default is for the from field to not be printed
71// "\n -i, --ip-addr"
72// Display IP address instead of hostname for from field.
73// "\n -o, --old-style"
74// Old style output. Prints blank space for idle times less than one minute.
75// Example output:
76// 17:28:00 up 4 days, 22:41, 4 users, load average: 0.84, 0.97, 0.90
77// USER TTY LOGIN@ IDLE JCPU PCPU WHAT
78// root tty1 Thu18 4days 4:33m 0.07s /bin/sh /etc/xdg/xfce4/xinitrc -- vt
79// root pts/1 Mon13 3:24m 1:01 0.01s w
80
47//usage:#define who_trivial_usage 81//usage:#define who_trivial_usage
48//usage: "[-a]" 82//usage: "[-a]"
49//usage:#define who_full_usage "\n\n" 83//usage:#define who_full_usage "\n\n"
@@ -74,14 +108,17 @@ static void idle_string(char *str6, time_t t)
74int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 108int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
75int who_main(int argc UNUSED_PARAM, char **argv) 109int who_main(int argc UNUSED_PARAM, char **argv)
76{ 110{
111#define CNT_APPLET (ENABLE_USERS + ENABLE_W + ENABLE_WHO)
112 int do_users = (ENABLE_USERS && (CNT_APPLET == 1 || applet_name[0] == 'u'));
113 int do_w = (ENABLE_W && (CNT_APPLET == 1 || applet_name[1] == '\0'));
114 int do_who = (ENABLE_WHO && (CNT_APPLET == 1 || applet_name[1] == 'h'));
77 struct utmpx *ut; 115 struct utmpx *ut;
78 unsigned opt; 116 unsigned opt;
79 int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
80 const char *fmt = "%s"; 117 const char *fmt = "%s";
81 118
82 opt_complementary = "=0"; 119 opt_complementary = "=0";
83 opt = getopt32(argv, do_users ? "" : "aH"); 120 opt = getopt32(argv, do_who ? "aH" : "");
84 if (opt & 2) // -H 121 if ((opt & 2) || do_w) /* -H or we are w */
85 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST"); 122 puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
86 123
87 setutxent(); 124 setutxent();
@@ -115,6 +152,9 @@ int who_main(int argc UNUSED_PARAM, char **argv)
115 (int)sizeof(ut->ut_user), ut->ut_user, 152 (int)sizeof(ut->ut_user), ut->ut_user,
116 (int)sizeof(ut->ut_line), ut->ut_line, 153 (int)sizeof(ut->ut_line), ut->ut_line,
117 str6, 154 str6,
155// TODO: with LANG=en_US.UTF-8, who from coreutils 8.25 shows
156// TIME col as "2017-04-06 18:47" (the default format is "Apr 6 18:47").
157// The former format looks saner to me. Switch to it unconditionally?
118 ctime(&seconds) + 4, 158 ctime(&seconds) + 4,
119 (int)sizeof(ut->ut_host), ut->ut_host 159 (int)sizeof(ut->ut_host), ut->ut_host
120 ); 160 );