libdlog: treat inotify creation errors as a failure 61/194261/1
authorMichal Bloch <m.bloch@samsung.com>
Fri, 30 Nov 2018 10:36:19 +0000 (11:36 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 30 Nov 2018 10:36:19 +0000 (11:36 +0100)
Change-Id: I7abcfcf606fbd32c9b6806e6bab557ee6155a9e5
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlog/dynamic_config.c

index ce91639..03e8215 100644 (file)
@@ -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;
 }