libdlog: don't read the config twice 98/190498/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 2 Oct 2018 11:29:38 +0000 (13:29 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 10 Oct 2018 11:08:15 +0000 (11:08 +0000)
Change-Id: I6c921f264cec7da77da0918ee94f03493f017424
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/libdlog/log.c
src/libdlog/log_android.c
src/libdlog/log_pipe.c

index ae29e09..582267d 100644 (file)
@@ -47,8 +47,8 @@ static int __write_to_log_null(log_id_t, log_priority, const char *, const char
  */
 int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg) = __write_to_log_null;
 pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
-extern void __dlog_init_pipe();
-extern void __dlog_init_android();
+extern void __dlog_init_pipe(const struct log_config *conf);
+extern void __dlog_init_android(const struct log_config *conf);
 
 bool limiter;
 bool dynamic_config;
@@ -93,9 +93,9 @@ static int __configure_backend(struct log_config *config)
                return 0;
 
        if (!strcmp(backend, "pipe"))
-               __dlog_init_pipe();
+               __dlog_init_pipe(config);
        else if (!strcmp(backend, "logger"))
-               __dlog_init_android();
+               __dlog_init_android(config);
        else
                return 0;
 
index 8ff4cc7..8e4f4f8 100644 (file)
@@ -74,16 +74,12 @@ static int __write_to_log_android(log_id_t log_id, log_priority prio, const char
  * @brief Initialize the backend
  * @details Prepares the backend for proper and fruitful work
  */
-void __dlog_init_android()
+void __dlog_init_android(const struct log_config *conf)
 {
-       struct log_config conf;
        log_id_t buf_id;
 
-       if (log_config_read(&conf) < 0)
-               return;
-
        for (buf_id = 0; buf_id < LOG_ID_MAX; ++buf_id) {
-               int ret = logger_open_buffer_from_config(buf_id, &conf, O_WRONLY, &log_fds[buf_id]);
+               int ret = logger_open_buffer_from_config(buf_id, conf, O_WRONLY, &log_fds[buf_id]);
 
                if (ret < 0)
                        goto failure; //LCOV_EXCL_LINE
@@ -91,15 +87,12 @@ void __dlog_init_android()
                        continue;
        }
        write_to_log = __write_to_log_android;
-       goto cleanup;
+       return;
 
 failure:
        for (buf_id = 0; buf_id < LOG_ID_MAX; buf_id++) { // LCOV_EXCL_LINE
                if (log_fds[buf_id] >= 0) // LCOV_EXCL_LINE
                        close(log_fds[buf_id]); // LCOV_EXCL_LINE
        }
-cleanup:
-       log_config_free(&conf);
-       return;
 }
 
index 05e9138..f436597 100644 (file)
@@ -159,9 +159,8 @@ static int __write_to_log_pipe(log_id_t log_id, log_priority prio, const char *t
  * @brief Initialize the backend
  * @details Prepares the backend for proper and fruitful work
  */
-void __dlog_init_pipe()
+void __dlog_init_pipe(const struct log_config *conf)
 {
-       struct log_config conf;
        int i;
 
        /*
@@ -171,20 +170,15 @@ void __dlog_init_pipe()
         */
        signal(SIGPIPE, SIG_IGN);
 
-       if (log_config_read(&conf) < 0)
-               return; // LCOV_EXCL_LINE
-
        for (i = 0; i < LOG_ID_MAX; ++i) {
                char conf_key[MAX_CONF_KEY_LEN];
                snprintf(conf_key, sizeof(conf_key), "%s_write_sock", log_name_by_id(i));
-               const char * conf_val = log_config_get(&conf, conf_key);
+               const char * conf_val = log_config_get(conf, conf_key);
                if (!conf_val) {
                        syslog_critical_failure("DLOG CRITICAL FAILURE: DLog config lacks the \"%s\" entry!", conf_key); // LCOV_EXCL_LINE
-                       log_config_free(&conf); // LCOV_EXCL_LINE
                        return; // LCOV_EXCL_LINE
                }
                snprintf(log_pipe_path[i], PATH_MAX, "%s", conf_val);
        }
-       log_config_free(&conf);
        write_to_log = __write_to_log_pipe;
 }