aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-01-31 13:11:47 -0800
committerRob Landley <rob@landley.net>2019-02-04 06:01:09 -0600
commitfa8a717bb908b526ab7b5fb5dfeeeda454d9d172 (patch)
treeaae66631c6eae2e0f874878459dbe87b7dada5f1 /toys/posix
parent354cc6aa0cf9f6d62dd879c4ab5a2c08257d76ed (diff)
downloadtoybox-fa8a717bb908b526ab7b5fb5dfeeeda454d9d172.tar.gz
who: make the output more like coreutils who.
Also add a TODO for the (undocumented, half-finished) -a option.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/who.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/toys/posix/who.c b/toys/posix/who.c
index 53252e87..2515af38 100644
--- a/toys/posix/who.c
+++ b/toys/posix/who.c
@@ -8,6 +8,8 @@
*
* Posix says to support many options (-abdHlmpqrstTu) but this
* isn't aimed at minicomputers with modem pools.
+ *
+ * TODO: -a doesn't know how to format other entries
USE_WHO(NEWTOY(who, "a", TOYFLAG_USR|TOYFLAG_BIN))
@@ -18,7 +20,7 @@ config WHO
help
usage: who
- Print logged user information on system
+ Print information about logged in users.
*/
#define FOR_who
@@ -29,20 +31,15 @@ void who_main(void)
struct utmpx *entry;
setutxent();
-
while ((entry = getutxent())) {
if (FLAG(a) || entry->ut_type == USER_PROCESS) {
- time_t time;
- int time_size;
- char *times;
+ time_t t = entry->ut_tv.tv_sec;
+ struct tm *tm = localtime(&t);
- time = entry->ut_tv.tv_sec;
- times = ctime(&time);
- time_size = strlen(times) - 2;
- printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line,
- time_size, time_size, ctime(&time), entry->ut_host);
+ strftime(toybuf, sizeof(toybuf), "%F %H:%M", tm);
+ printf("%s\t%s\t%s (%s)\n", entry->ut_user, entry->ut_line,
+ toybuf, entry->ut_host);
}
}
-
endutxent();
}