]> git.ipfire.org Git - thirdparty/dracut.git/blame - logtee.c
modules.d: Add a module for handling additional depmod kernel module directories
[thirdparty/dracut.git] / logtee.c
CommitLineData
51d0a545
HH
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <errno.h>
7#include <limits.h>
8
f59664a0
HH
9#define BUFLEN 4096
10
51d0a545
HH
11int
12main(int argc, char *argv[])
13{
14 int fd;
15 int len, slen;
16
17 if (argc != 2) {
18 fprintf(stderr, "Usage: %s <file>\n", argv[0]);
19 exit(EXIT_FAILURE);
20 }
21
22 fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
23 if (fd == -1) {
24 perror("open");
25 exit(EXIT_FAILURE);
26 }
27
28 fprintf(stderr, "Logging to %s: ", argv[1]);
29
f59664a0
HH
30 slen = 0;
31
51d0a545
HH
32 do {
33 len = splice(STDIN_FILENO, NULL, fd, NULL,
f59664a0 34 BUFLEN, SPLICE_F_MOVE);
51d0a545
HH
35
36 if (len < 0) {
37 if (errno == EAGAIN)
38 continue;
39 perror("tee");
40 exit(EXIT_FAILURE);
41 } else
42 if (len == 0)
43 break;
f59664a0
HH
44 slen += len;
45 if ((slen/BUFLEN) > 0) {
46 fprintf(stderr, ".");
47 }
48 slen = slen % BUFLEN;
49
51d0a545
HH
50 } while (1);
51 close(fd);
52 fprintf(stderr, "\n");
53 exit(EXIT_SUCCESS);
f59664a0 54}