summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTito Ragusa2011-08-09 04:37:50 +0200
committerDenys Vlasenko2011-08-09 04:37:50 +0200
commit7926b989491e3968f229c7d7675afe130947bf31 (patch)
tree2e2ff5be36e030cfa1659dff5d46342fa20307e4
parentd91b13806f41131fe55ece6027fa762f5da016ac (diff)
downloadbusybox-7926b989491e3968f229c7d7675afe130947bf31.zip
busybox-7926b989491e3968f229c7d7675afe130947bf31.tar.gz
users: new applet.
Signed-off-by: Tito Ragusa <farmatito@tiscali.it> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/Config.src7
-rw-r--r--coreutils/who.c90
2 files changed, 62 insertions, 35 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index 9aa04e9..65165d7 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -725,13 +725,6 @@ config FEATURE_WC_LARGE
help
Use "unsigned long long" in wc for counter variables.
-config WHO
- bool "who"
- default y
- depends on FEATURE_UTMP
- help
- who is used to show who is logged on.
-
config WHOAMI
bool "whoami"
default y
diff --git a/coreutils/who.c b/coreutils/who.c
index 9f37f65..c6c9252 100644
--- a/coreutils/who.c
+++ b/coreutils/who.c
@@ -18,6 +18,31 @@
*/
/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
+//config:config WHO
+//config: bool "who"
+//config: default y
+//config: depends on FEATURE_UTMP
+//config: help
+//config: who is used to show who is logged on.
+
+//config:config USERS
+//config: bool "users"
+//config: default y
+//config: depends on FEATURE_UTMP
+//config: help
+//config: Print users currently logged on.
+
+//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users))
+//applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_USERS) += who.o
+//kbuild:lib-$(CONFIG_WHO) += who.o
+
+//usage:#define users_trivial_usage
+//usage: ""
+//usage:#define users_full_usage "\n\n"
+//usage: "Print the users currently logged on"
+
//usage:#define who_trivial_usage
//usage: "[-a]"
//usage:#define who_full_usage "\n\n"
@@ -49,9 +74,11 @@ int who_main(int argc UNUSED_PARAM, char **argv)
{
struct utmp *ut;
unsigned opt;
+ int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
+ const char *fmt = "%s";
opt_complementary = "=0";
- opt = getopt32(argv, "aH");
+ opt = getopt32(argv, do_users ? "" : "aH");
if (opt & 2) // -H
printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
@@ -60,36 +87,43 @@ int who_main(int argc UNUSED_PARAM, char **argv)
if (ut->ut_user[0]
&& ((opt & 1) || ut->ut_type == USER_PROCESS)
) {
- char str6[6];
- char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
- struct stat st;
- time_t seconds;
+ if (!do_users) {
+ char str6[6];
+ char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
+ struct stat st;
+ time_t seconds;
- str6[0] = '?';
- str6[1] = '\0';
- strcpy(name, "/dev/");
- safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
- ut->ut_line,
- sizeof(ut->ut_line)+1
- );
- if (stat(name, &st) == 0)
- idle_string(str6, st.st_atime);
- /* manpages say ut_tv.tv_sec *is* time_t,
- * but some systems have it wrong */
- seconds = ut->ut_tv.tv_sec;
- /* How wide time field can be?
- * "Nov 10 19:33:20": 15 chars
- * "2010-11-10 19:33": 16 chars
- */
- printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
- (int)sizeof(ut->ut_user), ut->ut_user,
- (int)sizeof(ut->ut_line), ut->ut_line,
- str6,
- ctime(&seconds) + 4,
- (int)sizeof(ut->ut_host), ut->ut_host
- );
+ str6[0] = '?';
+ str6[1] = '\0';
+ strcpy(name, "/dev/");
+ safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
+ ut->ut_line,
+ sizeof(ut->ut_line)+1
+ );
+ if (stat(name, &st) == 0)
+ idle_string(str6, st.st_atime);
+ /* manpages say ut_tv.tv_sec *is* time_t,
+ * but some systems have it wrong */
+ seconds = ut->ut_tv.tv_sec;
+ /* How wide time field can be?
+ * "Nov 10 19:33:20": 15 chars
+ * "2010-11-10 19:33": 16 chars
+ */
+ printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
+ (int)sizeof(ut->ut_user), ut->ut_user,
+ (int)sizeof(ut->ut_line), ut->ut_line,
+ str6,
+ ctime(&seconds) + 4,
+ (int)sizeof(ut->ut_host), ut->ut_host
+ );
+ } else {
+ printf(fmt, ut->ut_user);
+ fmt = " %s";
+ }
}
}
+ if (do_users)
+ bb_putchar('\n');
if (ENABLE_FEATURE_CLEAN_UP)
endutent();
return EXIT_SUCCESS;