MCPcopy Create free account
hub / github.com/F-Stack/f-stack / init_dynamic_kenv_from

Function init_dynamic_kenv_from

freebsd/kern/kern_environment.c:320–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318}
319
320static void
321init_dynamic_kenv_from(char *init_env, int *curpos)
322{
323 char *cp, *cpnext, *eqpos, *found;
324 size_t len;
325 int i;
326
327 if (init_env && *init_env != '\0') {
328 found = NULL;
329 i = *curpos;
330 for (cp = init_env; cp != NULL; cp = cpnext) {
331 cpnext = kernenv_next(cp);
332 len = strlen(cp) + 1;
333 if (len > KENV_MNAMELEN + 1 + kenv_mvallen + 1) {
334 printf(
335 "WARNING: too long kenv string, ignoring %s\n",
336 cp);
337 goto sanitize;
338 }
339 eqpos = strchr(cp, '=');
340 if (eqpos == NULL) {
341 printf(
342 "WARNING: malformed static env value, ignoring %s\n",
343 cp);
344 goto sanitize;
345 }
346 *eqpos = 0;
347 /*
348 * De-dupe the environment as we go. We don't add the
349 * duplicated assignments because config(8) will flip
350 * the order of the static environment around to make
351 * kernel processing match the order of specification
352 * in the kernel config.
353 */
354 found = _getenv_dynamic_locked(cp, NULL);
355 *eqpos = '=';
356 if (found != NULL)
357 goto sanitize;
358 if (i > KENV_SIZE) {
359 printf(
360 "WARNING: too many kenv strings, ignoring %s\n",
361 cp);
362 goto sanitize;
363 }
364
365 kenvp[i] = malloc(len, M_KENV, M_WAITOK);
366 strcpy(kenvp[i++], cp);
367sanitize:
368 explicit_bzero(cp, len - 1);
369 }
370 *curpos = i;
371 }
372}
373
374/*
375 * Setup the dynamic kernel environment.

Callers 1

init_dynamic_kenvFunction · 0.85

Calls 6

strchrFunction · 0.85
mallocFunction · 0.85
explicit_bzeroFunction · 0.85
kernenv_nextFunction · 0.70
printfFunction · 0.70
_getenv_dynamic_lockedFunction · 0.70

Tested by

no test coverage detected