mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
config file param.
git-svn-id: file:///svn/unbound/trunk@133 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
a87e39c8e6
commit
2534d6b120
2 changed files with 41 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue