1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

clvmd: add debuglog mutex

Log messages issued by different threads occasionally got intertwined.
This commit is contained in:
Alasdair G Kergon 2017-07-01 00:58:39 +01:00
parent 006a9eaada
commit 17ed254091
2 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.173 -
=================================
Protect clvmd debug log messages with mutex.
Fix shellcheck reported issues for script files.
Version 2.02.172 - 28th June 2017

View File

@ -92,6 +92,7 @@ static const size_t STACK_SIZE = 128 * 1024;
static pthread_attr_t stack_attr;
static int lvm_thread_exit = 0;
static pthread_mutex_t lvm_thread_mutex;
static pthread_mutex_t _debuglog_mutex;
static pthread_cond_t lvm_thread_cond;
static pthread_barrier_t lvm_start_barrier;
static struct dm_list lvm_cmd_head;
@ -218,14 +219,17 @@ void debuglog(const char *fmt, ...)
switch (clvmd_get_debug()) {
case DEBUG_STDERR:
pthread_mutex_lock(&_debuglog_mutex);
va_start(ap,fmt);
time(&P);
fprintf(stderr, "CLVMD[%x]: %.15s ", (int)pthread_self(), ctime_r(&P, buf_ctime) + 4);
vfprintf(stderr, fmt, ap);
va_end(ap);
fflush(stderr);
pthread_mutex_unlock(&_debuglog_mutex);
break;
case DEBUG_SYSLOG:
pthread_mutex_lock(&_debuglog_mutex);
if (!syslog_init) {
openlog("clvmd", LOG_PID, LOG_DAEMON);
syslog_init = 1;
@ -234,6 +238,7 @@ void debuglog(const char *fmt, ...)
va_start(ap,fmt);
vsyslog(LOG_DEBUG, fmt, ap);
va_end(ap);
pthread_mutex_unlock(&_debuglog_mutex);
break;
case DEBUG_OFF:
break;
@ -522,6 +527,7 @@ int main(int argc, char *argv[])
exit(1);
}
pthread_mutex_init(&lvm_thread_mutex, NULL);
pthread_mutex_init(&_debuglog_mutex, NULL);
pthread_cond_init(&lvm_thread_cond, NULL);
pthread_barrier_init(&lvm_start_barrier, NULL, 2);
init_lvhash();