From 8341af8ce4432e2382d6605ec725c68aaa39cb3c Mon Sep 17 00:00:00 2001 From: Michal Bloch Date: Fri, 30 Nov 2018 11:36:19 +0100 Subject: [PATCH] libdlog: treat inotify creation errors as a failure Change-Id: I7abcfcf606fbd32c9b6806e6bab557ee6155a9e5 Signed-off-by: Michal Bloch --- src/libdlog/dynamic_config.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libdlog/dynamic_config.c b/src/libdlog/dynamic_config.c index ce91639..03e8215 100644 --- a/src/libdlog/dynamic_config.c +++ b/src/libdlog/dynamic_config.c @@ -35,7 +35,7 @@ extern pthread_mutex_t log_init_lock; extern bool limiter; extern void __update_plog(const struct log_config *conf); -static void __setup_runtime_watch(char const *path) +static bool __setup_runtime_watch(char const *path) { assert(path); assert(inotify_fd == -1); @@ -43,17 +43,19 @@ static void __setup_runtime_watch(char const *path) inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (inotify_fd == -1) { - syslog_critical_failure("DLog: inotify_init failed (%d)", errno);// LCOV_EXCL_LINE - return;// LCOV_EXCL_LINE + syslog_critical_failure("DLog: inotify_init failed (%d)", errno); + return false; } inotify_wd = inotify_add_watch(inotify_fd, path, IN_CREATE | IN_CLOSE_WRITE | IN_MOVE | IN_DELETE); if (inotify_wd == -1) { - syslog_critical_failure("DLog: inotify_add_watch failed (%d)", errno);// LCOV_EXCL_LINE - close(inotify_fd);// LCOV_EXCL_LINE - inotify_fd = -1;// LCOV_EXCL_LINE - return;// LCOV_EXCL_LINE + syslog_critical_failure("DLog: inotify_add_watch failed (%d)", errno); + close(inotify_fd); + inotify_fd = -1; + return false; } + + return true; } static void __apply_update() @@ -63,7 +65,7 @@ static void __apply_update() __attribute__((cleanup(log_config_free))) struct log_config config = {NULL, NULL}; const int r = log_config_read_file(&config, inotify_path); if (r && r != -ENOENT) { - syslog_critical_failure("DLog: keeping current runtime filters, can't read from \"%s\" (%d)", inotify_path, -r);// LCOV_EXCL_LINE + syslog_critical_failure("DLog: keeping current runtime filters, can't read from \"%s\" (%d)", inotify_path, -r); return; } @@ -88,14 +90,18 @@ bool __dynamic_config_create(struct log_config *config) return false; // LCOV_EXCL_LINE } + if (!__setup_runtime_watch(extra_config_path)) { + free(inotify_path); + inotify_path = NULL; + return false; + } + /* missing filters config file at startup * is not an error so no need to check * return value here */ log_config_read_file(config, inotify_path); - __setup_runtime_watch(extra_config_path); - return true; } -- 2.7.4