From: Wouter Wijngaards Date: Tue, 20 Feb 2007 16:19:00 +0000 (+0000) Subject: config file param. X-Git-Tag: release-0.1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2534d6b120fd831c67a4359c73eee82c233a0bab;p=thirdparty%2Funbound.git config file param. git-svn-id: file:///svn/unbound/trunk@133 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/unbound.c b/daemon/unbound.c index cece1953e..9abd10a4a 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -43,6 +43,7 @@ #include "config.h" #include "util/log.h" #include "daemon/worker.h" +#include "util/config_file.h" /** buffer size for network connections */ #define BUFSZ 65552 @@ -53,6 +54,7 @@ static void usage() printf("usage: unbound [options]\n"); printf(" start unbound daemon DNS resolver.\n"); printf("-h this help\n"); + printf("-c file config file to read, unbound.conf(5).\n"); printf("-p port the port to listen on\n"); printf("-v verbose (multiple times increase verbosity)\n"); printf("-f ip set forwarder address\n"); @@ -84,12 +86,16 @@ main(int argc, char* argv[]) int c; const char* fwd = "127.0.0.1"; const char* fwdport = UNBOUND_DNS_PORT; + const char* cfgfile = NULL; + struct config_file *cfg = NULL; log_init(); - log_info("Start of %s.", PACKAGE_STRING); /* parse the options */ - while( (c=getopt(argc, argv, "f:hvp:z:")) != -1) { + while( (c=getopt(argc, argv, "c:f:hvp:z:")) != -1) { switch(c) { + case 'c': + cfgfile = optarg; + break; case 'f': fwd = optarg; break; @@ -121,6 +127,18 @@ main(int argc, char* argv[]) return 1; } + if(!(cfg = config_create())) { + fprintf(stderr, "Could not init config defaults."); + return 1; + } + if(cfgfile) { + if(!config_read(cfg, cfgfile)) { + config_delete(cfg); + return 1; + } + } + log_info("Start of %s.", PACKAGE_STRING); + /* setup */ worker = worker_init(port, do_ip4, do_ip6, do_udp, do_tcp, BUFSZ, numports, baseport); diff --git a/util/config_file.c b/util/config_file.c index df6d34e03..038e601a0 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -73,6 +73,18 @@ config_create() return cfg; } +/** initialize the global cfg_parser object. */ +static void +create_cfg_parser(struct config_file* cfg, char* filename) +{ + static struct config_parser_state st; + cfg_parser = &st; + cfg_parser->filename = filename; + cfg_parser->line = 1; + cfg_parser->errors = 0; + cfg_parser->cfg = cfg; +} + int config_read(struct config_file* cfg, const char* filename) { @@ -81,7 +93,16 @@ config_read(struct config_file* cfg, const char* filename) log_err("Could not open %s: %s", filename, strerror(errno)); return 0; } + create_cfg_parser(cfg, (char*)filename); + ub_c_in = in; + ub_c_parse(); fclose(in); + + if(cfg_parser->errors != 0) { + fprintf(stderr, "read %s failed: %d errors in configuration file\n", + cfg_parser->filename, cfg_parser->errors); + return 0; + } return 1; }