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

Function kern_setenv

freebsd/kern/kern_environment.c:548–592  ·  view source on GitHub ↗

* Set an environment variable by name. */

Source from the content-addressed store, hash-verified

546 * Set an environment variable by name.
547 */
548int
549kern_setenv(const char *name, const char *value)
550{
551 char *buf, *cp, *oldenv;
552 int namelen, vallen, i;
553
554 if (!dynamic_kenv && md_env_len > 0)
555 return (setenv_static(name, value));
556
557 KENV_CHECK;
558
559 namelen = strlen(name) + 1;
560 if (namelen > KENV_MNAMELEN + 1)
561 return (-1);
562 vallen = strlen(value) + 1;
563 if (vallen > kenv_mvallen + 1)
564 return (-1);
565 buf = malloc(namelen + vallen, M_KENV, M_WAITOK);
566 sprintf(buf, "%s=%s", name, value);
567
568 mtx_lock(&kenv_lock);
569 cp = _getenv_dynamic(name, &i);
570 if (cp != NULL) {
571 oldenv = kenvp[i];
572 kenvp[i] = buf;
573 mtx_unlock(&kenv_lock);
574 free(oldenv, M_KENV);
575 } else {
576 /* We add the option if it wasn't found */
577 for (i = 0; (cp = kenvp[i]) != NULL; i++)
578 ;
579
580 /* Bounds checking */
581 if (i < 0 || i >= KENV_SIZE) {
582 free(buf, M_KENV);
583 mtx_unlock(&kenv_lock);
584 return (-1);
585 }
586
587 kenvp[i] = buf;
588 kenvp[i + 1] = NULL;
589 mtx_unlock(&kenv_lock);
590 }
591 return (0);
592}
593
594/*
595 * Unset an environment variable string.

Callers 11

static_hints_to_envFunction · 0.70
sys_kenvFunction · 0.70
jz4780_efuse_update_kenvFunction · 0.50
platform_startFunction · 0.50
platform_startFunction · 0.50
octeon_init_kenvFunction · 0.50
platform_startFunction · 0.50
xlp_bootargs_initFunction · 0.50
xen_pvh_set_envFunction · 0.50

Calls 7

setenv_staticFunction · 0.85
mallocFunction · 0.85
sprintfFunction · 0.85
mtx_lockFunction · 0.70
_getenv_dynamicFunction · 0.70
mtx_unlockFunction · 0.70
freeFunction · 0.70

Tested by

no test coverage detected