xref: /freebsd/lib/libsys/kenv.2 (revision 8269e7673cf033aba67dab8264fe719920c70f87)
1*8269e767SBrooks Davis.\"
2*8269e767SBrooks Davis.\" Copyright (C) 2002 Chad David <davidc@FreeBSD.org>. All rights reserved.
3*8269e767SBrooks Davis.\"
4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
6*8269e767SBrooks Davis.\" are met:
7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
8*8269e767SBrooks Davis.\"    notice(s), this list of conditions and the following disclaimer as
9*8269e767SBrooks Davis.\"    the first lines of this file unmodified other than the possible
10*8269e767SBrooks Davis.\"    addition of one or more copyright notices.
11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
12*8269e767SBrooks Davis.\"    notice(s), this list of conditions and the following disclaimer in the
13*8269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
14*8269e767SBrooks Davis.\"
15*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16*8269e767SBrooks Davis.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17*8269e767SBrooks Davis.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18*8269e767SBrooks Davis.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19*8269e767SBrooks Davis.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20*8269e767SBrooks Davis.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21*8269e767SBrooks Davis.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22*8269e767SBrooks Davis.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25*8269e767SBrooks Davis.\" DAMAGE.
26*8269e767SBrooks Davis.\"
27*8269e767SBrooks Davis.Dd June 20, 2021
28*8269e767SBrooks Davis.Dt KENV 2
29*8269e767SBrooks Davis.Os
30*8269e767SBrooks Davis.Sh NAME
31*8269e767SBrooks Davis.Nm kenv
32*8269e767SBrooks Davis.Nd kernel environment
33*8269e767SBrooks Davis.Sh LIBRARY
34*8269e767SBrooks Davis.Lb libc
35*8269e767SBrooks Davis.Sh SYNOPSIS
36*8269e767SBrooks Davis.In kenv.h
37*8269e767SBrooks Davis.Ft int
38*8269e767SBrooks Davis.Fn kenv "int action" "const char *name" "char *value" "int len"
39*8269e767SBrooks Davis.Sh DESCRIPTION
40*8269e767SBrooks DavisThe
41*8269e767SBrooks Davis.Fn kenv
42*8269e767SBrooks Davissystem call manipulates kernel environment variables.
43*8269e767SBrooks DavisIt supports the well known userland actions of getting, setting and unsetting
44*8269e767SBrooks Davisenvironment variables, as well as the ability to dump all of the entries in
45*8269e767SBrooks Davisthe kernel environment.
46*8269e767SBrooks Davis.Pp
47*8269e767SBrooks DavisThe
48*8269e767SBrooks Davis.Fa action
49*8269e767SBrooks Davisargument can be one of the following:
50*8269e767SBrooks Davis.Bl -tag -width ".Dv KENV_DUMP_LOADER"
51*8269e767SBrooks Davis.It Dv KENV_GET
52*8269e767SBrooks DavisGet the
53*8269e767SBrooks Davis.Fa value
54*8269e767SBrooks Davisof the variable with the given
55*8269e767SBrooks Davis.Fa name .
56*8269e767SBrooks DavisThe size of the
57*8269e767SBrooks Davis.Fa value
58*8269e767SBrooks Davisbuffer is given by
59*8269e767SBrooks Davis.Fa len ,
60*8269e767SBrooks Daviswhich should be at least
61*8269e767SBrooks Davis.Dv KENV_MVALLEN
62*8269e767SBrooks Davis+ 1 bytes to avoid truncation and to ensure NUL termination.
63*8269e767SBrooks Davis.It Dv KENV_SET
64*8269e767SBrooks DavisSet or add a variable.
65*8269e767SBrooks DavisThe
66*8269e767SBrooks Davis.Fa name
67*8269e767SBrooks Davisand
68*8269e767SBrooks Davis.Fa value
69*8269e767SBrooks Davisare limited to
70*8269e767SBrooks Davis.Dv KENV_MNAMELEN
71*8269e767SBrooks Davisand
72*8269e767SBrooks Davis.Dv KENV_MVALLEN
73*8269e767SBrooks Davischaracters, respectively
74*8269e767SBrooks Davis.Pq not including the NUL terminator.
75*8269e767SBrooks DavisThe
76*8269e767SBrooks Davis.Fa len
77*8269e767SBrooks Davisargument indicates the length of the
78*8269e767SBrooks Davis.Fa value
79*8269e767SBrooks Davisand must include the NUL terminator.
80*8269e767SBrooks DavisThis option is only available to the superuser.
81*8269e767SBrooks Davis.It Dv KENV_UNSET
82*8269e767SBrooks DavisUnset the variable with the given
83*8269e767SBrooks Davis.Fa name .
84*8269e767SBrooks DavisThe
85*8269e767SBrooks Davis.Fa value
86*8269e767SBrooks Davisand
87*8269e767SBrooks Davis.Fa len
88*8269e767SBrooks Davisarguments are ignored.
89*8269e767SBrooks DavisThis option is only available to the superuser.
90*8269e767SBrooks Davis.It Dv KENV_DUMP
91*8269e767SBrooks DavisDump as much of the dynamic kernel environment as will fit in
92*8269e767SBrooks Davis.Fa value ,
93*8269e767SBrooks Daviswhose size is given in
94*8269e767SBrooks Davis.Fa len .
95*8269e767SBrooks DavisIf
96*8269e767SBrooks Davis.Fa value
97*8269e767SBrooks Davisis
98*8269e767SBrooks Davis.Dv NULL ,
99*8269e767SBrooks Davis.Fn kenv
100*8269e767SBrooks Daviswill return the number of bytes required to copy out the entire environment.
101*8269e767SBrooks DavisThe
102*8269e767SBrooks Davis.Fa name
103*8269e767SBrooks Davisis ignored.
104*8269e767SBrooks Davis.It Dv KENV_DUMP_LOADER
105*8269e767SBrooks DavisDump the static environment provided by
106*8269e767SBrooks Davis.Xr loader 8 ,
107*8269e767SBrooks Daviswith semantics identical to
108*8269e767SBrooks Davis.Dv KENV_DUMP .
109*8269e767SBrooks DavisDuplicate and malformed variables originally present in this environment are
110*8269e767SBrooks Davisdiscarded by the kernel and will not appear in the output.
111*8269e767SBrooks Davis.It Dv KENV_DUMP_STATIC
112*8269e767SBrooks DavisDump the static environment defined by the kernel
113*8269e767SBrooks Davis.Xr config 5 .
114*8269e767SBrooks DavisThe semantics are identical to
115*8269e767SBrooks Davis.Dv KENV_DUMP_LOADER .
116*8269e767SBrooks Davis.El
117*8269e767SBrooks Davis.Sh RETURN VALUES
118*8269e767SBrooks DavisThe
119*8269e767SBrooks Davis.Fn kenv
120*8269e767SBrooks Davissystem call returns 0 if successful in the case of
121*8269e767SBrooks Davis.Dv KENV_SET
122*8269e767SBrooks Davisand
123*8269e767SBrooks Davis.Dv KENV_UNSET ,
124*8269e767SBrooks Davisand the number of bytes copied into
125*8269e767SBrooks Davis.Fa value
126*8269e767SBrooks Davisin the case of
127*8269e767SBrooks Davis.Dv KENV_DUMP
128*8269e767SBrooks Davisand
129*8269e767SBrooks Davis.Dv KENV_GET .
130*8269e767SBrooks DavisIf an error occurs, a value of \-1 is returned and
131*8269e767SBrooks Davisthe global variable
132*8269e767SBrooks Davis.Va errno
133*8269e767SBrooks Davisis set to indicate the error.
134*8269e767SBrooks Davis.Sh ERRORS
135*8269e767SBrooks DavisThe
136*8269e767SBrooks Davis.Fn kenv
137*8269e767SBrooks Davissystem call
138*8269e767SBrooks Daviswill fail if:
139*8269e767SBrooks Davis.Bl -tag -width Er
140*8269e767SBrooks Davis.It Bq Er EINVAL
141*8269e767SBrooks DavisThe
142*8269e767SBrooks Davis.Fa action
143*8269e767SBrooks Davisargument
144*8269e767SBrooks Davisis not a valid option, or the length of the
145*8269e767SBrooks Davis.Fa value
146*8269e767SBrooks Davisis less than 1 for a
147*8269e767SBrooks Davis.Dv KENV_SET .
148*8269e767SBrooks Davis.It Bq Er ENOENT
149*8269e767SBrooks DavisNo value could be found for
150*8269e767SBrooks Davis.Fa name
151*8269e767SBrooks Davisfor a
152*8269e767SBrooks Davis.Dv KENV_GET
153*8269e767SBrooks Davisor
154*8269e767SBrooks Davis.Dv KENV_UNSET .
155*8269e767SBrooks Davis.It Bq Er ENOENT
156*8269e767SBrooks DavisThe requested environment is not available for a
157*8269e767SBrooks Davis.Dv KENV_DUMP_LOADER
158*8269e767SBrooks Davisor
159*8269e767SBrooks Davis.Dv KENV_DUMP_STATIC .
160*8269e767SBrooks DavisThe kernel is configured to destroy these environments by default.
161*8269e767SBrooks Davis.It Bq Er EPERM
162*8269e767SBrooks DavisA user other than the superuser attempted to set or unset a kernel
163*8269e767SBrooks Davisenvironment variable.
164*8269e767SBrooks Davis.It Bq Er EFAULT
165*8269e767SBrooks DavisA bad address was encountered while attempting to copy in user arguments
166*8269e767SBrooks Davisor copy out value(s).
167*8269e767SBrooks Davis.It Bq Er ENAMETOOLONG
168*8269e767SBrooks DavisThe
169*8269e767SBrooks Davis.Fa name
170*8269e767SBrooks Davisor the
171*8269e767SBrooks Davis.Fa value
172*8269e767SBrooks Davisis longer than
173*8269e767SBrooks Davis.Dv KENV_MNAMELEN
174*8269e767SBrooks Davisor
175*8269e767SBrooks Davis.Dv KENV_MVALLEN
176*8269e767SBrooks Davischaracters, respectively, or
177*8269e767SBrooks Davis.Fa len
178*8269e767SBrooks Davisdid not include the NUL terminator for a
179*8269e767SBrooks Davis.Dv KENV_SET .
180*8269e767SBrooks Davis.El
181*8269e767SBrooks Davis.Sh SEE ALSO
182*8269e767SBrooks Davis.Xr kenv 1
183*8269e767SBrooks Davis.Sh AUTHORS
184*8269e767SBrooks Davis.An -nosplit
185*8269e767SBrooks DavisThis manual page was written by
186*8269e767SBrooks Davis.An Chad David Aq Mt davidc@FreeBSD.org .
187*8269e767SBrooks Davis.Pp
188*8269e767SBrooks DavisThe
189*8269e767SBrooks Davis.Fn kenv
190*8269e767SBrooks Davissystem call was written by
191*8269e767SBrooks Davis.An Maxime Henrion Aq Mt mux@FreeBSD.org .
192