logtee: reduce output

master
Harald Hoyer 2018-08-16 11:14:11 +02:00
parent 67f43d2124
commit f59664a01f
1 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,8 @@
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>


#define BUFLEN 4096

int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -25,9 +27,11 @@ main(int argc, char *argv[])


fprintf(stderr, "Logging to %s: ", argv[1]); fprintf(stderr, "Logging to %s: ", argv[1]);


slen = 0;

do { do {
len = splice(STDIN_FILENO, NULL, fd, NULL, len = splice(STDIN_FILENO, NULL, fd, NULL,
65536, SPLICE_F_MOVE); BUFLEN, SPLICE_F_MOVE);


if (len < 0) { if (len < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
@ -37,10 +41,14 @@ main(int argc, char *argv[])
} else } else
if (len == 0) if (len == 0)
break; break;
fprintf(stderr, ".", len); slen += len;
if ((slen/BUFLEN) > 0) {
fprintf(stderr, ".");
}
slen = slen % BUFLEN;

} while (1); } while (1);
close(fd); close(fd);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }