]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
config file param.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 20 Feb 2007 16:19:00 +0000 (16:19 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 20 Feb 2007 16:19:00 +0000 (16:19 +0000)
git-svn-id: file:///svn/unbound/trunk@133 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/unbound.c
util/config_file.c

index cece1953e10b316fdd560ef5e03d62f249e2a702..9abd10a4a9e01b06aaad7cf5638380019ae4b4af 100644 (file)
@@ -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);
index df6d34e038b2dcc4ce560e156dbeac610ecf9ee2..038e601a02dacbf54a94ea3b6299026d42ad736c 100644 (file)
@@ -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;
 }