aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-19 02:26:38 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-19 02:26:38 +0100
commit302af9e3d1ea7e83f382b9c97fa9fe4099345126 (patch)
treee41f6f62cc3e8fbd9de4ed09a255742d12b3858e /procps
parent7be97c5b6b0f186edd893ce3696047709f638cf6 (diff)
downloadbusybox-w32-302af9e3d1ea7e83f382b9c97fa9fe4099345126.tar.gz
busybox-w32-302af9e3d1ea7e83f382b9c97fa9fe4099345126.tar.bz2
busybox-w32-302af9e3d1ea7e83f382b9c97fa9fe4099345126.zip
watch: compat: use stderr to determine screen dimensions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r--procps/watch.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/procps/watch.c b/procps/watch.c
index ad44b3a3e..126945c40 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -32,13 +32,19 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
32 char *header; 32 char *header;
33 char *cmd; 33 char *cmd;
34 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
35 opt_complementary = "-1:n+"; // at least one param; -n NUM 41 opt_complementary = "-1:n+"; // at least one param; -n NUM
36 // "+": stop at first non-option (procps 3.x only) 42 // "+": stop at first non-option (procps 3.x only)
37 opt = getopt32(argv, "+dtn:", &period); 43 opt = getopt32(argv, "+dtn:", &period);
38 argv += optind; 44 argv += optind;
39 45
40 // watch from both procps 2.x and 3.x does concatenation. Example: 46 // watch from both procps 2.x and 3.x does concatenation. Example:
41 // watch ls -l "a /tmp" "2>&1" -- ls won't see "a /tmp" as one param 47 // watch ls -l "a /tmp" "2>&1" - ls won't see "a /tmp" as one param
42 cmd = *argv; 48 cmd = *argv;
43 while (*++argv) 49 while (*++argv)
44 cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd 50 cmd = xasprintf("%s %s", cmd, *argv); // leaks cmd
@@ -51,7 +57,9 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
51 const unsigned time_len = sizeof("1234-67-90 23:56:89"); 57 const unsigned time_len = sizeof("1234-67-90 23:56:89");
52 time_t t; 58 time_t t;
53 59
54 get_terminal_width_height(STDIN_FILENO, &new_width, NULL); 60 // 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);
55 if (new_width != width) { 63 if (new_width != width) {
56 width = new_width; 64 width = new_width;
57 free(header); 65 free(header);
@@ -62,7 +70,8 @@ int watch_main(int argc UNUSED_PARAM, char **argv)
62 strftime(header + width - time_len, time_len, 70 strftime(header + width - time_len, time_len,
63 "%Y-%m-%d %H:%M:%S", localtime(&t)); 71 "%Y-%m-%d %H:%M:%S", localtime(&t));
64 72
65 printf("%s\n\n", header); /* compat: empty line */ 73 // compat: empty line between header and cmd output
74 printf("%s\n\n", header);
66 } 75 }
67 fflush_all(); 76 fflush_all();
68 // TODO: 'real' watch pipes cmd's output to itself 77 // TODO: 'real' watch pipes cmd's output to itself