]>
git.ipfire.org Git - thirdparty/dracut.git/blob - logtee.c
13 main(int argc
, char *argv
[])
20 struct pollfd fds
[] = {{
22 .events
= POLLIN
| POLLERR
,
25 timeout_env
= getenv("LOGTEE_TIMEOUT_MS");
27 timeout
= atoi(timeout_env
);
32 fprintf(stderr
, "Usage: %s <file>\n", argv
[0]);
36 fd
= open(argv
[1], O_WRONLY
| O_CREAT
| O_TRUNC
| O_NONBLOCK
, 0644);
42 fprintf(stderr
, "Logging to %s: ", argv
[1]);
47 ret
= poll (fds
, sizeof(fds
) / sizeof(fds
[0]), timeout
);
49 fprintf (stderr
, "Timed out after %d milliseconds of no output.\n", timeout
);
52 len
= splice(STDIN_FILENO
, NULL
, fd
, NULL
,
53 BUFLEN
, SPLICE_F_MOVE
| SPLICE_F_NONBLOCK
);
64 if ((slen
/BUFLEN
) > 0) {
71 fprintf(stderr
, "\n");