1/* who.c - display who is on the system
2 *
3 * Copyright 2012 ProFUSION Embedded Systems
4 *
5 * by Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
6 *
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/who.html
8 *
9 * Posix says to support many options (-abdHlmpqrstTu) but this
10 * isn't aimed at minicomputers with modem pools.
11
12USE_WHO(NEWTOY(who, "a", TOYFLAG_USR|TOYFLAG_BIN))
13
14config WHO
15  bool "who"
16  default y
17  depends on TOYBOX_UTMPX
18  help
19    usage: who
20
21    Print logged user information on system
22*/
23
24#define FOR_who
25#include "toys.h"
26
27void who_main(void)
28{
29  struct utmpx *entry;
30
31  setutxent();
32
33  while ((entry = getutxent())) {
34    if ((toys.optflags & FLAG_a) || entry->ut_type == USER_PROCESS) {
35      time_t time;
36      int time_size;
37      char *times;
38
39      time = entry->ut_tv.tv_sec;
40      times = ctime(&time);
41      time_size = strlen(times) - 2;
42      printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line,
43        time_size, time_size, ctime(&time), entry->ut_host);
44    }
45  }
46
47  endutxent();
48}
49