diff options
author | Tito Ragusa <farmatito@tiscali.it> | 2011-08-09 04:37:50 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-08-09 04:37:50 +0200 |
commit | 7926b989491e3968f229c7d7675afe130947bf31 (patch) | |
tree | 2e2ff5be36e030cfa1659dff5d46342fa20307e4 /coreutils | |
parent | d91b13806f41131fe55ece6027fa762f5da016ac (diff) | |
download | busybox-w32-7926b989491e3968f229c7d7675afe130947bf31.tar.gz busybox-w32-7926b989491e3968f229c7d7675afe130947bf31.tar.bz2 busybox-w32-7926b989491e3968f229c7d7675afe130947bf31.zip |
users: new applet.
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/Config.src | 7 | ||||
-rw-r--r-- | coreutils/who.c | 90 |
2 files changed, 62 insertions, 35 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src index 9aa04e946..65165d79b 100644 --- a/coreutils/Config.src +++ b/coreutils/Config.src | |||
@@ -725,13 +725,6 @@ config FEATURE_WC_LARGE | |||
725 | help | 725 | help |
726 | Use "unsigned long long" in wc for counter variables. | 726 | Use "unsigned long long" in wc for counter variables. |
727 | 727 | ||
728 | config WHO | ||
729 | bool "who" | ||
730 | default y | ||
731 | depends on FEATURE_UTMP | ||
732 | help | ||
733 | who is used to show who is logged on. | ||
734 | |||
735 | config WHOAMI | 728 | config WHOAMI |
736 | bool "whoami" | 729 | bool "whoami" |
737 | default y | 730 | default y |
diff --git a/coreutils/who.c b/coreutils/who.c index 9f37f65fd..c6c925264 100644 --- a/coreutils/who.c +++ b/coreutils/who.c | |||
@@ -18,6 +18,31 @@ | |||
18 | */ | 18 | */ |
19 | /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */ | 19 | /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */ |
20 | 20 | ||
21 | //config:config WHO | ||
22 | //config: bool "who" | ||
23 | //config: default y | ||
24 | //config: depends on FEATURE_UTMP | ||
25 | //config: help | ||
26 | //config: who is used to show who is logged on. | ||
27 | |||
28 | //config:config USERS | ||
29 | //config: bool "users" | ||
30 | //config: default y | ||
31 | //config: depends on FEATURE_UTMP | ||
32 | //config: help | ||
33 | //config: Print users currently logged on. | ||
34 | |||
35 | //applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users)) | ||
36 | //applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
37 | |||
38 | //kbuild:lib-$(CONFIG_USERS) += who.o | ||
39 | //kbuild:lib-$(CONFIG_WHO) += who.o | ||
40 | |||
41 | //usage:#define users_trivial_usage | ||
42 | //usage: "" | ||
43 | //usage:#define users_full_usage "\n\n" | ||
44 | //usage: "Print the users currently logged on" | ||
45 | |||
21 | //usage:#define who_trivial_usage | 46 | //usage:#define who_trivial_usage |
22 | //usage: "[-a]" | 47 | //usage: "[-a]" |
23 | //usage:#define who_full_usage "\n\n" | 48 | //usage:#define who_full_usage "\n\n" |
@@ -49,9 +74,11 @@ int who_main(int argc UNUSED_PARAM, char **argv) | |||
49 | { | 74 | { |
50 | struct utmp *ut; | 75 | struct utmp *ut; |
51 | unsigned opt; | 76 | unsigned opt; |
77 | int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u')); | ||
78 | const char *fmt = "%s"; | ||
52 | 79 | ||
53 | opt_complementary = "=0"; | 80 | opt_complementary = "=0"; |
54 | opt = getopt32(argv, "aH"); | 81 | opt = getopt32(argv, do_users ? "" : "aH"); |
55 | if (opt & 2) // -H | 82 | if (opt & 2) // -H |
56 | printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n"); | 83 | printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n"); |
57 | 84 | ||
@@ -60,36 +87,43 @@ int who_main(int argc UNUSED_PARAM, char **argv) | |||
60 | if (ut->ut_user[0] | 87 | if (ut->ut_user[0] |
61 | && ((opt & 1) || ut->ut_type == USER_PROCESS) | 88 | && ((opt & 1) || ut->ut_type == USER_PROCESS) |
62 | ) { | 89 | ) { |
63 | char str6[6]; | 90 | if (!do_users) { |
64 | char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1]; | 91 | char str6[6]; |
65 | struct stat st; | 92 | char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1]; |
66 | time_t seconds; | 93 | struct stat st; |
94 | time_t seconds; | ||
67 | 95 | ||
68 | str6[0] = '?'; | 96 | str6[0] = '?'; |
69 | str6[1] = '\0'; | 97 | str6[1] = '\0'; |
70 | strcpy(name, "/dev/"); | 98 | strcpy(name, "/dev/"); |
71 | safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1, | 99 | safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1, |
72 | ut->ut_line, | 100 | ut->ut_line, |
73 | sizeof(ut->ut_line)+1 | 101 | sizeof(ut->ut_line)+1 |
74 | ); | 102 | ); |
75 | if (stat(name, &st) == 0) | 103 | if (stat(name, &st) == 0) |
76 | idle_string(str6, st.st_atime); | 104 | idle_string(str6, st.st_atime); |
77 | /* manpages say ut_tv.tv_sec *is* time_t, | 105 | /* manpages say ut_tv.tv_sec *is* time_t, |
78 | * but some systems have it wrong */ | 106 | * but some systems have it wrong */ |
79 | seconds = ut->ut_tv.tv_sec; | 107 | seconds = ut->ut_tv.tv_sec; |
80 | /* How wide time field can be? | 108 | /* How wide time field can be? |
81 | * "Nov 10 19:33:20": 15 chars | 109 | * "Nov 10 19:33:20": 15 chars |
82 | * "2010-11-10 19:33": 16 chars | 110 | * "2010-11-10 19:33": 16 chars |
83 | */ | 111 | */ |
84 | printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n", | 112 | printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n", |
85 | (int)sizeof(ut->ut_user), ut->ut_user, | 113 | (int)sizeof(ut->ut_user), ut->ut_user, |
86 | (int)sizeof(ut->ut_line), ut->ut_line, | 114 | (int)sizeof(ut->ut_line), ut->ut_line, |
87 | str6, | 115 | str6, |
88 | ctime(&seconds) + 4, | 116 | ctime(&seconds) + 4, |
89 | (int)sizeof(ut->ut_host), ut->ut_host | 117 | (int)sizeof(ut->ut_host), ut->ut_host |
90 | ); | 118 | ); |
119 | } else { | ||
120 | printf(fmt, ut->ut_user); | ||
121 | fmt = " %s"; | ||
122 | } | ||
91 | } | 123 | } |
92 | } | 124 | } |
125 | if (do_users) | ||
126 | bb_putchar('\n'); | ||
93 | if (ENABLE_FEATURE_CLEAN_UP) | 127 | if (ENABLE_FEATURE_CLEAN_UP) |
94 | endutent(); | 128 | endutent(); |
95 | return EXIT_SUCCESS; | 129 | return EXIT_SUCCESS; |