mirror of
https://github.com/NLnetLabs/unbound.git
synced 2024-09-21 14:47:09 +00:00
daemonize by default. -d to debugmode.
git-svn-id: file:///svn/unbound/trunk@141 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
a92f1cf9ac
commit
f0a6f5130f
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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':
|
||||
|
BIN
testdata/fwd_tcp.tpkg
vendored
BIN
testdata/fwd_tcp.tpkg
vendored
Binary file not shown.
BIN
testdata/fwd_udp.tpkg
vendored
BIN
testdata/fwd_udp.tpkg
vendored
Binary file not shown.
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user