1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

tests: avoid clobering dmesg

Restore old harness access to /dev/kmsg.
This commit is contained in:
Zdenek Kabelac 2015-05-08 22:43:06 +02:00
parent 3d845e492a
commit abcab54cca

View File

@ -541,26 +541,22 @@ struct FileSource : Source {
struct KMsg : Source {
bool can_clear;
KMsg() : can_clear( true ) {}
bool dev_kmsg() {
return fd >= 0;
}
void reset() {
KMsg() : can_clear( strcmp(getenv("LVM_TEST_CAN_CLOBBER_DMESG") ? : "0", "0") ) {
#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;
} else if (lseek(fd, 0L, SEEK_END) == (off_t) -1)
perror("lseek /dev/kmsg");
#endif
}
bool dev_kmsg() {
return fd >= 0;
}
void sync( Sink *s ) {
#ifdef __unix
ssize_t sz;
@ -569,10 +565,6 @@ 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 )