mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-11 20:58:50 +03:00
tests: avoid clobering dmesg
Restore old harness access to /dev/kmsg.
This commit is contained in:
parent
3d845e492a
commit
abcab54cca
@ -541,26 +541,22 @@ struct FileSource : Source {
|
|||||||
struct KMsg : Source {
|
struct KMsg : Source {
|
||||||
bool can_clear;
|
bool can_clear;
|
||||||
|
|
||||||
KMsg() : can_clear( true ) {}
|
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
|
||||||
|
}
|
||||||
|
|
||||||
bool dev_kmsg() {
|
bool dev_kmsg() {
|
||||||
return fd >= 0;
|
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 ) {
|
void sync( Sink *s ) {
|
||||||
#ifdef __unix
|
#ifdef __unix
|
||||||
ssize_t sz;
|
ssize_t sz;
|
||||||
@ -569,10 +565,6 @@ struct KMsg : Source {
|
|||||||
if ( dev_kmsg() ) {
|
if ( dev_kmsg() ) {
|
||||||
while ( (sz = ::read(fd, buf, sizeof(buf) - 1)) > 0 )
|
while ( (sz = ::read(fd, buf, sizeof(buf) - 1)) > 0 )
|
||||||
s->push( std::string( buf, sz ) );
|
s->push( std::string( buf, sz ) );
|
||||||
if ( sz < 0 ) {
|
|
||||||
fd = -1;
|
|
||||||
sync( s );
|
|
||||||
}
|
|
||||||
} else if ( can_clear ) {
|
} else if ( can_clear ) {
|
||||||
while ( (sz = klogctl( BRICK_SYSLOG_ACTION_READ_CLEAR, buf,
|
while ( (sz = klogctl( BRICK_SYSLOG_ACTION_READ_CLEAR, buf,
|
||||||
sizeof(buf) - 1 )) > 0 )
|
sizeof(buf) - 1 )) > 0 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user