From: Martin Mares Date: Sun, 22 Feb 2009 10:41:13 +0000 (+0100) Subject: Config: If cf_def_file is NULL, initialize the configuration. X-Git-Tag: holmes-import~35 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=b05c4e0038343a70f086d85f17bb1947fa789d16;p=libucw.git Config: If cf_def_file is NULL, initialize the configuration. Otherwise we end up uninitialized clists and other nasty stuff. (The problems were rarely visible, but the recent changes to conf-input.c have caused some extra commits, which crashed when no configuration was loaded.) This is a departure from the behavior of LibUCW 3.12, but I think we should guarantee that after cf_getopt(), the configuration is always in a consistent state, meaning that it has been initialized and committed. This should not depend on whether the default config file was loaded or not. On the other hand, program which avoid cf_getopt() and call cf_load() are on their own, there is no implicit commit for them yet. Maybe this should be fixed, too. --- diff --git a/ucw/conf-input.c b/ucw/conf-input.c index 09d21c83..e0ef334d 100644 --- a/ucw/conf-input.c +++ b/ucw/conf-input.c @@ -285,6 +285,7 @@ error: #define DEFAULT_CONFIG NULL #endif char *cf_def_file = DEFAULT_CONFIG; +static int cf_def_loaded; #ifndef ENV_VAR_CONFIG #define ENV_VAR_CONFIG NULL @@ -408,7 +409,7 @@ cf_load(const char *file) if (!err) { cf_journal_commit_transaction(1, oldj); cf_remember_entry(CE_FILE, file); - cf_def_file = NULL; + cf_def_loaded = 1; } else cf_journal_rollback_transaction(1, oldj); return err; @@ -432,6 +433,8 @@ cf_set(const char *string) static void load_default(void) { + if (cf_def_loaded++) + return; if (cf_def_file) { char *env; @@ -445,8 +448,11 @@ load_default(void) } else { - // We need to create an empty pool - cf_journal_commit_transaction(1, cf_journal_new_transaction(1)); + // We need to create an empty pool and initialize all configuration items + struct cf_journal_item *oldj = cf_journal_new_transaction(1); + cf_init_stack(); + done_stack(); + cf_journal_commit_transaction(1, oldj); } }