mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
- Fix #1349: allow suppression of pidfiles (from Daniel Kahn Gillmor).
With the -p option unbound does not create a pidfile. git-svn-id: file:///svn/unbound/trunk@4276 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
c52c07c086
commit
1d3e6758b2
3 changed files with 22 additions and 9 deletions
|
|
@ -400,7 +400,7 @@ detach(void)
|
||||||
/** daemonize, drop user priviliges and chroot if needed */
|
/** daemonize, drop user priviliges and chroot if needed */
|
||||||
static void
|
static void
|
||||||
perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
|
perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
|
||||||
const char** cfgfile)
|
const char** cfgfile, int need_pidfile)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_KILL
|
#ifdef HAVE_KILL
|
||||||
int pidinchroot;
|
int pidinchroot;
|
||||||
|
|
@ -444,13 +444,13 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
|
||||||
|
|
||||||
#ifdef HAVE_KILL
|
#ifdef HAVE_KILL
|
||||||
/* true if pidfile is inside chrootdir, or nochroot */
|
/* 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] &&
|
(cfg->chrootdir && cfg->chrootdir[0] &&
|
||||||
strncmp(cfg->pidfile, cfg->chrootdir,
|
strncmp(cfg->pidfile, cfg->chrootdir,
|
||||||
strlen(cfg->chrootdir))==0);
|
strlen(cfg->chrootdir))==0));
|
||||||
|
|
||||||
/* check old pid file before forking */
|
/* check old pid file before forking */
|
||||||
if(cfg->pidfile && cfg->pidfile[0]) {
|
if(cfg->pidfile && cfg->pidfile[0] && need_pidfile) {
|
||||||
/* calculate position of pidfile */
|
/* calculate position of pidfile */
|
||||||
if(cfg->pidfile[0] == '/')
|
if(cfg->pidfile[0] == '/')
|
||||||
daemon->pidfile = strdup(cfg->pidfile);
|
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) */
|
/* write new pidfile (while still root, so can be outside chroot) */
|
||||||
#ifdef HAVE_KILL
|
#ifdef HAVE_KILL
|
||||||
if(cfg->pidfile && cfg->pidfile[0]) {
|
if(cfg->pidfile && cfg->pidfile[0] && need_pidfile) {
|
||||||
writepid(daemon->pidfile, getpid());
|
writepid(daemon->pidfile, getpid());
|
||||||
if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1 &&
|
if(cfg->username && cfg->username[0] && cfg_uid != (uid_t)-1 &&
|
||||||
pidinchroot) {
|
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
|
* @param log_default_identity: Default identity to report in logs
|
||||||
*/
|
*/
|
||||||
static void
|
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 config_file* cfg = NULL;
|
||||||
struct daemon* daemon = 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))
|
if(!daemon_open_shared_ports(daemon))
|
||||||
fatal_exit("could not open ports");
|
fatal_exit("could not open ports");
|
||||||
if(!done_setup) {
|
if(!done_setup) {
|
||||||
perform_setup(daemon, cfg, debug_mode, &cfgfile);
|
perform_setup(daemon, cfg, debug_mode, &cfgfile, need_pidfile);
|
||||||
done_setup = 1;
|
done_setup = 1;
|
||||||
} else {
|
} else {
|
||||||
/* reopen log after HUP to facilitate log rotation */
|
/* reopen log after HUP to facilitate log rotation */
|
||||||
|
|
@ -682,6 +682,8 @@ main(int argc, char* argv[])
|
||||||
const char* log_ident_default;
|
const char* log_ident_default;
|
||||||
int cmdline_verbose = 0;
|
int cmdline_verbose = 0;
|
||||||
int debug_mode = 0;
|
int debug_mode = 0;
|
||||||
|
int need_pidfile = 1;
|
||||||
|
|
||||||
#ifdef UB_ON_WINDOWS
|
#ifdef UB_ON_WINDOWS
|
||||||
int cmdline_cfg = 0;
|
int cmdline_cfg = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -690,7 +692,7 @@ main(int argc, char* argv[])
|
||||||
log_ident_default = strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0];
|
log_ident_default = strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0];
|
||||||
log_ident_set(log_ident_default);
|
log_ident_set(log_ident_default);
|
||||||
/* parse the options */
|
/* parse the options */
|
||||||
while( (c=getopt(argc, argv, "c:dhvw:")) != -1) {
|
while( (c=getopt(argc, argv, "c:dhpvw:")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
cfgfile = optarg;
|
cfgfile = optarg;
|
||||||
|
|
@ -702,6 +704,9 @@ main(int argc, char* argv[])
|
||||||
cmdline_verbose++;
|
cmdline_verbose++;
|
||||||
verbosity++;
|
verbosity++;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
need_pidfile = 0;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
debug_mode++;
|
debug_mode++;
|
||||||
break;
|
break;
|
||||||
|
|
@ -732,7 +737,7 @@ main(int argc, char* argv[])
|
||||||
return 1;
|
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 */
|
log_init(NULL, 0, NULL); /* close logfile */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
17 July 2017: Wouter
|
17 July 2017: Wouter
|
||||||
- Fix #1350: make cachedb backend configurable (from JINMEI Tatuya).
|
- 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
|
11 July 2017: Wouter
|
||||||
- Fix #1344: RFC6761-reserved domains: test. and invalid.
|
- Fix #1344: RFC6761-reserved domains: test. and invalid.
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
.B unbound
|
.B unbound
|
||||||
.RB [ \-h ]
|
.RB [ \-h ]
|
||||||
.RB [ \-d ]
|
.RB [ \-d ]
|
||||||
|
.RB [ \-p ]
|
||||||
.RB [ \-v ]
|
.RB [ \-v ]
|
||||||
.RB [ \-c
|
.RB [ \-c
|
||||||
.IR cfgfile ]
|
.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
|
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.
|
or to syslog, but the log messages are printed to stderr all the time.
|
||||||
.TP
|
.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
|
.B \-v
|
||||||
Increase verbosity. If given multiple times, more information is logged.
|
Increase verbosity. If given multiple times, more information is logged.
|
||||||
This is in addition to the verbosity (if any) from the config file.
|
This is in addition to the verbosity (if any) from the config file.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue