From 03b90a39ed12a568c9da752466ea708d6348e110 Mon Sep 17 00:00:00 2001 From: Petri Latvala Date: Fri, 14 Sep 2018 14:21:39 +0300 Subject: runner: Increase buffer size for reading outputs The law of chosen magic numbers: The number selected is wrong. Chose another magic number for the size of the buffer used to read test outputs and kernel log records. It's now 2048, up from 256. Also added a warning print if that's still not enough for kernel logs. The lesson to learn here is that the /dev/kmsg interface does not give you a truncated log record as initially thought, but reports an undocumented EINVAL instead. Subsequent reads give the next record, so the failsafe added will make sure any future EINVALs will only drop the record that is too long instead of everything from that point onwards. Signed-off-by: Petri Latvala Reviewed-by: Arkadiusz Hiler --- runner/executor.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'runner') diff --git a/runner/executor.c b/runner/executor.c index 36117af6..701ca80d 100644 --- a/runner/executor.c +++ b/runner/executor.c @@ -242,7 +242,7 @@ static void dump_dmesg(int kmsgfd, int outfd) unsigned flags; unsigned long long seq, cmpseq, usec; char cont; - char buf[256]; + char buf[2048]; ssize_t r; if (comparefd < 0) @@ -323,7 +323,7 @@ static int monitor_output(pid_t child, struct settings *settings) { fd_set set; - char buf[256]; + char buf[2048]; char *outbuf = NULL; size_t outbufsize = 0; char current_subtest[256] = {}; @@ -539,11 +539,13 @@ static int monitor_output(pid_t child, if (kmsgfd >= 0 && FD_ISSET(kmsgfd, &set)) { s = read(kmsgfd, buf, sizeof(buf)); if (s < 0) { - if (errno != EPIPE) { + if (errno != EPIPE && errno != EINVAL) { fprintf(stderr, "Error reading from kmsg, stopping monitoring: %s\n", strerror(errno)); close(kmsgfd); kmsgfd = -1; + } else if (errno == EINVAL) { + fprintf(stderr, "Warning: Buffer too small for kernel log record, record lost.\n"); } } else { write(outputs[_F_DMESG], buf, s); -- cgit v1.2.3