svn commit: r246780 - head/usr.sbin/nfsd

Xin LI delphij at FreeBSD.org
Thu Feb 14 01:25:15 UTC 2013


Author: delphij
Date: Thu Feb 14 01:25:14 2013
New Revision: 246780
URL: http://svnweb.freebsd.org/changeset/base/246780

Log:
  Abstract out setting of nfsdcnt and consistently use MAXNFSDCNT when the
  proposed value is too high and DEFNFSDCNT when proposed value is too low.
  
  MFC after:	2 weeks

Modified:
  head/usr.sbin/nfsd/nfsd.c

Modified: head/usr.sbin/nfsd/nfsd.c
==============================================================================
--- head/usr.sbin/nfsd/nfsd.c	Thu Feb 14 01:20:26 2013	(r246779)
+++ head/usr.sbin/nfsd/nfsd.c	Thu Feb 14 01:25:14 2013	(r246780)
@@ -119,6 +119,7 @@ static void	usage(void);
 static void	open_stable(int *, int *);
 static void	copy_stable(int, int);
 static void	backup_stable(int);
+static void	set_nfsdcnt(int);
 
 /*
  * Nfs server daemon mostly just a user context for nfssvc()
@@ -178,8 +179,7 @@ main(int argc, char **argv)
 			bindanyflag = 1;
 			break;
 		case 'n':
-			nfsdcnt_set = 1;
-			nfsdcnt = atoi(optarg);
+			set_nfsdcnt(atoi(optarg));
 			break;
 		case 'h':
 			bindhostc++;
@@ -235,15 +235,8 @@ main(int argc, char **argv)
 	 */
 	if (argc > 1)
 		usage();
-	if (argc == 1) {
-		nfsdcnt_set = 1;
-		nfsdcnt = atoi(argv[0]);
-		if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
-			warnx("nfsd count %d; reset to %d", nfsdcnt,
-			    DEFNFSDCNT);
-			nfsdcnt = DEFNFSDCNT;
-		}
-	}
+	if (argc == 1)
+		set_nfsdcnt(atoi(argv[0]));
 
 	/*
 	 * Unless the "-o" option was specified, try and run "nfsd".
@@ -429,16 +422,6 @@ main(int argc, char **argv)
 	}
 
 	if (!new_syscall) {
-		if (nfsdcnt < 1) {
-			warnx("nfsd count too low %d; reset to %d", nfsdcnt,
-			    DEFNFSDCNT);
-			nfsdcnt = DEFNFSDCNT;
-		}
-		if (nfsdcnt > MAXNFSDCNT) {
-			warnx("nfsd count too high %d; reset to %d", nfsdcnt,
-			    DEFNFSDCNT);
-			nfsdcnt = MAXNFSDCNT;
-		}
 		/* If we use UDP only, we start the last server below. */
 		srvcnt = tcpflag ? nfsdcnt : nfsdcnt - 1;
 		for (i = 0; i < srvcnt; i++) {
@@ -891,6 +874,23 @@ setbindhost(struct addrinfo **ai, const 
 }
 
 static void
+set_nfsdcnt(int proposed)
+{
+
+	if (proposed < 1) {
+		warnx("nfsd count too low %d; reset to %d", proposed,
+		    DEFNFSDCNT);
+		nfsdcnt = DEFNFSDCNT;
+	} else if (proposed > MAXNFSDCNT) {
+		warnx("nfsd count too high %d; truncated to %d", proposed,
+		    MAXNFSDCNT);
+		nfsdcnt = MAXNFSDCNT;
+	} else
+		nfsdcnt = proposed;
+	nfsdcnt_set = 1;
+}
+
+static void
 usage(void)
 {
 	(void)fprintf(stderr, "%s", getopt_usage);


More information about the svn-src-head mailing list