Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/who.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/who.c
r1765 r2725 13 13 * Copyright (c) 2002 AYR Networks, Inc. 14 14 * 15 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.15 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 16 16 * 17 17 *---------------------------------------------------------------------- 18 18 */ 19 /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */ 19 20 20 21 #include "libbb.h" 21 22 #include <utmp.h> 22 #include <time.h>23 23 24 24 static void idle_string(char *str6, time_t t) … … 40 40 } 41 41 42 int who_main(int argc, char **argv) ;43 int who_main(int argc , char **argv)42 int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 43 int who_main(int argc UNUSED_PARAM, char **argv) 44 44 { 45 char str6[6];46 45 struct utmp *ut; 47 struct stat st; 48 char *name; 46 unsigned opt; 49 47 50 if (argc > 1) { 51 bb_show_usage(); 52 } 48 opt_complementary = "=0"; 49 opt = getopt32(argv, "aH"); 50 if (opt & 2) // -H 51 printf("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST\n"); 53 52 54 53 setutent(); 55 printf("USER TTY IDLE TIME HOST\n");56 54 while ((ut = getutent()) != NULL) { 57 if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) { 58 time_t thyme = ut->ut_tv.tv_sec; 55 if (ut->ut_user[0] 56 && ((opt & 1) || ut->ut_type == USER_PROCESS) 57 ) { 58 char str6[6]; 59 char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1]; 60 struct stat st; 61 time_t seconds; 59 62 60 /* ut->ut_line is device name of tty - "/dev/" */61 name = concat_path_file("/dev", ut->ut_line);62 63 str6[0] = '?'; 63 64 str6[1] = '\0'; 65 strcpy(name, "/dev/"); 66 safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1, 67 ut->ut_line, 68 sizeof(ut->ut_line)+1 69 ); 64 70 if (stat(name, &st) == 0) 65 71 idle_string(str6, st.st_atime); 66 printf("%-10s %-8s %-9s %-14.14s %s\n", 67 ut->ut_user, ut->ut_line, str6, 68 ctime(&thyme) + 4, ut->ut_host); 69 if (ENABLE_FEATURE_CLEAN_UP) 70 free(name); 72 /* manpages say ut_tv.tv_sec *is* time_t, 73 * but some systems have it wrong */ 74 seconds = ut->ut_tv.tv_sec; 75 /* How wide time field can be? 76 * "Nov 10 19:33:20": 15 chars 77 * "2010-11-10 19:33": 16 chars 78 */ 79 printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n", 80 (int)sizeof(ut->ut_user), ut->ut_user, 81 (int)sizeof(ut->ut_line), ut->ut_line, 82 str6, 83 ctime(&seconds) + 4, 84 (int)sizeof(ut->ut_host), ut->ut_host 85 ); 71 86 } 72 87 } 73 88 if (ENABLE_FEATURE_CLEAN_UP) 74 89 endutent(); 75 return 0;90 return EXIT_SUCCESS; 76 91 }
Note:
See TracChangeset
for help on using the changeset viewer.