diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-27 13:14:29 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-27 13:14:29 +0000 |
commit | 72b3442aeb948a9f27822d8888df765393b9ecd4 (patch) | |
tree | 7c3465cda1ac5edd4fb6ee563b7d065fc7430ddf | |
parent | 11b9f266104bf1c1bd21ec64cff22dbb5d0983a6 (diff) | |
download | busybox-w32-72b3442aeb948a9f27822d8888df765393b9ecd4.tar.gz busybox-w32-72b3442aeb948a9f27822d8888df765393b9ecd4.tar.bz2 busybox-w32-72b3442aeb948a9f27822d8888df765393b9ecd4.zip |
fbsplash: support this usage:
mkfifo cmd_pipe
fbsplash -f cmd_pipe .... &
...
echo 33 >cmd_pipe
...
echo 66 >cmd_pipe
Code size: fbsplash_main +116 bytes :(
-rw-r--r-- | include/usage.h | 2 | ||||
-rw-r--r-- | miscutils/Config.in | 4 | ||||
-rw-r--r-- | miscutils/fbsplash.c | 39 |
3 files changed, 32 insertions, 13 deletions
diff --git a/include/usage.h b/include/usage.h index f830fb35c..f950a0a49 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -133,8 +133,6 @@ | |||
133 | "\n -f Control pipe (else exit after drawing image)" \ | 133 | "\n -f Control pipe (else exit after drawing image)" \ |
134 | "\n commands: 'NN' (% for progress bar) or 'exit'" \ | 134 | "\n commands: 'NN' (% for progress bar) or 'exit'" \ |
135 | 135 | ||
136 | |||
137 | |||
138 | #define brctl_trivial_usage \ | 136 | #define brctl_trivial_usage \ |
139 | "COMMAND [BRIDGE [INTERFACE]]" | 137 | "COMMAND [BRIDGE [INTERFACE]]" |
140 | #define brctl_full_usage \ | 138 | #define brctl_full_usage \ |
diff --git a/miscutils/Config.in b/miscutils/Config.in index e740a4451..c6c1490df 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -214,13 +214,13 @@ config FBSPLASH | |||
214 | -c: hide cursor | 214 | -c: hide cursor |
215 | -d /dev/fbN: framebuffer device (if not /dev/fb0) | 215 | -d /dev/fbN: framebuffer device (if not /dev/fb0) |
216 | -s path_to_image_file (can be "-" for stdin) | 216 | -s path_to_image_file (can be "-" for stdin) |
217 | -i path_to_cfg_file | 217 | -i path_to_cfg_file (can be "-" for stdin) |
218 | -f path_to_fifo (can be "-" for stdin) | 218 | -f path_to_fifo (can be "-" for stdin) |
219 | - if you want to run it only in presence of kernel parameter: | 219 | - if you want to run it only in presence of kernel parameter: |
220 | grep -q "fbsplash=on" </proc/cmdline && setsid fbsplash [params] & | 220 | grep -q "fbsplash=on" </proc/cmdline && setsid fbsplash [params] & |
221 | - commands for fifo: | 221 | - commands for fifo: |
222 | "NN" (ASCII decimal number) - percentage to show on progress bar | 222 | "NN" (ASCII decimal number) - percentage to show on progress bar |
223 | "exit" (or just close fifo) - well you guessed it | 223 | "exit" - well you guessed it |
224 | 224 | ||
225 | config LAST | 225 | config LAST |
226 | bool "last" | 226 | bool "last" |
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 2fc3fae13..f254f5630 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c | |||
@@ -394,7 +394,8 @@ int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
394 | 394 | ||
395 | fb_drawimage(); | 395 | fb_drawimage(); |
396 | 396 | ||
397 | if (fifo_filename) { | 397 | if (fifo_filename) while (1) { |
398 | struct stat statbuf; | ||
398 | unsigned num; | 399 | unsigned num; |
399 | char *num_buf; | 400 | char *num_buf; |
400 | 401 | ||
@@ -402,11 +403,16 @@ int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
402 | // Block on read, waiting for some input. | 403 | // Block on read, waiting for some input. |
403 | // Use of <stdio.h> style I/O allows to correctly | 404 | // Use of <stdio.h> style I/O allows to correctly |
404 | // handle a case when we have many buffered lines | 405 | // handle a case when we have many buffered lines |
405 | // already in the pipe. | 406 | // already in the pipe |
406 | while ((num_buf = xmalloc_fgetline(fp)) != NULL) { | 407 | while ((num_buf = xmalloc_fgetline(fp)) != NULL) { |
407 | if (strncmp(num_buf, "exit", 4) == 0) { | 408 | if (strncmp(num_buf, "exit", 4) == 0) { |
408 | DEBUG_MESSAGE("exit"); | 409 | DEBUG_MESSAGE("exit"); |
409 | break; | 410 | exit_cmd: |
411 | if (bCursorOff) { | ||
412 | // restore cursor | ||
413 | full_write(STDOUT_FILENO, "\x1b" "[?25h", 6); | ||
414 | } | ||
415 | return EXIT_SUCCESS; | ||
410 | } | 416 | } |
411 | num = atoi(num_buf); | 417 | num = atoi(num_buf); |
412 | if (isdigit(num_buf[0]) && (num <= 100)) { | 418 | if (isdigit(num_buf[0]) && (num <= 100)) { |
@@ -419,13 +425,28 @@ int fbsplash_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
419 | } | 425 | } |
420 | free(num_buf); | 426 | free(num_buf); |
421 | } | 427 | } |
422 | if (bCursorOff) { | 428 | // We got EOF/error on fp |
423 | // restore cursor | 429 | if (ferror(fp)) |
424 | full_write(STDOUT_FILENO, "\x1b" "[?25h", 6); | 430 | goto exit_cmd; |
431 | fclose(fp); | ||
432 | if (LONE_DASH(fifo_filename) | ||
433 | || stat(fifo_filename, &statbuf) != 0 | ||
434 | || !S_ISFIFO(statbuf.st_mode) | ||
435 | ) { | ||
436 | goto exit_cmd; | ||
425 | } | 437 | } |
426 | if (ENABLE_FEATURE_CLEAN_UP) | 438 | // It's really a named pipe! |
427 | fclose(fp); | 439 | // For named pipes, we want to support this: |
428 | } | 440 | // mkfifo cmd_pipe |
441 | // fbsplash -f cmd_pipe .... & | ||
442 | // ... | ||
443 | // echo 33 >cmd_pipe | ||
444 | // ... | ||
445 | // echo 66 >cmd_pipe | ||
446 | // This means that on EOF, we need to close/open cmd_pipe | ||
447 | // (just reading again works too, but it hogs CPU) | ||
448 | fp = xfopen_stdin(fifo_filename); // blocks on open | ||
449 | } // end of while (1) | ||
429 | 450 | ||
430 | return EXIT_SUCCESS; | 451 | return EXIT_SUCCESS; |
431 | } | 452 | } |