Handle deleting dynamic configuration file 81/191781/2
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Tue, 23 Oct 2018 14:33:55 +0000 (16:33 +0200)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Thu, 25 Oct 2018 15:00:19 +0000 (17:00 +0200)
It's no longer an error when a dynamic configuration
file is deleted - restore default values both for plog and
filters in that case.

Change-Id: I3ec06aeba50f2e74bfee90736beeb5634d79e06d
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
src/libdlog/dynamic_config.c
src/libdlog/log.c

index a552966..a89439c 100644 (file)
@@ -62,7 +62,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) {
+       if (r && r != -ENOENT) {
                syslog_critical_failure("DLog: keeping current runtime filters, can't read from \"%s\" (%d)", inotify_path, -r);// LCOV_EXCL_LINE
                return;
        }
index 3139308..c441287 100644 (file)
@@ -53,6 +53,7 @@ extern void __dlog_init_android(const struct log_config *conf);
 bool limiter;
 bool dynamic_config;
 bool plog[LOG_ID_MAX];
+bool plog_default_values[LOG_ID_MAX];
 
 void __update_plog(const struct log_config *conf);
 
@@ -102,7 +103,13 @@ static int __configure_backend(struct log_config *config)
        return 1;
 }
 
-static void __configure_parameters(struct log_config *config)
+static void __set_plog_default_values()
+{
+       for (int i = 0; i < NELEMS(plog); ++i)
+               plog_default_values[i] = plog[i];
+}
+
+static void __initialize_plog(const struct log_config *config)
 {
        assert(config);
 
@@ -110,7 +117,16 @@ static void __configure_parameters(struct log_config *config)
        for (int i = 0; i < NELEMS(plog); ++i)
                plog[i] = plog_default;
        plog[LOG_ID_APPS] = true; // the default does not apply here for backward compatibility reasons.
+       __set_plog_default_values();
+}
+
+static void __configure_parameters(struct log_config *config)
+{
+       assert(config);
+
+       __initialize_plog(config);
        __update_plog(config);
+       __set_plog_default_values();
 
        debugmode = log_config_get_int(config, "debugmode", DEFAULT_CONFIG_DEBUGMODE);
        fatal_assert = access(DEBUGMODE_FILE, F_OK) != -1;
@@ -129,7 +145,7 @@ void __update_plog(const struct log_config *conf)
                const int r = snprintf(key, sizeof key, "enable_%s", log_name_by_id((log_id_t)i));
                if (r < 0)
                        continue;
-               plog[i] = log_config_get_boolean(conf, key, plog[i]);
+               plog[i] = log_config_get_boolean(conf, key, plog_default_values[i]);
        }
 }