diff options
author | hselasky <hselasky@FreeBSD.org> | 2014-07-05 06:12:48 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2014-07-05 06:12:48 +0000 |
commit | 9d5fb7b715ceb5e7e19c99087401f47510e7b791 (patch) | |
tree | 8d00f9594db05ebb7156f832d61808e5ea0504c6 | |
parent | 28432b0ce5a74d0cf2e0dad9d0e76c3be10d5dc3 (diff) | |
download | FreeBSD-src-9d5fb7b715ceb5e7e19c99087401f47510e7b791.zip FreeBSD-src-9d5fb7b715ceb5e7e19c99087401f47510e7b791.tar.gz |
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.
-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 149b90e..44078b1 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, |