static char *inotify_path;
extern pthread_mutex_t log_init_lock;
+extern bool limiter;
static void __setup_runtime_watch(char const *path)
{
}
}
-static void __update_filters()
+static void __apply_update()
{
assert(inotify_path);
- struct log_config config = {NULL, NULL};
+ __attribute__((cleanup(log_config_free))) struct log_config config = {NULL, NULL};
const int r = log_config_read_file(&config, inotify_path);
- if (!r)
- __log_limiter_update(&config);
- else
+ if (r) {
syslog_critical_failure("DLog: keeping current runtime filters, can't read from \"%s\" (%d)", inotify_path, -r);// LCOV_EXCL_LINE
+ return;
+ }
- log_config_free(&config);
+ if (limiter)
+ __log_limiter_update(&config);
}
/// caller has to guarantee exclusive access
-void __dynamic_config_create(struct log_config *config)
+bool __dynamic_config_create(struct log_config *config)
{
assert(config);
assert(!inotify_path);
const char *const extra_config_path = log_config_get(config, DYNAMIC_CONFIG_CONF_KEY);
if (!extra_config_path)
- return;
+ return false;
if (asprintf(&inotify_path, "%s/%s", extra_config_path, DYNAMIC_CONFIG_FILENAME) < 0) {
inotify_path = NULL;// LCOV_EXCL_LINE
syslog_critical_failure("DLog: out of memory");// LCOV_EXCL_LINE
- return;// LCOV_EXCL_LINE
+ return false; // LCOV_EXCL_LINE
}
/* missing filters config file at startup
log_config_read_file(config, inotify_path);
__setup_runtime_watch(extra_config_path);
+
+ return true;
}
/// caller has to guarantee exclusive access
assert(ievent.ie.wd == inotify_wd);
pthread_mutex_lock(&log_init_lock);
- __update_filters();
+ __apply_update();
pthread_mutex_unlock(&log_init_lock);
}
#include <assert.h>
#include <unistd.h>
-#define DEFAULT_CONFIG_LIMITER 0
+#define DEFAULT_CONFIG_LIMITER false
#define DEFAULT_CONFIG_PLOG 1
#define DEFAULT_CONFIG_DEBUGMODE 0
#define DEFAULT_CONFIG_LIMITER_APPLY_TO_ALL_BUFFERS 0
extern void __dlog_init_pipe();
extern void __dlog_init_android();
-static int limiter;
+bool limiter;
+bool dynamic_config;
+
static int plog;
static int debugmode;
static int fatal_assert;
if (!limiter)
return;
- __dynamic_config_create(config);
limiter = __log_limiter_create(config);
-
- if (!limiter)
- __dynamic_config_destroy(); // LCOV_EXCL_LINE
}
static int __configure_backend(struct log_config *config)
plog = log_config_get_int(config, "plog", DEFAULT_CONFIG_PLOG);
debugmode = log_config_get_int(config, "debugmode", DEFAULT_CONFIG_DEBUGMODE);
fatal_assert = access(DEBUGMODE_FILE, F_OK) != -1;
- limiter = log_config_get_int(config, "limiter", DEFAULT_CONFIG_LIMITER);
+ limiter = log_config_get_boolean(config, "limiter", DEFAULT_CONFIG_LIMITER);
limiter_apply_to_all_buffers = log_config_get_int(config,
"limiter_apply_to_all_buffers",
DEFAULT_CONFIG_LIMITER_APPLY_TO_ALL_BUFFERS);
if (log_config_read(&config) < 0)
goto failure;
+ dynamic_config = __dynamic_config_create(&config);
+
__configure_parameters(&config);
if (!__configure_backend(&config))
if (log_id != LOG_ID_APPS && !plog)
return DLOG_ERROR_NOT_PERMITTED;
- if (limiter) {
+ if (dynamic_config) {
__dynamic_config_update();
// LCOV_EXCL_START : disabled feature (limiter)
- pthread_mutex_lock(&log_init_lock);
- int should_log = __log_limiter_pass_log(tag, prio);
- pthread_mutex_unlock(&log_init_lock);
-
- if (!should_log) {
- return DLOG_ERROR_NOT_PERMITTED;
- } else if (should_log < 0) {
- write_to_log(log_id, prio, tag,
- "Your log has been blocked due to limit of log lines per minute.");
- return DLOG_ERROR_NOT_PERMITTED;
+ if (limiter) {
+ pthread_mutex_lock(&log_init_lock);
+ int should_log = __log_limiter_pass_log(tag, prio);
+ pthread_mutex_unlock(&log_init_lock);
+
+ if (!should_log) {
+ return DLOG_ERROR_NOT_PERMITTED;
+ } else if (should_log < 0) {
+ write_to_log(log_id, prio, tag,
+ "Your log has been blocked due to limit of log lines per minute.");
+ return DLOG_ERROR_NOT_PERMITTED;
+ }
}
// LCOV_EXCL_STOP
}