KENV(2)
πΈ NAME πΈ
kenv β kernel environment. yep bestie, this is the KENV(2) page from the System Calls Manual, and we're about to vibe-check kernel env vars together π
π LIBRARY π
Standard C Library (libc, -lc) β iconic, obviously.
π§ SYNOPSIS π§
#include <kenv.h>
int
kenv(int action, const char *name, char *value, int len);
β¨ DESCRIPTION β¨
okay so the kenv() system call manipulates kernel environment variables. It supports the well known userland actions of getting, setting and unsetting environment variables, plus the ability to dump all of the entries in the kernel environment. main character energy fr fr π
The action argument can be one of the following:
KENV_GETβ get the value of the variable with the givenname. the size of thevaluebuffer is given bylen, which should be at leastKENV_MVALLEN + 1bytes to avoid truncation and to ensure NUL termination. no cut-off queen behavior allowed πKENV_SETβ set or add a variable.nameandvalueare limited toKENV_MNAMELENandKENV_MVALLENcharacters, respectively (not including the NUL terminator.) thelenargument indicates the length of thevalueand must include the NUL terminator. this option is only available to the superuser πKENV_UNSETβ unset the variable with the givenname. thevalueandlenarguments are ignored. this option is only available to the superuser πKENV_DUMPβ dump as much of the dynamic kernel environment as will fit invalue, whose size is given inlen. ifvalueisNULL,kenv()will return the number of bytes required to copy out the entire environment. thenameis ignored. it's giving "how much room do I need?" πKENV_DUMP_LOADERβ dump the static environment provided byloader(8), with semantics identical toKENV_DUMP. duplicate and malformed variables originally present in this environment are discarded by the kernel and will not appear in the output. byeee messy entries πKENV_DUMP_STATICβ dump the static environment defined by the kernelconfig(5). the semantics are identical toKENV_DUMP_LOADER.
π«Ά RETURN VALUES π«Ά
The kenv() system call returns 0 if successful in the case of KENV_SET and KENV_UNSET, and the number of bytes copied into value in the case of KENV_DUMP and KENV_GET. if an error occurs, a value of -1 is returned and the global variable errno is set to indicate the error. good vibes only when it's 0, bestie π
π ERRORS π
The kenv() system call will fail if:
[EINVAL]β theactionargument is not a valid option, or the length of thevalueis less than1for aKENV_SET.[ENOENT]β no value could be found fornamefor aKENV_GETorKENV_UNSET.[ENOENT]β the requested environment is not available for aKENV_DUMP_LOADERorKENV_DUMP_STATIC. the kernel is configured to destroy these environments by default. yikes but that's the default π[EPERM]β a user other than the superuser attempted to set or unset a kernel environment variable.[EFAULT]β a bad address was encountered while attempting to copy in user arguments or copy outvalue(s).[ENAMETOOLONG]β thenameor thevalueis longer thanKENV_MNAMELENorKENV_MVALLENcharacters, respectively, orlendid not include the NUL terminator for aKENV_SET.
π SEE ALSO π
kenv(1) β go read that too, bestie π«Ά
π AUTHORS π
This manual page was written by Chad David <davidc@FreeBSD.org>.
The kenv() system call was written by Maxime Henrion <mux@FreeBSD.org>.
mwah π this page is from Debian, dated June 20, 2021 β and yes bestie, it's the KENV(2) page. go forth and dump those env vars responsibly π«Άπ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (C) 2002 Chad David <davidc@FreeBSD.org>. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms