Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 16  Line 16 
16   *   *
17   *----------------------------------------------------------------------   *----------------------------------------------------------------------
18   */   */
19    /* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -H, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'.  */
20    
21  #include "busybox.h"  #include "libbb.h"
22  #include <utmp.h>  #include <utmp.h>
23  #include <time.h>  #include <time.h>
24    
25  static const char * idle_string (time_t t)  static void idle_string(char *str6, time_t t)
26  {  {
27   static char str[6];   t = time(NULL) - t;
28    
29   time_t s = time(NULL) - t;   /*if (t < 60) {
30     str6[0] = '.';
31   if (s < 60)   str6[1] = '\0';
32   return ".";   return;
33   if (s < (24 * 60 * 60)) {   }*/
34   sprintf(str, "%02d:%02d",   if (t >= 0 && t < (24 * 60 * 60)) {
35   (int) (s / (60 * 60)),   sprintf(str6, "%02d:%02d",
36   (int) ((s % (60 * 60)) / 60));   (int) (t / (60 * 60)),
37   return str;   (int) ((t % (60 * 60)) / 60));
38     return;
39   }   }
40   return "old";   strcpy(str6, "old");
41  }  }
42    
43  int who_main(int argc, char **argv)  int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44    int who_main(int argc UNUSED_PARAM, char **argv)
45  {  {
46     char str6[6];
47   struct utmp *ut;   struct utmp *ut;
48   struct stat st;   struct stat st;
49   char *name;   char *name;
50     unsigned opt;
51    
52   if (argc > 1) {   opt_complementary = "=0";
53   bb_show_usage();   opt = getopt32(argv, "a");
  }  
54    
55   setutent();   setutent();
56   printf("USER       TTY      IDLE      TIME           HOST\n");   printf("USER       TTY      IDLE      TIME            HOST\n");
57   while ((ut = getutent()) != NULL) {   while ((ut = getutent()) != NULL) {
58   if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {   if (ut->ut_user[0] && (opt || ut->ut_type == USER_PROCESS)) {
59   time_t thyme = ut->ut_tv.tv_sec;   time_t tmp;
   
60   /* ut->ut_line is device name of tty - "/dev/" */   /* ut->ut_line is device name of tty - "/dev/" */
61   name = concat_path_file("/dev", ut->ut_line);   name = concat_path_file("/dev", ut->ut_line);
62   printf("%-10s %-8s %-8s  %-12.12s   %s\n", ut->ut_user, ut->ut_line,   str6[0] = '?';
63   (stat(name, &st)) ?  "?" : idle_string(st.st_atime),   str6[1] = '\0';
64   ctime(&thyme) + 4, ut->ut_host);   if (stat(name, &st) == 0)
65   if (ENABLE_FEATURE_CLEAN_UP) free(name);   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   }   }
76   }   }
77   if (ENABLE_FEATURE_CLEAN_UP) endutent();   if (ENABLE_FEATURE_CLEAN_UP)
78   return 0;   endutent();
79     return EXIT_SUCCESS;
80  }  }

Legend:
Removed from v.532  
changed lines
  Added in v.816