/* Reads all of the configuration files or directories that have been added
* with cfg_add_file(), merges their content. Any previous configuration is
- * replaced. */
-void
+ * replaced. Returns 0 if successful, otherwise a positive errno value. */
+int
cfg_read(void)
{
+ struct svec old_cfg;
struct ds ds;
FILE *file;
char *section;
if (!cfg_name) {
- return;
+ return ENODEV;
}
- /* Clear old configuration data. */
- svec_clear(&cfg);
+ /* Save old configuration data and clear the active configuration. */
+ svec_init(&old_cfg);
+ svec_swap(&old_cfg, &cfg);
/* Read new configuration. */
VLOG_DBG("reading configuration from %s", cfg_name);
file = fopen(cfg_name, "r");
if (!file) {
VLOG_ERR("failed to open \"%s\": %s", cfg_name, strerror(errno));
- return;
+ return errno;
}
ds_init(&ds);
fclose(file);
if (VLOG_IS_DBG_ENABLED()) {
+ struct svec removed, added;
size_t i;
- VLOG_DBG("new configuration:");
- for (i = 0; i < cfg.n; i++) {
- VLOG_DBG("%s", cfg.names[i]);
+ svec_diff(&old_cfg, &cfg, &removed, NULL, &added);
+ if (removed.n || added.n) {
+ VLOG_DBG("configuration changes:");
+ for (i = 0; i < removed.n; i++) {
+ VLOG_DBG("-%s", removed.names[i]);
+ }
+ for (i = 0; i < added.n; i++) {
+ VLOG_DBG("+%s", added.names[i]);
+ }
+ } else {
+ VLOG_DBG("configuration unchanged");
}
+ svec_destroy(&added);
+ svec_destroy(&removed);
}
+ svec_destroy(&old_cfg);
+
+ return 0;
}
int