From: Wouter Wijngaards Date: Fri, 23 Feb 2007 15:23:33 +0000 (+0000) Subject: daemonize by default. -d to debugmode. X-Git-Tag: release-0.1~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0a6f5130f96d2e6ac2ada21562857389cb7564a;p=thirdparty%2Funbound.git daemonize by default. -d to debugmode. git-svn-id: file:///svn/unbound/trunk@141 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/daemon/unbound.c b/daemon/unbound.c index 965ca137f..28f05d473 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -55,6 +55,7 @@ static void usage() printf(" start unbound daemon DNS resolver.\n"); printf("-h this help\n"); printf("-c file config file to read, unbound.conf(5).\n"); + printf("-d do not fork into the background.\n"); printf("-v verbose (multiple times increase verbosity)\n"); printf("Version %s\n", PACKAGE_VERSION); printf("BSD licensed, see LICENSE in source package for details.\n"); @@ -157,7 +158,7 @@ checkoldpid(struct config_file* cfg) /** daemonize, drop user priviliges and chroot if needed */ static void -do_chroot(struct daemon* daemon, struct config_file* cfg) +do_chroot(struct daemon* daemon, struct config_file* cfg, int debug_mode) { log_assert(cfg); @@ -182,7 +183,7 @@ do_chroot(struct daemon* daemon, struct config_file* cfg) /* init logfile just before fork */ log_init(cfg->logfile); - if(cfg->do_daemonize) { + if(!debug_mode && cfg->do_daemonize) { int fd; /* Take off... */ switch (fork()) { @@ -217,8 +218,9 @@ do_chroot(struct daemon* daemon, struct config_file* cfg) * @param cfgfile: the config file name. * @param cmdline_verbose: verbosity resulting from commandline -v. * These increase verbosity as specified in the config file. + * @param debug_mode: if set, do not daemonize. */ -static void run_daemon(const char* cfgfile, int cmdline_verbose) +static void run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode) { struct config_file* cfg = NULL; struct daemon* daemon = NULL; @@ -242,7 +244,7 @@ static void run_daemon(const char* cfgfile, int cmdline_verbose) if(!daemon_open_shared_ports(daemon)) fatal_exit("could not open ports"); if(!done_chroot) { - do_chroot(daemon, cfg); + do_chroot(daemon, cfg, debug_mode); done_chroot = 1; } /* work */ @@ -276,10 +278,11 @@ main(int argc, char* argv[]) int c; const char* cfgfile = NULL; int cmdline_verbose = 0; + int debug_mode = 0; log_init(NULL); /* parse the options */ - while( (c=getopt(argc, argv, "c:hv")) != -1) { + while( (c=getopt(argc, argv, "c:dhv")) != -1) { switch(c) { case 'c': cfgfile = optarg; @@ -288,6 +291,9 @@ main(int argc, char* argv[]) cmdline_verbose ++; verbosity++; break; + case 'd': + debug_mode = 1; + break; case '?': case 'h': default: @@ -303,6 +309,6 @@ main(int argc, char* argv[]) return 1; } - run_daemon(cfgfile, cmdline_verbose); + run_daemon(cfgfile, cmdline_verbose, debug_mode); return 0; } diff --git a/doc/Changelog b/doc/Changelog index 297f2fe5e..5ffabd124 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -5,6 +5,7 @@ - Ports for queries are shared. - config file added interface:, chroot: and username:. - config file: directory, logfile, pidfile. And they work too. + - will daemonize by default now. Use -d to stay in the foreground. 22 February 2007: Wouter - Have a config file. Removed commandline options, moved to config. diff --git a/doc/unbound.8 b/doc/unbound.8 index 7993904b7..aaa5c8367 100644 --- a/doc/unbound.8 +++ b/doc/unbound.8 @@ -41,8 +41,9 @@ unbound .Sh SYNOPSIS .Nm unbound .Op Fl h -.Op Fl c Ar cfgfile +.Op Fl d .Op Fl v +.Op Fl c Ar cfgfile .Sh DESCRIPTION .Ic Unbound @@ -60,6 +61,10 @@ Set the config file to read with settings for unbound. The syntax is described in .Xr unbound.conf 5 . +.It Fl d +Debug flag, do not fork into the background, but stay attached to the +console. + .It Fl v Increase verbosity. If given multiple times, more information is logged. This is in addition to the verbosity (if any) from the config file. diff --git a/testcode/testbound.c b/testcode/testbound.c index 09100bc44..b749c8874 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -156,6 +156,7 @@ main(int argc, char* argv[]) /* determine commandline options for the daemon */ pass_argc = 1; pass_argv[0] = "unbound"; + add_opts("-d", &pass_argc, pass_argv); while( (c=getopt(argc, argv, "ho:p:")) != -1) { switch(c) { case 'p': diff --git a/testdata/fwd_tcp.tpkg b/testdata/fwd_tcp.tpkg index f8d35662f..f73cd62c6 100644 Binary files a/testdata/fwd_tcp.tpkg and b/testdata/fwd_tcp.tpkg differ diff --git a/testdata/fwd_udp.tpkg b/testdata/fwd_udp.tpkg index 8a079cdef..f52c96d82 100644 Binary files a/testdata/fwd_udp.tpkg and b/testdata/fwd_udp.tpkg differ diff --git a/util/config_file.c b/util/config_file.c index 3be1bad60..8e05e0da2 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -84,7 +84,7 @@ config_create() if(!(cfg->logfile = strdup(""))) {config_delete(cfg); return NULL;} if(!(cfg->pidfile = strdup("unbound.pid"))) {config_delete(cfg); return NULL;} cfg->fwd_port = UNBOUND_DNS_PORT; - cfg->do_daemonize = 0; + cfg->do_daemonize = 1; cfg->num_ifs = 0; cfg->ifs = NULL; return cfg;