From 1c8a11858806ede33cd332d39606217edbefd346 Mon Sep 17 00:00:00 2001 From: Marian Csontos Date: Mon, 22 Jun 2015 16:43:17 +0200 Subject: [PATCH] Revert "tests: avoid clobering dmesg" This reverts commit abcab54cca4b4f9ff157a5f51718c69ffdf34c7a. Dmesg is not uploaded on machines except on F19. --- test/lib/brick-shelltest.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h index e64a166e1..af8051efc 100644 --- a/test/lib/brick-shelltest.h +++ b/test/lib/brick-shelltest.h @@ -541,22 +541,26 @@ struct FileSource : Source { struct KMsg : Source { bool can_clear; - KMsg() : can_clear( strcmp(getenv("LVM_TEST_CAN_CLOBBER_DMESG") ? : "0", "0") ) { -#ifdef __unix - if ( (fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK)) < 0 ) { - if (errno != ENOENT) /* Older kernels (<3.5) do not support /dev/kmsg */ - perror("opening /dev/kmsg"); - if ( klogctl( BRICK_SYSLOG_ACTION_CLEAR, 0, 0 ) < 0 ) - can_clear = false; - } else if (lseek(fd, 0L, SEEK_END) == (off_t) -1) - perror("lseek /dev/kmsg"); -#endif - } + KMsg() : can_clear( true ) {} bool dev_kmsg() { return fd >= 0; } + void reset() { +#ifdef __unix + if ( dev_kmsg() ) { + if ( (fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK)) < 0 ) { + if (errno != ENOENT) /* Older kernels (<3.5) do not support /dev/kmsg */ + perror("opening /dev/kmsg"); + } else if (lseek(fd, 0L, SEEK_END) == (off_t) -1) + perror("lseek /dev/kmsg"); + } else + if ( klogctl( BRICK_SYSLOG_ACTION_CLEAR, 0, 0 ) < 0 ) + can_clear = false; +#endif + } + void sync( Sink *s ) { #ifdef __unix ssize_t sz; @@ -565,6 +569,10 @@ struct KMsg : Source { if ( dev_kmsg() ) { while ( (sz = ::read(fd, buf, sizeof(buf) - 1)) > 0 ) s->push( std::string( buf, sz ) ); + if ( sz < 0 ) { + fd = -1; + sync( s ); + } } else if ( can_clear ) { while ( (sz = klogctl( BRICK_SYSLOG_ACTION_READ_CLEAR, buf, sizeof(buf) - 1 )) > 0 )