Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Monitor a pipe with a simple progress display. |
| 4 | * |
| 5 | * Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess |
| 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | 28826ac | 2015-10-19 00:52:26 +0200 | [diff] [blame] | 9 | //config:config PIPE_PROGRESS |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 10 | //config: bool "pipe_progress (225 bytes)" |
Denys Vlasenko | 28826ac | 2015-10-19 00:52:26 +0200 | [diff] [blame] | 11 | //config: default y |
| 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: Display a dot to indicate pipe activity. |
Denys Vlasenko | 28826ac | 2015-10-19 00:52:26 +0200 | [diff] [blame] | 14 | |
| 15 | //applet:IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP)) |
| 16 | |
| 17 | //kbuild:lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o |
Pere Orga | 6a3e01d | 2011-04-01 22:56:30 +0200 | [diff] [blame] | 18 | |
| 19 | //usage:#define pipe_progress_trivial_usage NOUSAGE_STR |
| 20 | //usage:#define pipe_progress_full_usage "" |
| 21 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 22 | #include "libbb.h" |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 23 | |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 24 | #define PIPE_PROGRESS_SIZE 4096 |
| 25 | |
Bernhard Reutner-Fischer | e15d757 | 2006-06-02 20:56:16 +0000 | [diff] [blame] | 26 | /* Read a block of data from stdin, write it to stdout. |
| 27 | * Activity is indicated by a '.' to stderr |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 28 | */ |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 29 | int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 30 | int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 31 | { |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 32 | char buf[PIPE_PROGRESS_SIZE]; |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 33 | time_t t = time(NULL); |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 34 | int len; |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 35 | |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 36 | while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) { |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 37 | time_t new_time = time(NULL); |
| 38 | if (new_time != t) { |
| 39 | t = new_time; |
Denys Vlasenko | 19ced5c | 2010-06-06 21:53:09 +0200 | [diff] [blame] | 40 | bb_putchar_stderr('.'); |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 41 | } |
Denys Vlasenko | 5f33037 | 2010-06-06 18:19:25 +0200 | [diff] [blame] | 42 | full_write(STDOUT_FILENO, buf, len); |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Denys Vlasenko | 19ced5c | 2010-06-06 21:53:09 +0200 | [diff] [blame] | 45 | bb_putchar_stderr('\n'); |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 46 | |
Glenn L McGrath | e9080c9 | 2003-11-14 10:04:33 +0000 | [diff] [blame] | 47 | return 0; |
| 48 | } |