]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix #1349: allow suppression of pidfiles (from Daniel Kahn Gillmor).
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 17 Jul 2017 08:26:49 +0000 (08:26 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 17 Jul 2017 08:26:49 +0000 (08:26 +0000)
  With the -p option unbound does not create a pidfile.

git-svn-id: file:///svn/unbound/trunk@4276 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/unbound.c
doc/Changelog
doc/unbound.8.in

index ba7337d8907adb4252aa648c36e65b5c7f9e7972..53b6e1393bdc837f7b5e4fdb0d21ace936456ea5 100644 (file)
@@ -400,7 +400,7 @@ detach(void)
 /** daemonize, drop user priviliges and chroot if needed */
 static void
 perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
-       const char** cfgfile)
+       const char** cfgfile, int need_pidfile)
 {
 #ifdef HAVE_KILL
        int pidinchroot;
@@ -444,13 +444,13 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
 
 #ifdef HAVE_KILL
        /* true if pidfile is inside chrootdir, or nochroot */
-       pidinchroot = !(cfg->chrootdir && cfg->chrootdir[0]) ||
+       pidinchroot = need_pidfile && (!(cfg->chrootdir && cfg->chrootdir[0]) ||
                                (cfg->chrootdir && cfg->chrootdir[0] &&
                                strncmp(cfg->pidfile, cfg->chrootdir,
-                               strlen(cfg->chrootdir))==0);
+                               strlen(cfg->chrootdir))==0));
 
        /* check old pid file before forking */
-       if(cfg->pidfile && cfg->pidfile[0]) {
+       if(cfg->pidfile && cfg->pidfile[0] && need_pidfile) {
                /* calculate position of pidfile */
                if(cfg->pidfile[0] == '/')
                        daemon->pidfile = strdup(cfg->pidfile);
@@ -469,7 +469,7 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
 
        /* write new pidfile (while still root, so can be outside chroot) */
 #ifdef HAVE_KILL
-       if(cfg->pidfile && cfg->pidfile[0]) {
+       if(cfg->pidfile && cfg->pidfile[0] && need_pidfile) {
                writepid(daemon->pidfile, getpid());
                if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1 &&
                        pidinchroot) {
@@ -602,7 +602,7 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
  * @param log_default_identity: Default identity to report in logs
  */
 static void 
-run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode, const char* log_default_identity)
+run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode, const char* log_default_identity, int need_pidfile)
 {
        struct config_file* cfg = NULL;
        struct daemon* daemon = NULL;
@@ -632,7 +632,7 @@ run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode, const char*
                if(!daemon_open_shared_ports(daemon))
                        fatal_exit("could not open ports");
                if(!done_setup) { 
-                       perform_setup(daemon, cfg, debug_mode, &cfgfile);
+                       perform_setup(daemon, cfg, debug_mode, &cfgfile, need_pidfile);
                        done_setup = 1; 
                } else {
                        /* reopen log after HUP to facilitate log rotation */
@@ -682,6 +682,8 @@ main(int argc, char* argv[])
        const char* log_ident_default;
        int cmdline_verbose = 0;
        int debug_mode = 0;
+       int need_pidfile = 1;
+
 #ifdef UB_ON_WINDOWS
        int cmdline_cfg = 0;
 #endif
@@ -690,7 +692,7 @@ main(int argc, char* argv[])
        log_ident_default = strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0];
        log_ident_set(log_ident_default);
        /* parse the options */
-       while( (c=getopt(argc, argv, "c:dhvw:")) != -1) {
+       while( (c=getopt(argc, argv, "c:dhpvw:")) != -1) {
                switch(c) {
                case 'c':
                        cfgfile = optarg;
@@ -702,6 +704,9 @@ main(int argc, char* argv[])
                        cmdline_verbose++;
                        verbosity++;
                        break;
+               case 'p':
+                       need_pidfile = 0;
+                       break;
                case 'd':
                        debug_mode++;
                        break;
@@ -732,7 +737,7 @@ main(int argc, char* argv[])
                return 1;
        }
 
-       run_daemon(cfgfile, cmdline_verbose, debug_mode, log_ident_default);
+       run_daemon(cfgfile, cmdline_verbose, debug_mode, log_ident_default, need_pidfile);
        log_init(NULL, 0, NULL); /* close logfile */
        return 0;
 }
index 03d0593f1cdd863b88f187e52132de1a19421514..91f430b2fabb7d30e8394144cebd0de3745a0838 100644 (file)
@@ -1,5 +1,7 @@
 17 July 2017: Wouter
        - Fix #1350: make cachedb backend configurable (from JINMEI Tatuya).
+       - Fix #1349: allow suppression of pidfiles (from Daniel Kahn Gillmor).
+         With the -p option unbound does not create a pidfile.
 
 11 July 2017: Wouter
        - Fix #1344: RFC6761-reserved domains: test. and invalid.
index 36014430dc29c52082397c96c53c16572a37378e..cea3aef18dd77330a3f0cf2b3018ca4b455d80f7 100644 (file)
@@ -14,6 +14,7 @@
 .B unbound
 .RB [ \-h ]
 .RB [ \-d ]
+.RB [ \-p ]
 .RB [ \-v ]
 .RB [ \-c
 .IR cfgfile ]
@@ -67,6 +68,11 @@ the thread\-spawn time, so that most config and setup errors appear on
 stderr. If given twice or more, logging does not switch to the log file
 or to syslog, but the log messages are printed to stderr all the time.
 .TP
+.B \-p
+Don't use a pidfile.  This argument should only be used by supervision
+systems which can ensure that only one instance of unbound will run
+concurrently.
+.TP
 .B \-v
 Increase verbosity. If given multiple times, more information is logged.
 This is in addition to the verbosity (if any) from the config file.