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 tarball for details.
17 *----------------------------------------------------------------------
24 static void idle_string(char *str6, time_t t)
33 if (t >= 0 && t < (24 * 60 * 60)) {
34 sprintf(str6, "%02d:%02d",
35 (int) (t / (60 * 60)),
36 (int) ((t % (60 * 60)) / 60));
42 int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
43 int who_main(int argc, char **argv)
51 opt_complementary = "=0";
52 opt = getopt32(argv, "a");
55 printf("USER TTY IDLE TIME HOST\n");
56 while ((ut = getutent()) != NULL) {
57 if (ut->ut_user[0] && (opt || ut->ut_type == USER_PROCESS)) {
58 /* ut->ut_line is device name of tty - "/dev/" */
59 name = concat_path_file("/dev", ut->ut_line);
62 if (stat(name, &st) == 0)
63 idle_string(str6, st.st_atime);
64 /* 15 chars for time: Nov 10 19:33:20 */
65 printf("%-10s %-8s %-9s %-15.15s %s\n",
66 ut->ut_user, ut->ut_line, str6,
67 ctime(&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
68 if (ENABLE_FEATURE_CLEAN_UP)
72 if (ENABLE_FEATURE_CLEAN_UP)