]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
logtee: time out after a period of no output
authorLubomir Rintel <lkundrak@v3.sk>
Mon, 11 Nov 2019 16:12:34 +0000 (17:12 +0100)
committerDaniel Molkentin <daniel@molkentin.de>
Mon, 11 Nov 2019 19:30:45 +0000 (20:30 +0100)
Travis cuts us short after 10 minutes of slience, giving us no chance to puke
out the output. Be faster.

fedora-test.sh
logtee.c

index e897c325cab46f073afd6883329d65aa7bcd7f6f..62725a32559f768264d7985eeadc7fc8e9d1087d 100755 (executable)
@@ -53,7 +53,7 @@ else
 
     cd test
 
-    time sudo make \
+    time sudo LOGTEE_TIMEOUT_MS=590000 make \
          KVERSION=$(rpm -qa kernel --qf '%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -rn | head -1) \
          TEST_RUN_ID=$RUN_ID \
          ${TESTS:+TESTS="$TESTS"} \
index 2690e72d1fe31fd083cd545e7aea5639e0170fe3..d32fa03724b645c09d3c555a745c96e05879a6c1 100644 (file)
--- a/logtee.c
+++ b/logtee.c
@@ -1,5 +1,6 @@
 #define _GNU_SOURCE
 #include <fcntl.h>
+#include <poll.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -13,13 +14,26 @@ main(int argc, char *argv[])
 {
        int fd;
        int len, slen;
+       int ret;
+       int timeout;
+       char *timeout_env;
+       struct pollfd fds[] = {{
+               .fd = STDIN_FILENO,
+               .events = POLLIN | POLLERR,
+       }};
+
+       timeout_env = getenv("LOGTEE_TIMEOUT_MS");
+       if (timeout_env)
+               timeout = atoi(timeout_env);
+       else
+               timeout = -1;
 
        if (argc != 2) {
                fprintf(stderr, "Usage: %s <file>\n", argv[0]);
                exit(EXIT_FAILURE);
        }
 
-       fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
+       fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, 0644);
        if (fd == -1) {
                perror("open");
                exit(EXIT_FAILURE);
@@ -30,8 +44,13 @@ main(int argc, char *argv[])
        slen = 0;
 
        do {
+               ret = poll (fds, sizeof(fds) / sizeof(fds[0]), timeout);
+               if (ret == 0) {
+                       fprintf (stderr, "Timed out after %d milliseconds of no output.\n", timeout);
+                       exit(EXIT_FAILURE);
+               }
                len = splice(STDIN_FILENO, NULL, fd, NULL,
-                            BUFLEN, SPLICE_F_MOVE);
+                            BUFLEN, SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
 
                if (len < 0) {
                        if (errno == EAGAIN)
@@ -51,4 +70,4 @@ main(int argc, char *argv[])
        close(fd);
        fprintf(stderr, "\n");
        exit(EXIT_SUCCESS);
-}
\ No newline at end of file
+}