1 /* vi: set sw=4 ts=4: */
2 /*----------------------------------------------------------------------
3 * Mini who is used to display user name, login time,
4 * idle time and host name.
6 * Author: Da Chen <dchen@ayrnetworks.com>
8 * This is a free document; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation:
11 * http://www.gnu.org/copyleft/gpl.html
13 * Copyright (c) 2002 AYR Networks, Inc.
15 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
17 *----------------------------------------------------------------------
19 /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
23 static void idle_string(char *str6, time_t t)
32 if (t >= 0 && t < (24 * 60 * 60)) {
33 sprintf(str6, "%02d:%02d",
34 (int) (t / (60 * 60)),
35 (int) ((t % (60 * 60)) / 60));
41 int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
42 int who_main(int argc UNUSED_PARAM, char **argv)
47 opt_complementary = "=0";
48 opt = getopt32(argv, "aH");
50 printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n");
53 while ((ut = getutent()) != NULL) {
55 && ((opt & 1) || ut->ut_type == USER_PROCESS)
58 char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
64 strcpy(name, "/dev/");
65 safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
69 if (stat(name, &st) == 0)
70 idle_string(str6, st.st_atime);
71 /* manpages say ut_tv.tv_sec *is* time_t,
72 * but some systems have it wrong */
73 seconds = ut->ut_tv.tv_sec;
74 /* How wide time field can be?
75 * "Nov 10 19:33:20": 15 chars
76 * "2010-11-10 19:33": 16 chars
78 printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
79 (int)sizeof(ut->ut_user), ut->ut_user,
80 (int)sizeof(ut->ut_line), ut->ut_line,
83 (int)sizeof(ut->ut_host), ut->ut_host
87 if (ENABLE_FEATURE_CLEAN_UP)