From 428239a3ebbef7b43643cd86abd1323be2c64fbc Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Thu, 27 Apr 2006 18:26:15 +0200 Subject: [PATCH] conf2: when loading the initial configuration, commit only once at the end --- lib/conf2.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/conf2.c b/lib/conf2.c index 93eda587..ad3839ae 100644 --- a/lib/conf2.c +++ b/lib/conf2.c @@ -1085,6 +1085,8 @@ init_stack(void) }; } +static uns postpone_commit; // only for cf_get_opt() + static int done_stack(void) { @@ -1093,6 +1095,8 @@ done_stack(void) return 1; } sort_dirty(); + if (postpone_commit) + return 0; if (commit_section(§ions, NULL, !everything_committed)) return 1; everything_committed = 1; @@ -1100,6 +1104,16 @@ done_stack(void) return 0; } +static void +final_commit(void) +{ + if (postpone_commit) { + postpone_commit = 0; + if (done_stack()) + die("Cannot commit after the initialization"); + } +} + /* Text file parser */ static byte *name_parse_fb; @@ -1398,6 +1412,7 @@ cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct o int res = getopt_long (argc, argv, short_opts, long_opts, long_index); if (res == 'S' || res == 'C' || res == 0x64436667) { + postpone_commit = 1; if (other_options) die("The -S and -C options must precede all other arguments"); if (res == 'S') { @@ -1411,6 +1426,7 @@ cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct o #ifdef CONFIG_DEBUG else { /* --dumpconfig */ load_default(); + final_commit(); struct fastbuf *b = bfdopen(1, 4096); cf_dump_sections(b); bclose(b); @@ -1420,6 +1436,7 @@ cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct o /* unhandled option or end of options */ if (res != ':' && res != '?') load_default(); + final_commit(); other_options++; return res; } -- 2.39.2