daemon: Allow configuration of logfile path as value
authorTobias Brunner <tobias@strongswan.org>
Thu, 31 May 2018 09:36:15 +0000 (11:36 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 27 Jun 2018 12:19:35 +0000 (14:19 +0200)
Some characters are not allowed in section names, this way they can
still be used in paths of log files.

conf/options/charon-logging.opt
src/libcharon/daemon.c

index 2bbb5dc..31ebf6c 100644 (file)
@@ -5,6 +5,10 @@ charon.filelog {}
 charon.filelog.<filename> { # }
        <filename> is the full path to the log file.
 
+charon.filelog.<filename>.path =
+       Optional path to the log file. Overrides the section name, may be used
+       if the path contains characters that aren't allowed in section names.
+
 charon.filelog.<filename>.default = 1
        Default loglevel.
 
index e4b8197..c02ab28 100644 (file)
@@ -480,25 +480,29 @@ static void load_sys_logger(private_daemon_t *this, char *facility,
 /**
  * Load the given file logger configured in strongswan.conf
  */
-static void load_file_logger(private_daemon_t *this, char *filename,
+static void load_file_logger(private_daemon_t *this, char *section,
                                                         linked_list_t *current_loggers)
 {
        file_logger_t *file_logger;
        debug_t group;
        level_t def;
        bool add_ms, ike_name, flush_line, append;
-       char *time_format;
+       char *time_format, *filename;
 
        time_format = lib->settings->get_str(lib->settings,
-                                               "%s.filelog.%s.time_format", NULL, lib->ns, filename);
+                                               "%s.filelog.%s.time_format", NULL, lib->ns, section);
        add_ms = lib->settings->get_bool(lib->settings,
-                                               "%s.filelog.%s.time_add_ms", FALSE, lib->ns, filename);
+                                               "%s.filelog.%s.time_add_ms", FALSE, lib->ns, section);
        ike_name = lib->settings->get_bool(lib->settings,
-                                               "%s.filelog.%s.ike_name", FALSE, lib->ns, filename);
+                                               "%s.filelog.%s.ike_name", FALSE, lib->ns, section);
        flush_line = lib->settings->get_bool(lib->settings,
-                                               "%s.filelog.%s.flush_line", FALSE, lib->ns, filename);
+                                               "%s.filelog.%s.flush_line", FALSE, lib->ns, section);
        append = lib->settings->get_bool(lib->settings,
-                                               "%s.filelog.%s.append", TRUE, lib->ns, filename);
+                                               "%s.filelog.%s.append", TRUE, lib->ns, section);
+       time_format = lib->settings->get_str(lib->settings,
+                                               "%s.filelog.%s.time_format", NULL, lib->ns, section);
+       filename = lib->settings->get_str(lib->settings,
+                                               "%s.filelog.%s.path", section, lib->ns, section);
 
        file_logger = add_file_logger(this, filename, current_loggers);
        if (!file_logger)
@@ -510,12 +514,12 @@ static void load_file_logger(private_daemon_t *this, char *filename,
        file_logger->open(file_logger, flush_line, append);
 
        def = lib->settings->get_int(lib->settings, "%s.filelog.%s.default", 1,
-                                                                lib->ns, filename);
+                                                                lib->ns, section);
        for (group = 0; group < DBG_MAX; group++)
        {
                file_logger->set_level(file_logger, group,
                                lib->settings->get_int(lib->settings, "%s.filelog.%s.%N", def,
-                                                       lib->ns, filename, debug_lower_names, group));
+                                                       lib->ns, section, debug_lower_names, group));
        }
        charon->bus->add_logger(charon->bus, &file_logger->logger);
 }