diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2014-07-05 06:12:48 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2014-07-05 06:12:48 +0000 |
commit | 604bf9d37ebab2628375d893fcaa1188bc04371c (patch) | |
tree | 8d00f9594db05ebb7156f832d61808e5ea0504c6 /sys/kern/kern_sysctl.c | |
parent | 92782c33a6982e197391e23239641f4c2f0298ae (diff) | |
download | src-604bf9d37ebab2628375d893fcaa1188bc04371c.tar.gz src-604bf9d37ebab2628375d893fcaa1188bc04371c.zip |
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.
Notes
Notes:
svn path=/head/; revision=268285
Diffstat (limited to 'sys/kern/kern_sysctl.c')
-rw-r--r-- | sys/kern/kern_sysctl.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 149b90e7431f..44078b1dff39 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -167,13 +167,14 @@ sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp) { 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 sysctl_oid *oidp) 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 sysctl_oid *oidp) 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, |