Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Mar 2012 15:09:41 +0000 (UTC)
From:      Jamie Gritton <jamie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r232342 - head/lib/libjail
Message-ID:  <201203011509.q21F9f2p084204@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jamie
Date: Thu Mar  1 15:09:41 2012
New Revision: 232342
URL: http://svn.freebsd.org/changeset/base/232342

Log:
  Handle the case where a boolean parameter is also a node.
  
  PR:		bin/165515
  MFC after:	2 weeks

Modified:
  head/lib/libjail/jail.c

Modified: head/lib/libjail/jail.c
==============================================================================
--- head/lib/libjail/jail.c	Thu Mar  1 15:08:58 2012	(r232341)
+++ head/lib/libjail/jail.c	Thu Mar  1 15:09:41 2012	(r232342)
@@ -885,36 +885,20 @@ jailparam_type(struct jailparam *jp)
 		 * the "no" counterpart to a boolean.
 		 */
 		nname = nononame(jp->jp_name);
-		if (nname != NULL) {
-			snprintf(desc.s, sizeof(desc.s), SJPARAM ".%s", nname);
-			free(nname);
-			miblen = sizeof(mib) - 2 * sizeof(int);
-			if (sysctl(mib, 2, mib + 2, &miblen, desc.s,
-			    strlen(desc.s)) >= 0) {
-				mib[1] = 4;
-				desclen = sizeof(desc);
-				if (sysctl(mib, (miblen / sizeof(int)) + 2,
-				    &desc, &desclen, NULL, 0) < 0) {
-					snprintf(jail_errmsg,
-					    JAIL_ERRMSGLEN,
-					    "sysctl(0.4.%s): %s", desc.s,
-					    strerror(errno));
-					return (-1);
-				}
-				if ((desc.i & CTLTYPE) == CTLTYPE_INT &&
-				    desc.s[0] == 'B') {
-					jp->jp_ctltype = desc.i;
-					jp->jp_flags |= JP_NOBOOL;
-					jp->jp_valuelen = sizeof(int);
-					return (0);
-				}
-			}
+		if (nname == NULL) {
+		unknown_parameter:
+			snprintf(jail_errmsg, JAIL_ERRMSGLEN,
+			    "unknown parameter: %s", jp->jp_name);
+			errno = ENOENT;
+			return (-1);
 		}
-	unknown_parameter:
-		snprintf(jail_errmsg, JAIL_ERRMSGLEN,
-		    "unknown parameter: %s", jp->jp_name);
-		errno = ENOENT;
-		return (-1);
+		snprintf(desc.s, sizeof(desc.s), SJPARAM ".%s", nname);
+		free(nname);
+		miblen = sizeof(mib) - 2 * sizeof(int);
+		if (sysctl(mib, 2, mib + 2, &miblen, desc.s,
+		    strlen(desc.s)) < 0)
+			goto unknown_parameter;
+		jp->jp_flags |= JP_NOBOOL;
 	}
  mib_desc:
 	mib[1] = 4;
@@ -925,6 +909,16 @@ jailparam_type(struct jailparam *jp)
 		    "sysctl(0.4.%s): %s", jp->jp_name, strerror(errno));
 		return (-1);
 	}
+	jp->jp_ctltype = desc.i;
+	/* If this came from removing a "no", it better be a boolean. */
+	if (jp->jp_flags & JP_NOBOOL) {
+		if ((desc.i & CTLTYPE) == CTLTYPE_INT && desc.s[0] == 'B') {
+			jp->jp_valuelen = sizeof(int);
+			return (0);
+		}
+		else if ((desc.i & CTLTYPE) != CTLTYPE_NODE)
+			goto unknown_parameter;
+	}
 	/* See if this is an array type. */
 	p = strchr(desc.s, '\0');
 	isarray  = 0;
@@ -935,7 +929,6 @@ jailparam_type(struct jailparam *jp)
 		p[-2] = 0;
 	}
 	/* Look for types we understand. */
-	jp->jp_ctltype = desc.i;
 	switch (desc.i & CTLTYPE) {
 	case CTLTYPE_INT:
 		if (desc.s[0] == 'B')



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203011509.q21F9f2p084204>