Skip to content

Commit

Permalink
Enhanced diagnostics of config files.
Browse files Browse the repository at this point in the history
Load config files as late as possible, so that -v options have a chance to
take effect. Extra verbose messages when processing the config files
  • Loading branch information
dleonard committed Oct 14, 2008
1 parent 5b76690 commit 1f91120
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions conf-t.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#define TESTFILEPATH "/tmp/_conf_test.txt"

int verbose;

int main()
{
FILE *f;
Expand Down
11 changes: 10 additions & 1 deletion conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "conf.h"
#include "stream.h"

extern int verbose;

/* A configuration entry */
struct config {
char *key, *value;
Expand Down Expand Up @@ -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. */
Expand All @@ -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);
}
Expand Down
23 changes: 19 additions & 4 deletions dnsupdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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':
Expand All @@ -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':
Expand All @@ -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;
Expand Down

0 comments on commit 1f91120

Please sign in to comment.