#ifndef UNIT_TEST
static
#endif
-void __configure(void)
+bool __configure(void)
{
- struct log_config config;
+ __attribute__((cleanup(log_config_free))) struct log_config config;
if (log_config_read(&config) < 0)
- goto out;
+ return false;
dynamic_config = __dynamic_config_create(&config);
__configure_parameters(&config);
- if (!__configure_backend(&config))
- goto out;
+ if (!__configure_backend(&config)) {
+ __dynamic_config_destroy();
+ dynamic_config = false;
+ return false;
+ }
__configure_limiter(&config);
-
-out:
- log_config_free(&config);
- return;
+ return true;
}
static bool first = true;
-static void initialize()
+static bool initialize()
{
if (is_initialized)
- return;
+ return true;
/* The mutex acts as a barrier, but otherwise the C language's
* machine abstraction is single-threaded. This means that the
* and the simplest way to achieve that is to just wait until
* the second entry into the mutex. */
+ bool ret;
pthread_mutex_lock(&log_construction_lock);
- if (first) {
- __configure();
- first = false; // pop this cherry
- } else {
+ if (first)
+ first = !__configure();
+ else
is_initialized = true;
- }
+ ret = !first;
pthread_mutex_unlock(&log_construction_lock);
+ return ret;
}
/**
* but giving this guarantee makes everything a lot simpler as it removes
* the risk of something suddenly becoming NULL during processing. */
pthread_rwlock_rdlock(&log_destruction_lock);
- initialize();
- ret = write_to_log ? __write_to_log_critical_section(log_id, prio, tag, fmt, ap, check_should_log) : DLOG_ERROR_NOT_PERMITTED;
+ ret = !initialize() || !write_to_log
+ ? DLOG_ERROR_NOT_PERMITTED
+ : __write_to_log_critical_section(log_id, prio, tag, fmt, ap, check_should_log)
+ ;
pthread_rwlock_unlock(&log_destruction_lock);
return ret;
assert(write_to_log != wtl_pipe);
conf_read_called = false;
assert(dlog_print(DLOG_ERROR, "tag", "msg") == DLOG_ERROR_NOT_PERMITTED);
- assert(!conf_read_called); // no duplicate init
+ assert(conf_read_called); // should retry reinitializing
__dlog_fini();
log_config_set(&CONFIG, "backend", "Hej, zamawiam Bentoye. Czekam do 11:15.");