Paul Wouters
2013-Apr-18 21:01 UTC
[nsd-users] PATCH: option to allow nofork without enabling debug mode
Hi, I'm looking at running nsd from systemd without forking. The man page for nsd states: -d Turn on debugging mode, do not fork, stay in the foreground. Now I don't really want "debugging mode", I just want it to not fork. Attached is a small patch that adds the -D option that does not change the debugging level, but will prevent nsd from forking when specified. This allows systemd to restart nsd when it crashes. Paul -------------- next part -------------- diff -Naur nsd-3.2.15-orig/nsd.8.in nsd-3.2.15/nsd.8.in --- nsd-3.2.15-orig/nsd.8.in 2013-02-04 05:22:20.000000000 -0500 +++ nsd-3.2.15/nsd.8.in 2013-04-18 16:58:17.504031512 -0400 @@ -114,6 +114,9 @@ .B \-d Turn on debugging mode, do not fork, stay in the foreground. .TP +.B \-D +Do not fork, stay in the foreground, but don't turn on debugging mode +.TP .B \-f\fI database Use the specified .I database diff -Naur nsd-3.2.15-orig/nsd.c nsd-3.2.15/nsd.c --- nsd-3.2.15-orig/nsd.c 2013-01-09 05:32:50.000000000 -0500 +++ nsd-3.2.15/nsd.c 2013-04-18 16:57:23.384332746 -0400 @@ -68,6 +68,7 @@ " May be specified multiple times).\n" " -c configfile Read specified configfile instead of %s.\n" " -d Enable debug mode (do not fork as a daemon process).\n" + " -D Do not fork as a daemon process (but don't enable debug mode.\n" #ifndef NDEBUG " -F facilities Specify the debug facilities.\n" #endif /* NDEBUG */ @@ -557,6 +558,9 @@ case 'd': nsd.debug = 1; break; + case 'D': + nsd.nofork = 1; + break; case 'f': nsd.dbfile = optarg; break; @@ -982,7 +986,7 @@ } /* Unless we're debugging, fork... */ - if (!nsd.debug) { + if (!nsd.debug && !nsd.nofork) { int fd; /* Take off... */ diff -Naur nsd-3.2.15-orig/nsd.h nsd-3.2.15/nsd.h --- nsd-3.2.15-orig/nsd.h 2012-12-03 09:48:04.000000000 -0500 +++ nsd-3.2.15/nsd.h 2013-04-18 16:56:45.230840194 -0400 @@ -158,6 +158,7 @@ unsigned server_kind; struct namedb *db; int debug; + int nofork; size_t child_count; struct nsd_child *children;
Anand Buddhdev
2013-Apr-18 21:19 UTC
[nsd-users] PATCH: option to allow nofork without enabling debug mode
On 18/04/2013 23:01, Paul Wouters wrote:> Hi, > > I'm looking at running nsd from systemd without forking. The man page > for nsd states: > > -d Turn on debugging mode, do not fork, stay in the foreground. > > Now I don't really want "debugging mode", I just want it to not fork. > > Attached is a small patch that adds the -D option that does not change > the debugging level, but will prevent nsd from forking when specified. > > This allows systemd to restart nsd when it crashes.Hey Paul, Have you tested nsd long enough with this option? I'm not certain it will work. It will appear to work in the beginning, but when nsd does zone transfers, it will fork a child, which will load the zone database, and then kill its parents. At this point, systemd may not be able to keep track of nsd. At least, this was what I experienced when trying to make nsd3 work under Redhat's upstart. Changing this is more work than a simple patch, and Wouter has already done this for the upcoming nsd 4, which runs just fine under upstart. But it may never make it into nsd 3. Please do correct me if I got it wrong. Regards, Anand