Skip to content

Commit

Permalink
Merge pull request #368 from lxbsz/logdir_dyn
Browse files Browse the repository at this point in the history
config: add the logdir option dynamic reloading support
  • Loading branch information
mikechristie committed Jun 1, 2018
2 parents 815e5f8 + 1b6e652 commit bb7279b
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 88 deletions.
31 changes: 22 additions & 9 deletions libtcmu_config.c
Expand Up @@ -114,21 +114,30 @@ do { \
} \
} while (0)

#define TCMU_PARSE_CFG_BOOL(cfg, key) \
#define TCMU_PARSE_CFG_BOOL(cfg, key, def) \
do { \
struct tcmu_conf_option *option; \
option = tcmu_get_option(#key); \
if (option) { \
cfg->key = option->opt_bool; \
option->opt_bool = def; \
} \
} while (0)

#define TCMU_PARSE_CFG_STR(cfg, key) \
#define TCMU_PARSE_CFG_STR(cfg, key, def) \
do { \
struct tcmu_conf_option *option; \
char buf[1024]; \
option = tcmu_get_option(#key); \
if (option) { \
cfg->key = strdup(option->opt_str); } \
if (cfg->key) \
free(cfg->key); \
cfg->key = strdup(option->opt_str); \
if (option->opt_str) \
free(option->opt_str); \
sprintf(buf, "%s", def); \
option->opt_str = strdup(buf); \
} \
} while (0);

#define TCMU_FREE_CFG_STR_KEY(cfg, key) \
Expand All @@ -144,9 +153,9 @@ static void tcmu_conf_set_options(struct tcmu_config *cfg, bool reloading)
tcmu_set_log_level(cfg->log_level);
}

/* set log_dir path option */
TCMU_PARSE_CFG_STR(cfg, log_dir_path, TCMU_LOG_DIR_DEFAULT);
if (!reloading) {
/* set log_dir path option */
TCMU_PARSE_CFG_STR(cfg, log_dir_path);
/*
* The priority of the logdir setting is:
* 1, --tcmu_log_dir/-l LOG_DIR_PATH
Expand All @@ -155,11 +164,16 @@ static void tcmu_conf_set_options(struct tcmu_config *cfg, bool reloading)
* 4, default /var/log/
*/
if (!tcmu_get_logdir())
tcmu_logdir_create(cfg->log_dir_path);
tcmu_logdir_create(cfg->log_dir_path, false);
else
tcmu_warn("The logdir option from the tcmu.conf will be ignored\n");
} else {
tcmu_warn("The logdir option is not supported by dynamic reloading for now!\n");
/*
* Here we asume that users want to change the
* log_dir_path without considering the priority
* mentioned above.
*/
tcmu_logdir_resetup(cfg->log_dir_path);
}

/* add your new config options */
Expand All @@ -172,6 +186,7 @@ static void tcmu_conf_free_str_keys(struct tcmu_config *cfg)
* For example:
* TCMU_FREE_CFG_STR_KEY(cfg, 'STR KEY');
*/
TCMU_FREE_CFG_STR_KEY(cfg, log_dir_path);
}

#define TCMU_MAX_CFG_FILE_SIZE (2 * 1024 * 1024)
Expand Down Expand Up @@ -538,8 +553,6 @@ void tcmu_destroy_config(struct tcmu_config *cfg)
}

tcmu_conf_free_str_keys(cfg);
if (cfg->log_dir_path)
free(cfg->log_dir_path);
free(cfg->path);
free(cfg);
}

0 comments on commit bb7279b

Please sign in to comment.