Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Jul 2014 06:12:49 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r268285 - head/sys/kern
Message-ID:  <201407050612.s656CnwY045496@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Sat Jul  5 06:12:48 2014
New Revision: 268285
URL: http://svnweb.freebsd.org/changeset/base/268285

Log:
  When getting the initial value of numeric tunables use the
  getenv_xxx() functions instead of strtoq(), because the getenv_xxx()
  functions include wrappers for various postfixes like G/M/K, which
  strtoq() doesn't do.

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==============================================================================
--- head/sys/kern/kern_sysctl.c	Sat Jul  5 05:44:26 2014	(r268284)
+++ head/sys/kern/kern_sysctl.c	Sat Jul  5 06:12:48 2014	(r268285)
@@ -167,13 +167,14 @@ sysctl_load_tunable_by_oid_locked(struct
 {
 	struct sysctl_req req;
 	struct sysctl_oid *curr;
-	char *penv;
+	char *penv = NULL;
 	char path[64];
 	ssize_t rem = sizeof(path);
 	ssize_t len;
 	int val_int;
 	long val_long;
 	int64_t val_64;
+	quad_t val_quad;
 	int error;
 
 	path[--rem] = 0;
@@ -192,10 +193,6 @@ sysctl_load_tunable_by_oid_locked(struct
 			path[rem + len] = '.';
 	}
 
-	penv = getenv(path + rem);
-	if (penv == NULL)
-		return;
-
 	memset(&req, 0, sizeof(req));
 
 	req.td = curthread;
@@ -205,41 +202,52 @@ sysctl_load_tunable_by_oid_locked(struct
 
 	switch (oidp->oid_kind & CTLTYPE) {
 	case CTLTYPE_INT:
-		val_int = strtoq(penv, NULL, 0);
+		if (getenv_int(path + rem, &val_int) == 0)
+			return;
 		req.newlen = sizeof(val_int);
 		req.newptr = &val_int;
 		break;
 	case CTLTYPE_UINT:
-		val_int = strtouq(penv, NULL, 0);
+		if (getenv_uint(path + rem, (unsigned int *)&val_int) == 0)
+			return;
 		req.newlen = sizeof(val_int);
 		req.newptr = &val_int;
 		break;
 	case CTLTYPE_LONG:
-		val_long = strtoq(penv, NULL, 0);
+		if (getenv_long(path + rem, &val_long) == 0)
+			return;
 		req.newlen = sizeof(val_long);
 		req.newptr = &val_long;
 		break;
 	case CTLTYPE_ULONG:
-		val_long = strtouq(penv, NULL, 0);
+		if (getenv_ulong(path + rem, (unsigned long *)&val_long) == 0)
+			return;
 		req.newlen = sizeof(val_long);
 		req.newptr = &val_long;
 		break;
 	case CTLTYPE_S64:
-		val_64 = strtoq(penv, NULL, 0);
+		if (getenv_quad(path + rem, &val_quad) == 0)
+			return;
+		val_64 = val_quad;
 		req.newlen = sizeof(val_64);
 		req.newptr = &val_64;
 		break;
 	case CTLTYPE_U64:
-		val_64 = strtouq(penv, NULL, 0);
+		/* XXX there is no getenv_uquad() */
+		if (getenv_quad(path + rem, &val_quad) == 0)
+			return;
+		val_64 = val_quad;
 		req.newlen = sizeof(val_64);
 		req.newptr = &val_64;
 		break;
 	case CTLTYPE_STRING:
+		penv = getenv(path + rem);
+		if (penv == NULL)
+			return;
 		req.newlen = strlen(penv);
 		req.newptr = penv;
 		break;
 	default:
-		freeenv(penv);
 		return;
 	}
 	error = sysctl_root_handler_locked(oidp, oidp->oid_arg1,



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