portmap(8) and mountd(8) both accept an argument 'd' in order to
prevent them from detaching from the controlling terminal. This
allows them e.g. to be run from daemontools-like startup procedures.

The following patch adds the same functionality to nfsd(8).

Index: sbin/nfsd/nfsd.8
===================================================================
RCS file: /cvs/src/sbin/nfsd/nfsd.8,v
retrieving revision 1.18
diff -u -r1.18 nfsd.8
--- sbin/nfsd/nfsd.8    12 Jul 2014 17:38:19 -0000      1.18
+++ sbin/nfsd/nfsd.8    5 May 2015 06:51:51 -0000
@@ -40,7 +40,7 @@
 server
 .Sh SYNOPSIS
 .Nm nfsd
-.Op Fl rtu
+.Op Fl drtu
 .Op Fl n Ar num_servers
 .Sh DESCRIPTION
 .Nm
@@ -57,6 +57,11 @@
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl d
+Enable debugging mode.
+.Nm
+will not detach from the controlling terminal and will print
+debugging messages to stderr.
 .It Fl n Ar num_servers
 Specifies how many servers to create (max 20).
 .It Fl r
Index: sbin/nfsd/nfsd.c
===================================================================
RCS file: /cvs/src/sbin/nfsd/nfsd.c,v
retrieving revision 1.35
diff -u -r1.35 nfsd.c
--- sbin/nfsd/nfsd.c    16 Jan 2015 06:40:00 -0000      1.35
+++ sbin/nfsd/nfsd.c    5 May 2015 06:51:51 -0000
@@ -112,8 +112,11 @@
 
        if (argc == 1)
                udpflag = 1;
-       while ((ch = getopt(argc, argv, "n:rtu")) != -1)
+       while ((ch = getopt(argc, argv, "dn:rtu")) != -1)
                switch (ch) {
+               case 'd':
+                       debug = 1;
+                       break;
                case 'n':
                        nfsdcnt = strtonum(optarg, 1, MAXNFSDCNT, &errstr);
                        if (errstr) {
@@ -175,9 +178,11 @@
                return (0);
        }
 
-       /* Cut back to writing to log only. */
-       closelog();
-       openlog("nfsd", LOG_PID, LOG_DAEMON);
+       if (debug == 0) {
+               /* Cut back to writing to log only. */
+               closelog();
+               openlog("nfsd", LOG_PID, LOG_DAEMON);
+       }
 
        for (i = 0; i < nfsdcnt; i++) {
                switch (fork()) {

Reply via email to