summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-11-01 13:32:44 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-11-01 13:32:44 +0100
commite47e5c8339c3496015f667b7f71a6d673807141d (patch)
tree6a96dfe52bbd5e43924f35ddc884c7efa1899d2b
parente4469a55553423344e8b6fe5251eeb58e7c3e9bd (diff)
verbose: Ensure mutual exclusion when logging
Change-Id: I3ccc2ba35ee8db3d62eb229c736e65b2305184e3 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/verbose.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/verbose.c b/src/verbose.c
index f330c6f5..e96627ed 100644
--- a/src/verbose.c
+++ b/src/verbose.c
@@ -85,6 +85,7 @@ void verbose_set_name(const char *name, int authority)
#include <errno.h>
#include <string.h>
#include <sys/uio.h>
+#include <pthread.h>
static const char *appname;
@@ -105,6 +106,8 @@ static int tty;
static const char chars[] = { '\n', '?', ':', ' ', '[', ',', ']' };
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
static void _vverbose_(int loglevel, const char *file, int line, const char *function, const char *fmt, va_list args)
{
char buffer[4000];
@@ -169,7 +172,9 @@ static void _vverbose_(int loglevel, const char *file, int line, const char *fun
iov[n].iov_base = (void*)&chars[0];
iov[n++].iov_len = 1;
+ pthread_mutex_lock(&mutex);
writev(STDERR_FILENO, iov, n);
+ pthread_mutex_unlock(&mutex);
errno = saverr;
}