2006-06-03 02:26:16 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-14 15:34:33 +05:30
|
|
|
/*
|
|
|
|
* Monitor a pipe with a simple progress display.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2003-11-14 15:34:33 +05:30
|
|
|
*/
|
2015-10-19 04:22:26 +05:30
|
|
|
//config:config PIPE_PROGRESS
|
|
|
|
//config: bool "pipe_progress"
|
|
|
|
//config: default y
|
|
|
|
//config: help
|
|
|
|
//config: Display a dot to indicate pipe activity.
|
|
|
|
|
|
|
|
//applet:IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o
|
2011-04-02 02:26:30 +05:30
|
|
|
|
|
|
|
//usage:#define pipe_progress_trivial_usage NOUSAGE_STR
|
|
|
|
//usage:#define pipe_progress_full_usage ""
|
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2003-11-14 15:34:33 +05:30
|
|
|
|
|
|
|
#define PIPE_PROGRESS_SIZE 4096
|
|
|
|
|
2006-06-03 02:26:16 +05:30
|
|
|
/* Read a block of data from stdin, write it to stdout.
|
|
|
|
* Activity is indicated by a '.' to stderr
|
2003-11-14 15:34:33 +05:30
|
|
|
*/
|
2007-10-11 15:35:36 +05:30
|
|
|
int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
2003-11-14 15:34:33 +05:30
|
|
|
{
|
2010-06-06 21:49:25 +05:30
|
|
|
char buf[PIPE_PROGRESS_SIZE];
|
2003-11-14 15:34:33 +05:30
|
|
|
time_t t = time(NULL);
|
2010-06-06 21:49:25 +05:30
|
|
|
int len;
|
2003-11-14 15:34:33 +05:30
|
|
|
|
2010-06-06 21:49:25 +05:30
|
|
|
while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) {
|
2003-11-14 15:34:33 +05:30
|
|
|
time_t new_time = time(NULL);
|
|
|
|
if (new_time != t) {
|
|
|
|
t = new_time;
|
2010-06-07 01:23:09 +05:30
|
|
|
bb_putchar_stderr('.');
|
2003-11-14 15:34:33 +05:30
|
|
|
}
|
2010-06-06 21:49:25 +05:30
|
|
|
full_write(STDOUT_FILENO, buf, len);
|
2003-11-14 15:34:33 +05:30
|
|
|
}
|
|
|
|
|
2010-06-07 01:23:09 +05:30
|
|
|
bb_putchar_stderr('\n');
|
2003-11-14 15:34:33 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|