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.
14 *----------------------------------------------------------------------
24 static const char * idle_string (time_t t)
28 time_t s = time(NULL) - t;
32 if (s < (24 * 60 * 60)) {
33 sprintf (str, "%02d:%02d",
34 (int) (s / (60 * 60)),
35 (int) ((s % (60 * 60)) / 60));
36 return (const char *) str;
41 int who_main(int argc, char **argv)
52 printf("USER TTY IDLE TIME HOST\n");
53 while ((ut = getutent()) != NULL) {
54 if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
55 /* ut->ut_line is device name of tty - "/dev/" */
56 name = concat_path_file("/dev", ut->ut_line);
57 printf("%-10s %-8s %-8s %-12.12s %s\n", ut->ut_user, ut->ut_line,
58 (stat(name, &st)) ? "?" : idle_string(st.st_atime),
59 ctime((time_t*)&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);