summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuoCe <guoce@kylinos.cn>2022-09-23 14:25:31 +0800
committerRadek Podgorny <radek@podgorny.cz>2023-02-13 12:55:25 +0100
commit4587e2b2f9c610a700126010bf2e1ac92a8bc7b4 (patch)
treee48bb2d76bced0e024f7e6b7a98804ce70d48d03
parent08f58ed03ac6c459c6ac6fcfa28c2bebb484fc77 (diff)
downloadunionfs-fuse-git-4587e2b2f9c610a700126010bf2e1ac92a8bc7b4.tar.gz
Use locks to protect condition variables from errors
-rw-r--r--src/usyslog.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/usyslog.c b/src/usyslog.c
index 67d6f49..edf701f 100644
--- a/src/usyslog.c
+++ b/src/usyslog.c
@@ -37,6 +37,7 @@ static ulogs_t *free_head, *free_bottom; // free chained list log entries
static ulogs_t *used_head = NULL, *used_bottom = NULL; //used chained list pointers
static pthread_mutex_t list_lock; // locks the entire chained list
+static pthread_mutex_t sleep_mutex; // locks cond_message
static pthread_cond_t cond_message; // used to wake up the syslog thread
// Only used for debugging, protected by list_lock
@@ -160,9 +161,7 @@ static void * syslog_thread(void *arg)
if (tinfo == 0 && tinfo == 1)
printf("Starting thread %d", tinfo);
- pthread_mutex_t sleep_mutex;
- pthread_mutex_init(&sleep_mutex, NULL);
pthread_mutex_lock(&sleep_mutex);
while (1) {
pthread_cond_wait(&cond_message, &sleep_mutex);
@@ -247,7 +246,12 @@ void usyslog(int priority, const char *format, ...)
pthread_mutex_unlock(&log->lock);
+
+ pthread_mutex_lock(&sleep_mutex);
+
pthread_cond_signal(&cond_message); // wake up the syslog thread
+
+ pthread_mutex_unlock(&sleep_mutex);
}
/**
@@ -258,6 +262,7 @@ void init_syslog(void)
openlog("unionfs-fuse: ", LOG_CONS | LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_DAEMON);
pthread_mutex_init(&list_lock, NULL);
+ pthread_mutex_init(&sleep_mutex, NULL);
pthread_cond_init(&cond_message, NULL);
pthread_t thread;
pthread_attr_t attr;