Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/procps/watch.c

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

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 32  int watch_main(int argc UNUSED_PARAM, ch Line 32  int watch_main(int argc UNUSED_PARAM, ch
32   char *header;   char *header;
33   char *cmd;   char *cmd;
34    
35    #if 0 // maybe ENABLE_DESKTOP?
36     // procps3 compat - "echo TEST | watch cat" doesn't show TEST:
37     close(STDIN_FILENO);
38     xopen("/dev/null", O_RDONLY);
39    #endif
40    
41   opt_complementary = "-1:n+"; // at least one param; -n NUM   opt_complementary = "-1:n+"; // at least one param; -n NUM
42   // "+": stop at first non-option (procps 3.x only)   // "+": stop at first non-option (procps 3.x only)
43   opt = getopt32(argv, "+dtn:", &period);   opt = getopt32(argv, "+dtn:", &period);
44   argv += optind;   argv += optind;
45    
46   // watch from both procps 2.x and 3.x does concatenation. Example:   // watch from both procps 2.x and 3.x does concatenation. Example:
47   // watch ls -l "a /tmp" "2>&1" -- ls won't see "a /tmp" as one param   // watch ls -l "a /tmp" "2>&1" - ls won't see "a /tmp" as one param
48   cmd = *argv;   cmd = *argv;
49   while (*++argv)   while (*++argv)
50   cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd   cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd
# Line 51  int watch_main(int argc UNUSED_PARAM, ch Line 57  int watch_main(int argc UNUSED_PARAM, ch
57   const unsigned time_len = sizeof("1234-67-90 23:56:89");   const unsigned time_len = sizeof("1234-67-90 23:56:89");
58   time_t t;   time_t t;
59    
60   get_terminal_width_height(STDIN_FILENO, &new_width, NULL);   // STDERR_FILENO is procps3 compat:
61     // "watch ls 2>/dev/null" does not detect tty size
62     get_terminal_width_height(STDERR_FILENO, &new_width, NULL);
63   if (new_width != width) {   if (new_width != width) {
64   width = new_width;   width = new_width;
65   free(header);   free(header);
# Line 62  int watch_main(int argc UNUSED_PARAM, ch Line 70  int watch_main(int argc UNUSED_PARAM, ch
70   strftime(header + width - time_len, time_len,   strftime(header + width - time_len, time_len,
71   "%Y-%m-%d %H:%M:%S", localtime(&t));   "%Y-%m-%d %H:%M:%S", localtime(&t));
72    
73   puts(header);   // compat: empty line between header and cmd output
74     printf("%s\n\n", header);
75   }   }
76   fflush(stdout);   fflush_all();
77   // TODO: 'real' watch pipes cmd's output to itself   // TODO: 'real' watch pipes cmd's output to itself
78   // and does not allow it to overflow the screen   // and does not allow it to overflow the screen
79   // (taking into account linewrap!)   // (taking into account linewrap!)

Legend:
Removed from v.983  
changed lines
  Added in v.984