• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   *
12   * TODO: -a doesn't know how to format other entries
13  
14  USE_WHO(NEWTOY(who, "a", TOYFLAG_USR|TOYFLAG_BIN))
15  
16  config WHO
17    bool "who"
18    default y
19    depends on TOYBOX_UTMPX
20    help
21      usage: who
22  
23      Print information about logged in users.
24  */
25  
26  #define FOR_who
27  #include "toys.h"
28  
who_main(void)29  void who_main(void)
30  {
31    struct utmpx *entry;
32  
33    setutxent();
34    while ((entry = getutxent())) {
35      if (FLAG(a) || entry->ut_type == USER_PROCESS) {
36        time_t t = entry->ut_tv.tv_sec;
37        struct tm *tm = localtime(&t);
38  
39        strftime(toybuf, sizeof(toybuf), "%F %H:%M", tm);
40        printf("%s\t%s\t%s (%s)\n", entry->ut_user, entry->ut_line,
41          toybuf, entry->ut_host);
42      }
43    }
44    endutxent();
45  }
46