KENV(2)
π KENV(2) β kernel environment π
okay bestie, buckle up, because we're about to talk about kenv(2), the system call (not the userland tool, that's a whole different girlie, see SEE ALSO π). It lives in the System Calls Manual and it's literally the kernel's little environment-variable closet. slay.
πΈ LIBRARY πΈ
Standard C Library (libc, -lc). yeah, she's a libc girlie, no extra libraries needed, we love a low-maintenance queen π«Ά
β¨ SYNOPSIS β¨
#include <kenv.h>
int
kenv(int action, const char *name, char *value, int len);
π¦ DESCRIPTION π¦
so the kenv() system call manipulates kernel environment variables. it's giving "the userland actions you already know and love" β getting, setting and unsetting env vars β but make it kernel. and ALSO she can dump, like, every single entry in the kernel environment. main character energy fr fr π
the action argument can be one of these babes:
KENV_GETβ get the value of the variable with the given name. the size of the value buffer is given by len, and bestie, that len should be at leastKENV_MVALLEN + 1bytes so you avoid truncation and make sure it's NUL-terminated. don't skip the +1, i'm begging πKENV_SETβ set or add a variable. the name and value are limited toKENV_MNAMELENandKENV_MVALLENcharacters respectively (and no, the NUL terminator does not count toward that). the len argument tells you the length of the value and it must include the NUL terminator. and this one? superuser only, sorry not sorry πKENV_UNSETβ unset the variable with the given name. the value and len arguments are literally ignored, they don't matter, they're just there. also superuser only πKENV_DUMPβ dump as much of the kernel environment as will fit into value, whose size is given in len. and here's the cute part: if value isNULL,kenv()returns the number of bytes required to copy out the entire environment. so you can ask "how big should my buffer be, bestie?" first. name is ignored here, she's not needed.
π RETURN VALUES π
so here's the tea on what she gives back:
kenv()returns 0 if it was successful in the case ofKENV_SETandKENV_UNSETβ- it returns the number of bytes copied into value in the case of
KENV_DUMPandKENV_GETπ - and if an error happens? you get
-1and the global variableerrnogets set to tell you what went wrong. classic. π
π ERRORS π
the kenv() system call will fail if:
[EINVAL]β the action argument is not a valid option, OR the length of the value is less than 1 for aKENV_SET. (yeah, empty values? not the vibe.)[ENOENT]β no value could be found for name for aKENV_GETorKENV_UNSET. she looked. it's not there. π[EPERM]β a user other than the superuser tried to set or unset a kernel environment variable. bestie you are not the superuser, sit down π[EFAULT]β a bad address was encountered while attempting to copy in user arguments or copy out value(s). bad pointer, bad vibe.[ENAMETOOLONG]β the name or the value is longer thanKENV_MNAMELENorKENV_MVALLENcharacters respectively, OR len did not include the NUL terminator for aKENV_SET. too long, too iconic, rejected.
β SEE ALSO β
π AUTHORS π
- this manual page was written by Chad David
<davidc@FreeBSD.org>. iconic of him honestly. - the
kenv()system call was written by Maxime Henrion<mux@FreeBSD.org>. king behavior π
and that's the whole page, bestie π«Ά this cutie comes to you from Debian, dated February 20, 2017, and yes she's still serving. go forth and kenv() responsibly πβ¨π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (C) 2002 Chad David <davidc@FreeBSD.org>. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms