diff --git a/conf-t.c b/conf-t.c index 29fc80d..c84ae4c 100644 --- a/conf-t.c +++ b/conf-t.c @@ -6,6 +6,8 @@ #define TESTFILEPATH "/tmp/_conf_test.txt" +int verbose; + int main() { FILE *f; diff --git a/conf.c b/conf.c index c048014..7f6a3cb 100644 --- a/conf.c +++ b/conf.c @@ -8,6 +8,8 @@ #include "conf.h" #include "stream.h" +extern int verbose; + /* A configuration entry */ struct config { char *key, *value; @@ -40,6 +42,8 @@ config_add(char *key, char *value) config->value = value; config->next = Config; Config = config; + if (verbose > 2) + fprintf(stderr, "config_add: %s = %s\n", key, value); } /* Adds settings from a configuration file into the global configuration. */ @@ -48,8 +52,13 @@ config_load(const char *path) { struct stream stream; - if (!stream_init_path(&stream, path)) + if (verbose > 2) + fprintf(stderr, "config_load %s\n", path); + if (!stream_init_path(&stream, path)) { + if (verbose) + warn("%s", path); return; + } config_load_stream(&stream); stream_fini(&stream); } diff --git a/dnsupdate.c b/dnsupdate.c index 06d3ba4..1be6ca3 100644 --- a/dnsupdate.c +++ b/dnsupdate.c @@ -921,6 +921,19 @@ parent_domain(const char *d) return d; } +/* Load default configuration, once */ +static void +config_init_once() +{ + static int config_loaded; + + if (!config_loaded) { + config_loaded = 1; + config_load(PATH_SYSCONFDIR "/dnsupdate.conf"); + resconf_init(); + } +} + /* Sets an option of the form "KEY=VALUE" */ static int config_opt(char *arg) @@ -970,10 +983,6 @@ main(int argc, char **argv) err_enable_syslog(1); - /* Load default configuration */ - config_load(PATH_SYSCONFDIR "/dnsupdate.conf"); - resconf_init(); - /* Argument processing */ while ((ch = getopt(argc, argv, "a:C:d:h:INo:rs:S:t:vV")) != -1) switch (ch) { @@ -994,15 +1003,18 @@ main(int argc, char **argv) ietf_compliant = 1; break; case 'N': + config_init_once(); config_add("UpdateSecurityLevel", STR(SECURITY_ONLY_UNSECURE)); break; case 'o': + config_init_once(); if (!config_opt(optarg)) { fprintf(stderr, "bad option '%s'\n", optarg); opterror = 1; } break; case 'r': + config_init_once(); config_add("RegisterReverseLookup", "1"); break; case 's': @@ -1013,6 +1025,7 @@ main(int argc, char **argv) server_spn = optarg; break; case 't': + config_init_once(); config_add("RegistrationTtl", optarg); break; case 'v': @@ -1027,6 +1040,8 @@ main(int argc, char **argv) break; } + config_init_once(); + /* Expect an IP address argument */ if (!(optind < argc && my_inet_aton(argv[optind++], ipaddr, sizeof ipaddr))) opterror = 1;