Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/who.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/who.c
r821 r1770 12 12 * 13 13 * Copyright (c) 2002 AYR Networks, Inc. 14 * 15 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 16 * 14 17 *---------------------------------------------------------------------- 15 18 */ 16 19 17 #include " busybox.h"20 #include "libbb.h" 18 21 #include <utmp.h> 19 22 #include <time.h> 20 23 21 static const char * idle_string (time_t t)24 static void idle_string(char *str6, time_t t) 22 25 { 23 static char str[6]; 24 25 time_t s = time(NULL) - t; 26 t = time(NULL) - t; 26 27 27 if (s < 60) 28 return "."; 29 if (s < (24 * 60 * 60)) { 30 sprintf (str, "%02d:%02d", 31 (int) (s / (60 * 60)), 32 (int) ((s % (60 * 60)) / 60)); 33 return str; 28 /*if (t < 60) { 29 str6[0] = '.'; 30 str6[1] = '\0'; 31 return; 32 }*/ 33 if (t >= 0 && t < (24 * 60 * 60)) { 34 sprintf(str6, "%02d:%02d", 35 (int) (t / (60 * 60)), 36 (int) ((t % (60 * 60)) / 60)); 37 return; 34 38 } 35 return "old";39 strcpy(str6, "old"); 36 40 } 37 41 42 int who_main(int argc, char **argv); 38 43 int who_main(int argc, char **argv) 39 44 { 45 char str6[6]; 40 46 struct utmp *ut; 41 47 struct stat st; 42 48 char *name; 43 49 44 50 if (argc > 1) { 45 51 bb_show_usage(); 46 52 } 47 53 48 54 setutent(); 49 55 printf("USER TTY IDLE TIME HOST\n"); … … 54 60 /* ut->ut_line is device name of tty - "/dev/" */ 55 61 name = concat_path_file("/dev", ut->ut_line); 56 printf("%-10s %-8s %-8s %-12.12s %s\n", ut->ut_user, ut->ut_line, 57 (stat(name, &st)) ? "?" : idle_string(st.st_atime), 58 ctime(&thyme) + 4, ut->ut_host); 59 if (ENABLE_FEATURE_CLEAN_UP) free(name); 62 str6[0] = '?'; 63 str6[1] = '\0'; 64 if (stat(name, &st) == 0) 65 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); 60 71 } 61 72 } 62 if (ENABLE_FEATURE_CLEAN_UP) endutent(); 73 if (ENABLE_FEATURE_CLEAN_UP) 74 endutent(); 63 75 return 0; 64 76 }
Note:
See TracChangeset
for help on using the changeset viewer.