blob: 21d330b59453f1fef9c78fa1601b07cc7a839f45 [file] [log] [blame]
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrathe9080c92003-11-14 10:04:33 +00002/*
3 * Monitor a pipe with a simple progress display.
4 *
5 * Copyright (C) 2003 by Rob Landley <rob@landley.net>, Joey Hess
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrathe9080c92003-11-14 10:04:33 +00008 */
Denys Vlasenko28826ac2015-10-19 00:52:26 +02009//config:config PIPE_PROGRESS
10//config: bool "pipe_progress"
11//config: default y
12//config: help
13//config: Display a dot to indicate pipe activity.
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 Orga6a3e01d2011-04-01 22:56:30 +020018
19//usage:#define pipe_progress_trivial_usage NOUSAGE_STR
20//usage:#define pipe_progress_full_usage ""
21
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000022#include "libbb.h"
Glenn L McGrathe9080c92003-11-14 10:04:33 +000023
Glenn L McGrathe9080c92003-11-14 10:04:33 +000024#define PIPE_PROGRESS_SIZE 4096
25
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000026/* Read a block of data from stdin, write it to stdout.
27 * Activity is indicated by a '.' to stderr
Glenn L McGrathe9080c92003-11-14 10:04:33 +000028 */
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000029int pipe_progress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000030int pipe_progress_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
Glenn L McGrathe9080c92003-11-14 10:04:33 +000031{
Denys Vlasenko5f330372010-06-06 18:19:25 +020032 char buf[PIPE_PROGRESS_SIZE];
Glenn L McGrathe9080c92003-11-14 10:04:33 +000033 time_t t = time(NULL);
Denys Vlasenko5f330372010-06-06 18:19:25 +020034 int len;
Glenn L McGrathe9080c92003-11-14 10:04:33 +000035
Denys Vlasenko5f330372010-06-06 18:19:25 +020036 while ((len = safe_read(STDIN_FILENO, buf, PIPE_PROGRESS_SIZE)) > 0) {
Glenn L McGrathe9080c92003-11-14 10:04:33 +000037 time_t new_time = time(NULL);
38 if (new_time != t) {
39 t = new_time;
Denys Vlasenko19ced5c2010-06-06 21:53:09 +020040 bb_putchar_stderr('.');
Glenn L McGrathe9080c92003-11-14 10:04:33 +000041 }
Denys Vlasenko5f330372010-06-06 18:19:25 +020042 full_write(STDOUT_FILENO, buf, len);
Glenn L McGrathe9080c92003-11-14 10:04:33 +000043 }
44
Denys Vlasenko19ced5c2010-06-06 21:53:09 +020045 bb_putchar_stderr('\n');
Glenn L McGrathe9080c92003-11-14 10:04:33 +000046
Glenn L McGrathe9080c92003-11-14 10:04:33 +000047 return 0;
48}