[nsd-users] PATCH: option to allow nofork without enabling debug mode

Paul Wouters paul at nohats.ca
Thu Apr 18 21:01:30 UTC 2013


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;


More information about the nsd-users mailing list