Rename dynamic filters to dynamic config 31/190031/3
authorMichal Bloch <m.bloch@samsung.com>
Mon, 24 Sep 2018 14:34:40 +0000 (16:34 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 28 Sep 2018 10:59:58 +0000 (12:59 +0200)
Filters are just one of the many config entries and there are plans
to make others available in the dynamic API.

So far this is just a rename with no logic changes. In particular,
the dynamic API is still enabled alongside limiter for the time being.
This is to make actual logic changes easier to track.

Change-Id: I39296f07a0fe9f8c36ac244f9b790e16bdaa173c
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
Makefile.am
configs/dlog-logger.conf.test
configs/dlog-pipe.conf.test
configs/dlog.conf
include/dynamic_config.h [moved from include/log_filters.h with 72% similarity]
src/libdlog/dynamic_config.c [moved from src/libdlog/log_filters.c with 88% similarity]
src/libdlog/log.c
src/logctl/logctl.c
tests/test_filters.c

index 1d93d3a..3b5ccf3 100644 (file)
@@ -27,7 +27,7 @@ libdlog_la_SOURCES =  \
        src/shared/parsers.c \
        src/shared/queued_entry.c \
        src/shared/translate_syslog.c \
-       src/libdlog/log_filters.c \
+       src/libdlog/dynamic_config.c \
        src/libdlog/loglimiter.c \
        src/libdlog/log_pipe.c \
        src/libdlog/log_android.c
index d68e48e..966fda9 100644 (file)
@@ -39,4 +39,4 @@ dlog_logger_conf_main=dlogutil -b main -r 1024 -n 1 -f /var/log/dlog/main -v rec
 dlog_logger_conf_radio=dlogutil -b radio -r 256 -n 1 -f /var/log/dlog/radio -v recv_realtime
 dlog_logger_conf_kmsg=dlogutil -b kmsg -r 1024 -n 1 -f /var/log/dlog/kernel -v rwtime
 util_sorting_buffer_size=8192
-dynamic_filters_path=/tmp/dlog-filters/
+dynamic_config_path=/tmp/dlog-filters/
index b9c7ce8..711e14b 100644 (file)
@@ -86,4 +86,4 @@ syslog_size=1048576
 
 util_sorting_time_window=5000
 util_sorting_buffer_size=32000
-dynamic_filters_path=/tmp/dlog-filters/
+dynamic_config_path=/tmp/dlog-filters/
index 2392983..f3a1035 100644 (file)
@@ -16,8 +16,8 @@ limiter|*|*=allow
 # A flag indicating if apps/events buffer entries are always checked against static/dynamic limiter rules
 limiter_apply_to_all_buffers=0
 
-# dynamic filters_path - specifies the path to a DIRECTORY to enable dynamic runtime filter set changes (use dlogctl for control)
-# dynamic_filters_path=/run/dlog/filters.d/
+# dynamic config_path - specifies the path to a DIRECTORY to enable dynamic runtime config changes (use dlogctl for control)
+# dynamic_config_path=/run/dlog/filters.d/
 
 ##### Settings used by the logging daemon
 
similarity index 72%
rename from include/log_filters.h
rename to include/dynamic_config.h
index 925ba86..770e679 100644 (file)
@@ -23,12 +23,12 @@ extern "C" {
 
 #include <logconfig.h>
 
-#define DYNAMIC_FILTERS_CONF_KEY "dynamic_filters_path"
-#define DYNAMIC_FILTERS_FILENAME "FILTERS"
+#define DYNAMIC_CONFIG_CONF_KEY "dynamic_config_path"
+#define DYNAMIC_CONFIG_FILENAME "FILTERS" // legacy name; should ideally become "CONFIG" at some point
 
-void __dynamic_filters_create(struct log_config *config);
-void __dynamic_filters_destroy();
-void __dynamic_filters_update();
+void __dynamic_config_create(struct log_config *config);
+void __dynamic_config_destroy();
+void __dynamic_config_update();
 
 #ifdef __cplusplus
 }
similarity index 88%
rename from src/libdlog/log_filters.c
rename to src/libdlog/dynamic_config.c
index e173a63..33563e5 100644 (file)
@@ -22,9 +22,9 @@
 #include <unistd.h>
 #include <sys/inotify.h>
 
+#include <dynamic_config.h>
 #include <logcommon.h>
 #include <logconfig.h>
-#include <log_filters.h>
 #include <loglimiter.h>
 
 static int inotify_fd = -1;
@@ -69,16 +69,16 @@ static void __update_filters()
 }
 
 /// caller has to guarantee exclusive access
-void __dynamic_filters_create(struct log_config *config)
+void __dynamic_config_create(struct log_config *config)
 {
        assert(config);
        assert(!inotify_path);
 
-       const char *const extra_filters_path = log_config_get(config, DYNAMIC_FILTERS_CONF_KEY);
-       if (!extra_filters_path)
+       const char *const extra_config_path = log_config_get(config, DYNAMIC_CONFIG_CONF_KEY);
+       if (!extra_config_path)
                return;
 
-       if (asprintf(&inotify_path, "%s/%s", extra_filters_path, DYNAMIC_FILTERS_FILENAME) < 0) {
+       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
@@ -90,11 +90,11 @@ void __dynamic_filters_create(struct log_config *config)
         */
        log_config_read_file(config, inotify_path);
 
-       __setup_runtime_watch(extra_filters_path);
+       __setup_runtime_watch(extra_config_path);
 }
 
 /// caller has to guarantee exclusive access
-void __dynamic_filters_destroy()
+void __dynamic_config_destroy()
 {
        assert(inotify_fd < 0 || inotify_path);
        assert(inotify_wd < 0 || inotify_fd >= 0);
@@ -116,7 +116,7 @@ void __dynamic_filters_destroy()
        inotify_fd = -1;
 }
 
-void __dynamic_filters_update()
+void __dynamic_config_update()
 {
        if (inotify_fd < 0)
                return;
index 9badc63..75f90cd 100644 (file)
@@ -21,8 +21,8 @@
 #include <stdbool.h>
 #include <stdio.h>
 
+#include <dynamic_config.h>
 #include <logcommon.h>
-#include <log_filters.h>
 #include "loglimiter.h"
 #include "logconfig.h"
 #include <assert.h>
@@ -77,11 +77,11 @@ static void __configure_limiter(struct log_config *config)
        if (!limiter)
                return;
 
-       __dynamic_filters_create(config);
+       __dynamic_config_create(config);
        limiter = __log_limiter_create(config);
 
        if (!limiter)
-               __dynamic_filters_destroy();// LCOV_EXCL_LINE
+               __dynamic_config_destroy(); // LCOV_EXCL_LINE
 }
 
 static int __configure_backend(struct log_config *config)
@@ -197,7 +197,7 @@ static int dlog_should_log(log_id_t log_id, int prio, const char *tag)
                return DLOG_ERROR_NOT_PERMITTED;
 
        if (limiter) {
-               __dynamic_filters_update();
+               __dynamic_config_update();
 
                // LCOV_EXCL_START : disabled feature (limiter)
                pthread_mutex_lock(&log_init_lock);
@@ -299,5 +299,5 @@ int dlog_print(log_priority prio, const char *tag, const char *fmt, ...)
 void __attribute__((destructor)) __dlog_fini(void)
 {
        __log_limiter_destroy();
-       __dynamic_filters_destroy();
+       __dynamic_config_destroy();
 }
index 2d7d139..4c671bd 100644 (file)
@@ -12,9 +12,9 @@
 #include <sys/stat.h>
 
 // DLog
+#include <dynamic_config.h>
 #include <logcommon.h>
 #include <logconfig.h>
-#include <log_filters.h>
 #include <loglimiter.h>
 
 struct parsed_params {
@@ -161,7 +161,7 @@ void copy_except(FILE *in, FILE *out, const char *key, const char *value)
                fprintf(out, "%s%s\n", key, value);
 }
 
-int handle_set(const struct parsed_params *params, char *filters_path, struct log_config *conf)
+int handle_set(const struct parsed_params *params, char *config_path, struct log_config *conf)
 {
        __attribute__((cleanup(free_ptr))) char *key;
        if (asprintf(&key, "limiter|%s|%c=", params->tag, params->prio) < 0) {
@@ -170,14 +170,14 @@ int handle_set(const struct parsed_params *params, char *filters_path, struct lo
                return EXIT_FAILURE;
        }
 
-       __attribute__((cleanup(close_FILE))) FILE *const filtersfile = fopen(filters_path, "a+"); // won't actually append anything but this is the only mode that both positions the read steam at the beginning and opens the file if missing
-       if (!filtersfile) {
-               ERR("filters file %s fopen failed: %m\n", filters_path);
+       __attribute__((cleanup(close_FILE))) FILE *const configfile = fopen(config_path, "a+"); // won't actually append anything but this is the only mode that both positions the read steam at the beginning and opens the file if missing
+       if (!configfile) {
+               ERR("config file %s fopen failed: %m\n", config_path);
                return EXIT_FAILURE;
        }
 
        __attribute__((cleanup(free_ptr))) char *tempname = NULL;
-       int r = asprintf(&tempname, "%sXXXXXX", filters_path);
+       int r = asprintf(&tempname, "%sXXXXXX", config_path);
        if (r < 0) {
                tempname = NULL;
                ERR("asprintf tempname failed: %m\n");
@@ -201,9 +201,9 @@ int handle_set(const struct parsed_params *params, char *filters_path, struct lo
                goto remove_temp;
        }
 
-       copy_except(filtersfile, tempfile, key, params->value);
+       copy_except(configfile, tempfile, key, params->value);
 
-       if (rename(tempname, filters_path) < 0) {
+       if (rename(tempname, config_path) < 0) {
                ERR("rename failed: %m\n");
                goto remove_temp;
        }
@@ -240,7 +240,7 @@ static void print_limit(int limit, const char *tag, char prio, bool *shadowed, b
                *shadowed = true;
 }
 
-int handle_get(const struct parsed_params *params, char *filters_path, struct log_config *conf)
+int handle_get(const struct parsed_params *params, char *config_path, struct log_config *conf)
 {
        if (!__log_limiter_create(conf)) {
                ERR("error creating limiter\n");
@@ -249,7 +249,7 @@ int handle_get(const struct parsed_params *params, char *filters_path, struct lo
 
        struct limiter_limits lims_static = __log_limiter_get_limits(params->tag, params->prio);
 
-       log_config_read_file(conf, filters_path); // not an error on failure - config still valid if missing, static rules apply
+       log_config_read_file(conf, config_path); // not an error on failure - config still valid if missing, static rules apply
        __log_limiter_update(conf);
        struct limiter_limits lims_dynamic = __log_limiter_get_limits(params->tag, params->prio);
 
@@ -274,7 +274,7 @@ int handle_get(const struct parsed_params *params, char *filters_path, struct lo
        return EXIT_SUCCESS;
 }
 
-int handle_dump(const struct parsed_params *params, char *filters_path, struct log_config *conf)
+int handle_dump(const struct parsed_params *params, char *config_path, struct log_config *conf)
 {
        if (!__log_limiter_create(conf)) {
                ERR("error creating limiter\n");
@@ -282,7 +282,7 @@ int handle_dump(const struct parsed_params *params, char *filters_path, struct l
        }
        char buf[1024];
 
-       log_config_read_file(conf, filters_path); // not an error on failure - config still valid if missing, static rules apply
+       log_config_read_file(conf, config_path); // not an error on failure - config still valid if missing, static rules apply
        __log_limiter_update(conf);
 
        struct rule *r = NULL;
@@ -315,14 +315,14 @@ int main(int argc, const char **argv)
                return EXIT_FAILURE;
        }
 
-       const char *const extra_filters_path = log_config_get(&conf, DYNAMIC_FILTERS_CONF_KEY);
-       if (!extra_filters_path) {
-               printf("Dynamic filters are disabled (\"%s\" not defined in config)\n", DYNAMIC_FILTERS_CONF_KEY);
+       const char *const extra_config_path = log_config_get(&conf, DYNAMIC_CONFIG_CONF_KEY);
+       if (!extra_config_path) {
+               printf("Dynamic config is disabled (\"%s\" not defined in config)\n", DYNAMIC_CONFIG_CONF_KEY);
                return EXIT_SUCCESS;
        }
 
        __attribute__ ((cleanup(free_ptr))) char *full_inotify_path = NULL;
-       if (asprintf(&full_inotify_path, "%s/%s", extra_filters_path, DYNAMIC_FILTERS_FILENAME) < 0) {
+       if (asprintf(&full_inotify_path, "%s/%s", extra_config_path, DYNAMIC_CONFIG_FILENAME) < 0) {
                full_inotify_path = NULL;
                ERR("asprintf: no memory");
                return EXIT_FAILURE;
index 42eb769..e36b5a2 100644 (file)
 
 // DLOG
 #include <dlog.h>
+#include <dynamic_config.h>
 #include <logcommon.h>
-#include <log_filters.h>
 #include <loglimiter.h>
 
-#define FILTERS_CONF "/tmp/dlog-filters/" DYNAMIC_FILTERS_FILENAME
+#define DYNAMIC_CONF "/tmp/dlog-filters/" DYNAMIC_CONFIG_FILENAME
 #define BUF_LEN (MAX_CONF_KEY_LEN + MAX_CONF_VAL_LEN + 3) // +3 because KEY=VAL\n\0
 
 #define FILTER_ALLOW (__LOG_LIMITER_LIMIT_MAX + 1)
@@ -39,9 +39,9 @@ int set_config(int flag, char prio, const char *tag, int limit)
        char buf[BUF_LEN];
        const int flags = O_CREAT | O_WRONLY | flag;
 
-       __attribute__ ((cleanup(close_fd))) const int fd = open(FILTERS_CONF, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+       __attribute__ ((cleanup(close_fd))) const int fd = open(DYNAMIC_CONF, flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
        if (fd < 0) {
-               perror("error opening filters conf file");
+               perror("error opening dynamic conf file");
                return -errno;
        }
 
@@ -69,9 +69,9 @@ int set_config(int flag, char prio, const char *tag, int limit)
 
 int erase_file()
 {
-       __attribute__ ((cleanup(close_fd))) const int fd = open(FILTERS_CONF, O_RDWR|O_TRUNC);
+       __attribute__ ((cleanup(close_fd))) const int fd = open(DYNAMIC_CONF, O_RDWR|O_TRUNC);
        if (fd < 0) {
-               perror("error opening filters conf file");
+               perror("error opening dynamic conf file");
                return -errno;
        }