kern_environment.c (107850) | kern_environment.c (109623) |
---|---|
1/*- 2 * Copyright (c) 1998 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/kern_environment.c 107850 2002-12-14 02:07:32Z alfred $ | 26 * $FreeBSD: head/sys/kern/kern_environment.c 109623 2003-01-21 08:56:16Z alfred $ |
27 */ 28 29/* 30 * The unified bootloader passes us a pointer to a preserved copy of 31 * bootstrap/kernel environment variables. We convert them to a 32 * dynamic array of strings later when the VM subsystem is up. 33 * 34 * We make these available through the kenv(2) syscall for userland --- 91 unchanged lines hidden (view full) --- 126 127 if ((uap->what == KENV_SET) || 128 (uap->what == KENV_UNSET)) { 129 error = suser(td); 130 if (error) 131 return (error); 132 } 133 | 27 */ 28 29/* 30 * The unified bootloader passes us a pointer to a preserved copy of 31 * bootstrap/kernel environment variables. We convert them to a 32 * dynamic array of strings later when the VM subsystem is up. 33 * 34 * We make these available through the kenv(2) syscall for userland --- 91 unchanged lines hidden (view full) --- 126 127 if ((uap->what == KENV_SET) || 128 (uap->what == KENV_UNSET)) { 129 error = suser(td); 130 if (error) 131 return (error); 132 } 133 |
134 name = malloc(KENV_MNAMELEN, M_TEMP, M_WAITOK); | 134 name = malloc(KENV_MNAMELEN, M_TEMP, 0); |
135 136 error = copyinstr(uap->name, name, KENV_MNAMELEN, NULL); 137 if (error) 138 goto done; 139 140 switch (uap->what) { 141 case KENV_GET: 142#ifdef MAC --- 18 unchanged lines hidden (view full) --- 161 case KENV_SET: 162 len = uap->len; 163 if (len < 1) { 164 error = EINVAL; 165 goto done; 166 } 167 if (len > KENV_MVALLEN) 168 len = KENV_MVALLEN; | 135 136 error = copyinstr(uap->name, name, KENV_MNAMELEN, NULL); 137 if (error) 138 goto done; 139 140 switch (uap->what) { 141 case KENV_GET: 142#ifdef MAC --- 18 unchanged lines hidden (view full) --- 161 case KENV_SET: 162 len = uap->len; 163 if (len < 1) { 164 error = EINVAL; 165 goto done; 166 } 167 if (len > KENV_MVALLEN) 168 len = KENV_MVALLEN; |
169 value = malloc(len, M_TEMP, M_WAITOK); | 169 value = malloc(len, M_TEMP, 0); |
170 error = copyinstr(uap->value, value, len, NULL); 171 if (error) { 172 free(value, M_TEMP); 173 goto done; 174 } 175#ifdef MAC 176 error = mac_check_kenv_set(td->td_ucred, name, value); 177 if (error == 0) --- 24 unchanged lines hidden (view full) --- 202 * Setup the dynamic kernel environment. 203 */ 204static void 205init_dynamic_kenv(void *data __unused) 206{ 207 char *cp; 208 int len, i; 209 | 170 error = copyinstr(uap->value, value, len, NULL); 171 if (error) { 172 free(value, M_TEMP); 173 goto done; 174 } 175#ifdef MAC 176 error = mac_check_kenv_set(td->td_ucred, name, value); 177 if (error == 0) --- 24 unchanged lines hidden (view full) --- 202 * Setup the dynamic kernel environment. 203 */ 204static void 205init_dynamic_kenv(void *data __unused) 206{ 207 char *cp; 208 int len, i; 209 |
210 kenvp = malloc(KENV_SIZE * sizeof(char *), M_KENV, M_WAITOK | M_ZERO); | 210 kenvp = malloc(KENV_SIZE * sizeof(char *), M_KENV, M_ZERO); |
211 i = 0; 212 for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) { 213 len = strlen(cp) + 1; | 211 i = 0; 212 for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) { 213 len = strlen(cp) + 1; |
214 kenvp[i] = malloc(len, M_KENV, M_WAITOK); | 214 kenvp[i] = malloc(len, M_KENV, 0); |
215 strcpy(kenvp[i++], cp); 216 } 217 kenvp[i] = NULL; 218 219 sx_init(&kenv_lock, "kernel environment"); 220 dynamic_kenv = 1; 221} 222SYSINIT(kenv, SI_SUB_KMEM, SI_ORDER_ANY, init_dynamic_kenv, NULL); --- 62 unchanged lines hidden (view full) --- 285 286 if (dynamic_kenv) { 287 sx_slock(&kenv_lock); 288 cp = _getenv_dynamic(name, NULL); 289 if (cp != NULL) { 290 strcpy(buf, cp); 291 sx_sunlock(&kenv_lock); 292 len = strlen(buf) + 1; | 215 strcpy(kenvp[i++], cp); 216 } 217 kenvp[i] = NULL; 218 219 sx_init(&kenv_lock, "kernel environment"); 220 dynamic_kenv = 1; 221} 222SYSINIT(kenv, SI_SUB_KMEM, SI_ORDER_ANY, init_dynamic_kenv, NULL); --- 62 unchanged lines hidden (view full) --- 285 286 if (dynamic_kenv) { 287 sx_slock(&kenv_lock); 288 cp = _getenv_dynamic(name, NULL); 289 if (cp != NULL) { 290 strcpy(buf, cp); 291 sx_sunlock(&kenv_lock); 292 len = strlen(buf) + 1; |
293 ret = malloc(len, M_KENV, M_WAITOK); | 293 ret = malloc(len, M_KENV, 0); |
294 strcpy(ret, buf); 295 } else { 296 sx_sunlock(&kenv_lock); 297 ret = NULL; 298 } 299 } else 300 ret = _getenv_static(name); 301 return (ret); --- 30 unchanged lines hidden (view full) --- 332 KENV_CHECK; 333 334 namelen = strlen(name) + 1; 335 if (namelen > KENV_MNAMELEN) 336 return (-1); 337 vallen = strlen(value) + 1; 338 if (vallen > KENV_MVALLEN) 339 return (-1); | 294 strcpy(ret, buf); 295 } else { 296 sx_sunlock(&kenv_lock); 297 ret = NULL; 298 } 299 } else 300 ret = _getenv_static(name); 301 return (ret); --- 30 unchanged lines hidden (view full) --- 332 KENV_CHECK; 333 334 namelen = strlen(name) + 1; 335 if (namelen > KENV_MNAMELEN) 336 return (-1); 337 vallen = strlen(value) + 1; 338 if (vallen > KENV_MVALLEN) 339 return (-1); |
340 buf = malloc(namelen + vallen, M_KENV, M_WAITOK); | 340 buf = malloc(namelen + vallen, M_KENV, 0); |
341 sprintf(buf, "%s=%s", name, value); 342 343 sx_xlock(&kenv_lock); 344 cp = _getenv_dynamic(name, &i); 345 if (cp != NULL) { 346 oldenv = kenvp[i]; 347 kenvp[i] = buf; 348 sx_xunlock(&kenv_lock); --- 134 unchanged lines hidden --- | 341 sprintf(buf, "%s=%s", name, value); 342 343 sx_xlock(&kenv_lock); 344 cp = _getenv_dynamic(name, &i); 345 if (cp != NULL) { 346 oldenv = kenvp[i]; 347 kenvp[i] = buf; 348 sx_xunlock(&kenv_lock); --- 134 unchanged lines hidden --- |