git: 7c2901b08b4e - main - mountd: Add options to disable daemon mode and setting localhost

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Thu, 11 Jul 2024 19:40:29 UTC
The branch main has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=7c2901b08b4e68c3fb0587003cf7e46335e24baa

commit 7c2901b08b4e68c3fb0587003cf7e46335e24baa
Author:     Joyu Liao <joyul@juniper.net>
AuthorDate: 2024-07-11 19:38:04 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2024-07-11 19:38:04 +0000

    mountd: Add options to disable daemon mode and setting localhost
    
    In our products, we need those options to support our features.
    
    Add daemon mode option for mountd, nfsd.
    Add skip local host binding option for rpcd.
    Add skip local host binding option for mountd.
    
    Reviewed by:    rmacklem
    Differential Revision:  https://reviews.freebsd.org/D45118
---
 usr.sbin/mountd/mountd.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c
index 14693a922186..00293909614e 100644
--- a/usr.sbin/mountd/mountd.c
+++ b/usr.sbin/mountd/mountd.c
@@ -287,6 +287,8 @@ static int *sock_fd;
 static int sock_fdcnt;
 static int sock_fdpos;
 static int suspend_nfsd = 0;
+static int nofork = 0;
+static int skiplocalhost = 0;
 
 static int opt_flags;
 static int have_v6 = 1;
@@ -436,7 +438,7 @@ main(int argc, char **argv)
 	else
 		close(s);
 
-	while ((c = getopt(argc, argv, "2Adeh:lnp:RrS")) != -1)
+	while ((c = getopt(argc, argv, "2Adeh:lNnp:RrSs")) != -1)
 		switch (c) {
 		case '2':
 			force_v2 = 1;
@@ -495,6 +497,12 @@ main(int argc, char **argv)
 		case 'S':
 			suspend_nfsd = 1;
 			break;
+		case 'N':
+			nofork = 1;
+			break;
+		case 's':
+			skiplocalhost = 1;
+			break;
 		default:
 			usage();
 		}
@@ -514,6 +522,9 @@ main(int argc, char **argv)
 		}
 	}
 
+	if (nhosts == 0 && skiplocalhost != 0)
+		warnx("-s without -h, ignored");
+
 	if (modfind("nfsd") < 0) {
 		/* Not present in kernel, try loading it */
 		if (kldload("nfsd") < 0 || modfind("nfsd") < 0)
@@ -535,7 +546,7 @@ main(int argc, char **argv)
 	get_mountlist();
 	if (debug)
 		warnx("here we go");
-	if (debug == 0) {
+	if (debug == 0 && nofork == 0) {
 		daemon(0, 0);
 		signal(SIGINT, SIG_IGN);
 		signal(SIGQUIT, SIG_IGN);
@@ -571,7 +582,7 @@ main(int argc, char **argv)
 				out_of_mem();
 			hosts[0] = "*";
 			nhosts = 1;
-		} else {
+		} else if (skiplocalhost == 0) {
 			hosts_bak = hosts;
 			if (have_v6) {
 				hosts_bak = realloc(hosts, (nhosts + 2) *
@@ -1111,8 +1122,8 @@ static void
 usage(void)
 {
 	fprintf(stderr,
-		"usage: mountd [-2] [-d] [-e] [-l] [-n] [-p <port>] [-r] "
-		"[-S] [-h <bindip>] [export_file ...]\n");
+	    "usage: mountd [-2] [-d] [-e] [-l] [-N] [-n] [-p <port>] [-r] [-S] "
+	    "[-s] [-h <bindip>] [export_file ...]\n");
 	exit(1);
 }