From d1eded3f9d739b4b866df90a013fea02c7e0005d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Wed, 5 Jun 2013 21:17:18 +0200 Subject: [PATCH] grap log lock when initializing a destination --- src/logging.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/logging.c b/src/logging.c index a34a8a4..057d63d 100644 --- a/src/logging.c +++ b/src/logging.c @@ -118,20 +118,26 @@ static inline int uc_ll_2_syslog(enum UC_LOG_LEVEL l) return LOG_INFO; } +//Note, this grabs the global lock static int uc_log_init_settings(struct uc_log_destination *dest) { int i; + int rc = -1; + + pthread_mutex_lock(&g_log_lock); dest->module_settings = calloc(g_modules.cnt, sizeof *dest->module_settings); - if (dest->module_settings == NULL) { - return -1; + if (dest->module_settings != NULL) { + for (i = 0; i < g_modules.cnt; i++) { + dest->module_settings[i].log_level = g_modules.mods[i].log_level; + } + + rc = 0; } - for (i = 0; i < g_modules.cnt; i++) { - dest->module_settings[i].log_level = g_modules.mods[i].log_level; - } + pthread_mutex_unlock(&g_log_lock); - return 0; + return rc; } struct uc_log_destination *uc_log_new_stderr(int log_level, int log_location)