Make getenv_*() functions and respectively TUNABLE_*_FETCH() macros not
allocate memory and so not require sleepable environment. getenv() has already used on-stack temporary storage, so just use it more rationally. getenv_string() receives buffer as argument, so don't need another one.
This commit is contained in:
parent
586904c22e
commit
915f2b7c89
@ -315,20 +315,12 @@ char *
|
|||||||
getenv(const char *name)
|
getenv(const char *name)
|
||||||
{
|
{
|
||||||
char buf[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
|
char buf[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
|
||||||
char *ret, *cp;
|
char *ret;
|
||||||
int len;
|
|
||||||
|
|
||||||
if (dynamic_kenv) {
|
if (dynamic_kenv) {
|
||||||
mtx_lock(&kenv_lock);
|
if (getenv_string(name, buf, sizeof(buf))) {
|
||||||
cp = _getenv_dynamic(name, NULL);
|
ret = strdup(buf, M_KENV);
|
||||||
if (cp != NULL) {
|
|
||||||
strcpy(buf, cp);
|
|
||||||
mtx_unlock(&kenv_lock);
|
|
||||||
len = strlen(buf) + 1;
|
|
||||||
ret = malloc(len, M_KENV, M_WAITOK);
|
|
||||||
strcpy(ret, buf);
|
|
||||||
} else {
|
} else {
|
||||||
mtx_unlock(&kenv_lock);
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
|
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
|
||||||
"getenv");
|
"getenv");
|
||||||
@ -458,15 +450,20 @@ unsetenv(const char *name)
|
|||||||
int
|
int
|
||||||
getenv_string(const char *name, char *data, int size)
|
getenv_string(const char *name, char *data, int size)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *cp;
|
||||||
|
|
||||||
tmp = getenv(name);
|
if (dynamic_kenv) {
|
||||||
if (tmp != NULL) {
|
mtx_lock(&kenv_lock);
|
||||||
strlcpy(data, tmp, size);
|
cp = _getenv_dynamic(name, NULL);
|
||||||
freeenv(tmp);
|
if (cp != NULL)
|
||||||
return (1);
|
strlcpy(data, cp, size);
|
||||||
} else
|
mtx_unlock(&kenv_lock);
|
||||||
return (0);
|
} else {
|
||||||
|
cp = _getenv_static(name);
|
||||||
|
if (cp != NULL)
|
||||||
|
strlcpy(data, cp, size);
|
||||||
|
}
|
||||||
|
return (cp != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -535,18 +532,15 @@ getenv_ulong(const char *name, unsigned long *data)
|
|||||||
int
|
int
|
||||||
getenv_quad(const char *name, quad_t *data)
|
getenv_quad(const char *name, quad_t *data)
|
||||||
{
|
{
|
||||||
char *value;
|
char value[KENV_MNAMELEN + 1 + KENV_MVALLEN + 1];
|
||||||
char *vtp;
|
char *vtp;
|
||||||
quad_t iv;
|
quad_t iv;
|
||||||
|
|
||||||
value = getenv(name);
|
if (!getenv_string(name, value, sizeof(value)))
|
||||||
if (value == NULL)
|
|
||||||
return (0);
|
return (0);
|
||||||
iv = strtoq(value, &vtp, 0);
|
iv = strtoq(value, &vtp, 0);
|
||||||
if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
|
if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0'))
|
||||||
freeenv(value);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
|
||||||
switch (vtp[0]) {
|
switch (vtp[0]) {
|
||||||
case 't': case 'T':
|
case 't': case 'T':
|
||||||
iv *= 1024;
|
iv *= 1024;
|
||||||
@ -559,11 +553,9 @@ getenv_quad(const char *name, quad_t *data)
|
|||||||
case '\0':
|
case '\0':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
freeenv(value);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
*data = iv;
|
*data = iv;
|
||||||
freeenv(value);
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user