FreeBSD kernel kern code
kern_environment.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/kenv.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/libkern.h>
#include <sys/limits.h>
#include <security/mac/mac_framework.h>
Include dependency graph for kern_environment.c:

Go to the source code of this file.

Macros

#define KENV_SIZE   512 /* Maximum number of environment strings */
 
#define KENV_CHECK
 

Functions

 __FBSDID ("$FreeBSD$")
 
static char * _getenv_dynamic_locked (const char *name, int *idx)
 
static char * _getenv_dynamic (const char *name, int *idx)
 
static char * kenv_acquire (const char *name)
 
static void kenv_release (const char *buf)
 
static MALLOC_DEFINE (M_KENV, "kenv", "kernel environment")
 
static char * kernenv_next (char *)
 
static int kenv_dump (struct thread *td, char **envp, int what, char *value, int len)
 
int sys_kenv (struct thread *td, struct kenv_args *uap)
 
void init_static_kenv (char *buf, size_t len)
 
static void init_dynamic_kenv_from (char *init_env, int *curpos)
 
static void init_dynamic_kenv (void *data __unused)
 
 SYSINIT (kenv, SI_SUB_KMEM+1, SI_ORDER_FIRST, init_dynamic_kenv, NULL)
 
void freeenv (char *env)
 
static char * _getenv_static_from (char *chkenv, const char *name)
 
static char * _getenv_static (const char *name)
 
char * kern_getenv (const char *name)
 
int testenv (const char *name)
 
static int setenv_static (const char *name, const char *value)
 
int kern_setenv (const char *name, const char *value)
 
int kern_unsetenv (const char *name)
 
int getenv_string (const char *name, char *data, int size)
 
int getenv_array (const char *name, void *pdata, int size, int *psize, int type_size, bool allow_signed)
 
int getenv_int (const char *name, int *data)
 
int getenv_uint (const char *name, unsigned int *data)
 
int getenv_int64 (const char *name, int64_t *data)
 
int getenv_uint64 (const char *name, uint64_t *data)
 
int getenv_long (const char *name, long *data)
 
int getenv_ulong (const char *name, unsigned long *data)
 
int getenv_quad (const char *name, quad_t *data)
 
int getenv_bool (const char *name, bool *data)
 
bool getenv_is_true (const char *name)
 
bool getenv_is_false (const char *name)
 
void tunable_int_init (void *data)
 
void tunable_long_init (void *data)
 
void tunable_ulong_init (void *data)
 
void tunable_int64_init (void *data)
 
void tunable_uint64_init (void *data)
 
void tunable_quad_init (void *data)
 
void tunable_bool_init (void *data)
 
void tunable_str_init (void *data)
 

Variables

static uma_zone_t kenv_zone
 
static int kenv_mvallen = KENV_MVALLEN
 
char * kern_envp
 
char * md_envp
 
static int md_env_len
 
static int md_env_pos
 
char ** kenvp
 
struct mtx kenv_lock
 
bool dynamic_kenv
 

Macro Definition Documentation

◆ KENV_CHECK

#define KENV_CHECK
Value:
if (!dynamic_kenv) \
panic("%s: called before SI_SUB_KMEM", __func__)
bool dynamic_kenv

Definition at line 92 of file kern_environment.c.

◆ KENV_SIZE

#define KENV_SIZE   512 /* Maximum number of environment strings */

Definition at line 68 of file kern_environment.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ _getenv_dynamic()

static char * _getenv_dynamic ( const char *  name,
int *  idx 
)
static

Definition at line 481 of file kern_environment.c.

References _getenv_dynamic_locked(), kenv_lock, and name.

Referenced by kenv_acquire(), kern_getenv(), kern_setenv(), and kern_unsetenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getenv_dynamic_locked()

static char * _getenv_dynamic_locked ( const char *  name,
int *  idx 
)
static

Definition at line 463 of file kern_environment.c.

References kenvp, and name.

Referenced by _getenv_dynamic(), and init_dynamic_kenv_from().

Here is the caller graph for this function:

◆ _getenv_static()

static char * _getenv_static ( const char *  name)
static

Definition at line 508 of file kern_environment.c.

References _getenv_static_from(), kern_envp, md_envp, and name.

Referenced by kenv_acquire(), and kern_getenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getenv_static_from()

static char * _getenv_static_from ( char *  chkenv,
const char *  name 
)
static

Definition at line 489 of file kern_environment.c.

References kernenv_next(), and name.

Referenced by _getenv_static().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeenv()

void freeenv ( char *  env)

Definition at line 450 of file kern_environment.c.

References dynamic_kenv, and kenv_zone.

Referenced by getenv_bool(), parse_dir_ask_printenv(), start_init(), sys_kenv(), sysctl_load_tunable_by_oid_locked(), and vfs_mountroot_conf0().

Here is the caller graph for this function:

◆ getenv_array()

int getenv_array ( const char *  name,
void *  pdata,
int  size,
int *  psize,
int  type_size,
bool  allow_signed 
)

Definition at line 719 of file kern_environment.c.

References buf, kenv_acquire(), kenv_release(), name, and value.

Referenced by sysctl_load_tunable_by_oid_locked().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getenv_bool()

int getenv_bool ( const char *  name,
bool *  data 
)

Definition at line 993 of file kern_environment.c.

References data, freeenv(), kern_getenv(), name, and printf().

Referenced by getenv_is_false(), and getenv_is_true().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getenv_int()

int getenv_int ( const char *  name,
int *  data 
)

Definition at line 858 of file kern_environment.c.

References data, getenv_quad(), and name.

Here is the call graph for this function:

◆ getenv_int64()

int getenv_int64 ( const char *  name,
int64_t *  data 
)

Definition at line 888 of file kern_environment.c.

References data, getenv_quad(), and name.

Here is the call graph for this function:

◆ getenv_is_false()

bool getenv_is_false ( const char *  name)

Definition at line 1038 of file kern_environment.c.

References getenv_bool(), and name.

Here is the call graph for this function:

◆ getenv_is_true()

bool getenv_is_true ( const char *  name)

Definition at line 1025 of file kern_environment.c.

References getenv_bool(), and name.

Referenced by init_static_kenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getenv_long()

int getenv_long ( const char *  name,
long *  data 
)

Definition at line 918 of file kern_environment.c.

References data, getenv_quad(), and name.

Here is the call graph for this function:

◆ getenv_quad()

int getenv_quad ( const char *  name,
quad_t *  data 
)

Definition at line 948 of file kern_environment.c.

References data, kenv_acquire(), kenv_release(), name, and value.

Referenced by getenv_int(), getenv_int64(), getenv_long(), getenv_uint(), getenv_uint64(), and getenv_ulong().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getenv_string()

int getenv_string ( const char *  name,
char *  data,
int  size 
)

Definition at line 701 of file kern_environment.c.

References data, kenv_acquire(), kenv_release(), and name.

Here is the call graph for this function:

◆ getenv_uint()

int getenv_uint ( const char *  name,
unsigned int *  data 
)

Definition at line 873 of file kern_environment.c.

References data, getenv_quad(), and name.

Here is the call graph for this function:

◆ getenv_uint64()

int getenv_uint64 ( const char *  name,
uint64_t *  data 
)

Definition at line 903 of file kern_environment.c.

References data, getenv_quad(), and name.

Here is the call graph for this function:

◆ getenv_ulong()

int getenv_ulong ( const char *  name,
unsigned long *  data 
)

Definition at line 933 of file kern_environment.c.

References data, getenv_quad(), and name.

Here is the call graph for this function:

◆ init_dynamic_kenv()

static void init_dynamic_kenv ( void *data  __unused)
static

Definition at line 425 of file kern_environment.c.

References dynamic_kenv, init_dynamic_kenv_from(), kenv_lock, kenv_mvallen, KENV_SIZE, kenv_zone, kenvp, kern_envp, malloc(), and md_envp.

Here is the call graph for this function:

◆ init_dynamic_kenv_from()

static void init_dynamic_kenv_from ( char *  init_env,
int *  curpos 
)
static

Definition at line 364 of file kern_environment.c.

References _getenv_dynamic_locked(), kenv_mvallen, KENV_SIZE, kenvp, kernenv_next(), malloc(), and printf().

Referenced by init_dynamic_kenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_static_kenv()

void init_static_kenv ( char *  buf,
size_t  len 
)

Definition at line 298 of file kern_environment.c.

References buf, dynamic_kenv, getenv_is_true(), kern_envp, md_env_len, md_env_pos, and md_envp.

Here is the call graph for this function:

◆ kenv_acquire()

static char * kenv_acquire ( const char *  name)
static

Definition at line 673 of file kern_environment.c.

References _getenv_dynamic(), _getenv_static(), dynamic_kenv, kenv_lock, name, and value.

Referenced by getenv_array(), getenv_quad(), getenv_string(), and testenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kenv_dump()

static int kenv_dump ( struct thread *  td,
char **  envp,
int  what,
char *  value,
int  len 
)
static

Definition at line 96 of file kern_environment.c.

References free(), kenv_lock, kenv_mvallen, KENV_SIZE, kernenv_next(), malloc(), and value.

Referenced by sys_kenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kenv_release()

static void kenv_release ( const char *  buf)
static

Definition at line 691 of file kern_environment.c.

References buf, dynamic_kenv, and kenv_lock.

Referenced by getenv_array(), getenv_quad(), getenv_string(), and testenv().

Here is the caller graph for this function:

◆ kern_getenv()

char * kern_getenv ( const char *  name)

Definition at line 528 of file kern_environment.c.

References _getenv_dynamic(), _getenv_static(), dynamic_kenv, kenv_lock, kenv_mvallen, kenv_zone, and name.

Referenced by getenv_bool(), parse_dir_ask_printenv(), start_init(), sys_kenv(), sysctl_load_tunable_by_oid_locked(), and vfs_mountroot_conf0().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_setenv()

int kern_setenv ( const char *  name,
const char *  value 
)

Definition at line 596 of file kern_environment.c.

References _getenv_dynamic(), buf, dynamic_kenv, free(), KENV_CHECK, kenv_lock, kenv_mvallen, KENV_SIZE, kenvp, malloc(), md_env_len, name, setenv_static(), sprintf(), and value.

Referenced by static_hints_to_env(), and sys_kenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kern_unsetenv()

int kern_unsetenv ( const char *  name)

Definition at line 645 of file kern_environment.c.

References _getenv_dynamic(), KENV_CHECK, kenv_lock, kenvp, name, and zfree().

Referenced by resource_unset_value(), start_init(), and sys_kenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ kernenv_next()

static char * kernenv_next ( char *  cp)
static

Definition at line 1052 of file kern_environment.c.

Referenced by _getenv_static_from(), init_dynamic_kenv_from(), and kenv_dump().

Here is the caller graph for this function:

◆ MALLOC_DEFINE()

static MALLOC_DEFINE ( M_KENV  ,
"kenv"  ,
"kernel environment"   
)
static

◆ setenv_static()

static int setenv_static ( const char *  name,
const char *  value 
)
static

Definition at line 573 of file kern_environment.c.

References md_env_len, md_env_pos, md_envp, name, sprintf(), and value.

Referenced by kern_setenv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sys_kenv()

int sys_kenv ( struct thread *  td,
struct kenv_args *  uap 
)

Definition at line 160 of file kern_environment.c.

References dynamic_kenv, free(), freeenv(), kenv_dump(), kenv_mvallen, kenvp, kern_envp, kern_getenv(), kern_setenv(), kern_unsetenv(), malloc(), md_envp, name, priv_check(), and value.

Here is the call graph for this function:

◆ SYSINIT()

SYSINIT ( kenv  ,
SI_SUB_KMEM+  1,
SI_ORDER_FIRST  ,
init_dynamic_kenv  ,
NULL   
)

◆ testenv()

int testenv ( const char *  name)

Definition at line 555 of file kern_environment.c.

References kenv_acquire(), kenv_release(), and name.

Referenced by static_hints_to_env().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tunable_bool_init()

void tunable_bool_init ( void *  data)

Definition at line 1114 of file kern_environment.c.

References data.

◆ tunable_int64_init()

void tunable_int64_init ( void *  data)

Definition at line 1090 of file kern_environment.c.

References data.

◆ tunable_int_init()

void tunable_int_init ( void *  data)

Definition at line 1066 of file kern_environment.c.

References data.

◆ tunable_long_init()

void tunable_long_init ( void *  data)

Definition at line 1074 of file kern_environment.c.

References data.

◆ tunable_quad_init()

void tunable_quad_init ( void *  data)

Definition at line 1106 of file kern_environment.c.

References data.

◆ tunable_str_init()

void tunable_str_init ( void *  data)

Definition at line 1122 of file kern_environment.c.

References data.

◆ tunable_uint64_init()

void tunable_uint64_init ( void *  data)

Definition at line 1098 of file kern_environment.c.

References data.

◆ tunable_ulong_init()

void tunable_ulong_init ( void *  data)

Definition at line 1082 of file kern_environment.c.

References data.

Variable Documentation

◆ dynamic_kenv

◆ kenv_lock

◆ kenv_mvallen

int kenv_mvallen = KENV_MVALLEN
static

◆ kenv_zone

uma_zone_t kenv_zone
static

Definition at line 70 of file kern_environment.c.

Referenced by freeenv(), init_dynamic_kenv(), and kern_getenv().

◆ kenvp

◆ kern_envp

char* kern_envp

◆ md_env_len

int md_env_len
static

Definition at line 78 of file kern_environment.c.

Referenced by init_static_kenv(), kern_setenv(), and setenv_static().

◆ md_env_pos

int md_env_pos
static

Definition at line 79 of file kern_environment.c.

Referenced by init_static_kenv(), and setenv_static().

◆ md_envp

char* md_envp