Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/coreutils/who.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (hide annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 2183 byte(s)
-updated to busybox-1.13.4
1 niro 532 /* vi: set sw=4 ts=4: */
2     /*----------------------------------------------------------------------
3     * Mini who is used to display user name, login time,
4     * idle time and host name.
5     *
6     * Author: Da Chen <dchen@ayrnetworks.com>
7     *
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
12     *
13     * Copyright (c) 2002 AYR Networks, Inc.
14     *
15     * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
16     *
17     *----------------------------------------------------------------------
18     */
19 niro 816 /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -H, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
20 niro 532
21 niro 816 #include "libbb.h"
22 niro 532 #include <utmp.h>
23     #include <time.h>
24    
25 niro 816 static void idle_string(char *str6, time_t t)
26 niro 532 {
27 niro 816 t = time(NULL) - t;
28 niro 532
29 niro 816 /*if (t < 60) {
30     str6[0] = '.';
31     str6[1] = '\0';
32     return;
33     }*/
34     if (t >= 0 && t < (24 * 60 * 60)) {
35     sprintf(str6, "%02d:%02d",
36     (int) (t / (60 * 60)),
37     (int) ((t % (60 * 60)) / 60));
38     return;
39 niro 532 }
40 niro 816 strcpy(str6, "old");
41 niro 532 }
42    
43 niro 816 int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44     int who_main(int argc UNUSED_PARAM, char **argv)
45 niro 532 {
46 niro 816 char str6[6];
47 niro 532 struct utmp *ut;
48     struct stat st;
49     char *name;
50 niro 816 unsigned opt;
51 niro 532
52 niro 816 opt_complementary = "=0";
53     opt = getopt32(argv, "a");
54 niro 532
55     setutent();
56 niro 816 printf("USER TTY IDLE TIME HOST\n");
57 niro 532 while ((ut = getutent()) != NULL) {
58 niro 816 if (ut->ut_user[0] && (opt || ut->ut_type == USER_PROCESS)) {
59     time_t tmp;
60 niro 532 /* ut->ut_line is device name of tty - "/dev/" */
61     name = concat_path_file("/dev", ut->ut_line);
62 niro 816 str6[0] = '?';
63     str6[1] = '\0';
64     if (stat(name, &st) == 0)
65     idle_string(str6, st.st_atime);
66     /* manpages say ut_tv.tv_sec *is* time_t,
67     * but some systems have it wrong */
68     tmp = ut->ut_tv.tv_sec;
69     /* 15 chars for time: Nov 10 19:33:20 */
70     printf("%-10s %-8s %-9s %-15.15s %s\n",
71     ut->ut_user, ut->ut_line, str6,
72     ctime(&tmp) + 4, ut->ut_host);
73     if (ENABLE_FEATURE_CLEAN_UP)
74     free(name);
75 niro 532 }
76     }
77 niro 816 if (ENABLE_FEATURE_CLEAN_UP)
78     endutent();
79     return EXIT_SUCCESS;
80 niro 532 }