]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
daemonize by default. -d to debugmode.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 23 Feb 2007 15:23:33 +0000 (15:23 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 23 Feb 2007 15:23:33 +0000 (15:23 +0000)
git-svn-id: file:///svn/unbound/trunk@141 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/unbound.c
doc/Changelog
doc/unbound.8
testcode/testbound.c
testdata/fwd_tcp.tpkg
testdata/fwd_udp.tpkg
util/config_file.c

index 965ca137fed2e1558f00e28e8d348bef447f0375..28f05d47397d95a2a082b4e7363e8c1c4ae1bda1 100644 (file)
@@ -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;
 }
index 297f2fe5e211c0d7444672f10e66b6eae2fd4422..5ffabd12481fbec3068602068265311ef8778cf2 100644 (file)
@@ -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.
index 7993904b71abb56d6e0fb8d30b8209330d8fb5c5..aaa5c8367f6d94ceb4187ce698ba37dc3076793d 100644 (file)
@@ -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.
index 09100bc44618eb92b68814bdfb79853bb1de7979..b749c8874fe1521385547fd082ec0497207a0b47 100644 (file)
@@ -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':
index f8d35662f04d65e7fcf12decc71d26c5f9d9293e..f73cd62c64887266db47323bbab6a892cac3f41f 100644 (file)
Binary files a/testdata/fwd_tcp.tpkg and b/testdata/fwd_tcp.tpkg differ
index 8a079cdef0e6860f477bbe10ac9d82aaa145b0d7..f52c96d82d79923bef830f0542a764de988556d2 100644 (file)
Binary files a/testdata/fwd_udp.tpkg and b/testdata/fwd_udp.tpkg differ
index 3be1bad601fb521e4cf571ac661b15089f59b1a6..8e05e0da2dbef3164af009c7bf434058fb50531e 100644 (file)
@@ -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;