1e083a43cSThomas E. Spanjaard.\" 2e083a43cSThomas E. Spanjaard.\" Copyright (c) 2007 The DragonFly Project. All rights reserved. 3e083a43cSThomas E. Spanjaard.\" 4e083a43cSThomas E. Spanjaard.\" Redistribution and use in source and binary forms, with or without 5e083a43cSThomas E. Spanjaard.\" modification, are permitted provided that the following conditions 6e083a43cSThomas E. Spanjaard.\" are met: 7e083a43cSThomas E. Spanjaard.\" 8e083a43cSThomas E. Spanjaard.\" 1. Redistributions of source code must retain the above copyright 9e083a43cSThomas E. Spanjaard.\" notice, this list of conditions and the following disclaimer. 10e083a43cSThomas E. Spanjaard.\" 2. Redistributions in binary form must reproduce the above copyright 11e083a43cSThomas E. Spanjaard.\" notice, this list of conditions and the following disclaimer in 12e083a43cSThomas E. Spanjaard.\" the documentation and/or other materials provided with the 13e083a43cSThomas E. Spanjaard.\" distribution. 14e083a43cSThomas E. Spanjaard.\" 3. Neither the name of The DragonFly Project nor the names of its 15e083a43cSThomas E. Spanjaard.\" contributors may be used to endorse or promote products derived 16e083a43cSThomas E. Spanjaard.\" from this software without specific, prior written permission. 17e083a43cSThomas E. Spanjaard.\" 18e083a43cSThomas E. Spanjaard.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19e083a43cSThomas E. Spanjaard.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20e083a43cSThomas E. Spanjaard.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21e083a43cSThomas E. Spanjaard.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22e083a43cSThomas E. Spanjaard.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23e083a43cSThomas E. Spanjaard.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24e083a43cSThomas E. Spanjaard.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25e083a43cSThomas E. Spanjaard.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26e083a43cSThomas E. Spanjaard.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27e083a43cSThomas E. Spanjaard.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28e083a43cSThomas E. Spanjaard.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29e083a43cSThomas E. Spanjaard.\" SUCH DAMAGE. 30e083a43cSThomas E. Spanjaard.\" 31fbaa5e6cSSascha Wildner.Dd July 21, 2012 32e083a43cSThomas E. Spanjaard.Dt KENV 9 3306b20a23SThomas E. Spanjaard.Os 34e083a43cSThomas E. Spanjaard.Sh NAME 35e083a43cSThomas E. Spanjaard.Nm kfreeenv , 36e083a43cSThomas E. Spanjaard.Nm kgetenv , 37e083a43cSThomas E. Spanjaard.Nm kgetenv_int , 38e083a43cSThomas E. Spanjaard.Nm kgetenv_quad , 39e083a43cSThomas E. Spanjaard.Nm kgetenv_string , 407a923c67SSascha Wildner.Nm kgetenv_ulong , 41e083a43cSThomas E. Spanjaard.Nm ksetenv , 42e083a43cSThomas E. Spanjaard.Nm ktestenv , 4306b20a23SThomas E. Spanjaard.Nm kunsetenv 4406b20a23SThomas E. Spanjaard.Nd API for manipulation of the kernel environment 45e083a43cSThomas E. Spanjaard.Sh SYNOPSIS 46e083a43cSThomas E. Spanjaard.In sys/systm.h 47e083a43cSThomas E. Spanjaard.Ft void 48e083a43cSThomas E. Spanjaard.Fn kfreeenv "char *env" 49e083a43cSThomas E. Spanjaard.Ft char * 50e083a43cSThomas E. Spanjaard.Fn kgetenv "const char *name" 51e083a43cSThomas E. Spanjaard.Ft int 52e083a43cSThomas E. Spanjaard.Fn kgetenv_int "const char *name" "int *data" 53e083a43cSThomas E. Spanjaard.Ft int 54e083a43cSThomas E. Spanjaard.Fn kgetenv_quad "const char *name" "quad_t *data" 55e083a43cSThomas E. Spanjaard.Ft int 56e083a43cSThomas E. Spanjaard.Fn kgetenv_string "const char *name" "char *data" "int size" 57e083a43cSThomas E. Spanjaard.Ft int 587a923c67SSascha Wildner.Fn kgetenv_ulong "const char *name" "unsigned long *data" 597a923c67SSascha Wildner.Ft int 60e083a43cSThomas E. Spanjaard.Fn ksetenv "const char *name" "const char *value" 61e083a43cSThomas E. Spanjaard.Ft int 62e083a43cSThomas E. Spanjaard.Fn ktestenv "const char *name" 63e083a43cSThomas E. Spanjaard.Ft int 64e083a43cSThomas E. Spanjaard.Fn kunsetenv "const char *name" 65e083a43cSThomas E. Spanjaard.Sh DESCRIPTION 6650e92fdfSThomas E. Spanjaard.Nm kenv 6706b20a23SThomas E. Spanjaardprovides an API for manipulation of the kernel environment of a live system by 6806b20a23SThomas E. Spanjaard.Dq consumers 6906b20a23SThomas E. Spanjaard(other kernel subsystems). 70e083a43cSThomas E. SpanjaardUpon boot, the kernel environment is inherited from 71e083a43cSThomas E. Spanjaard.Xr loader 8 . 72e083a43cSThomas E. SpanjaardThe static environment inherited is converted to a dynamic array at the end of 73e083a43cSThomas E. Spanjaardthe 74e083a43cSThomas E. Spanjaard.Nm kmem 75e083a43cSThomas E. Spanjaardsubsystem configure phase of the kernel booting process. 76e083a43cSThomas E. Spanjaard.Pp 77e083a43cSThomas E. SpanjaardThe 78e083a43cSThomas E. Spanjaard.Fn kfreeenv 79e083a43cSThomas E. Spanjaardfunction reclaims an array of characters earlier allocated by one of the 80e083a43cSThomas E. Spanjaard.Fn kgetenv 81e083a43cSThomas E. Spanjaardfunctions for use by the caller. 82e083a43cSThomas E. Spanjaard.Pp 83e083a43cSThomas E. SpanjaardThe 84e083a43cSThomas E. Spanjaard.Fn kgetenv* 85e083a43cSThomas E. Spanjaardfunctions look up a given entry in the kernel environment, and return it if 86e083a43cSThomas E. Spanjaardfound. 87e083a43cSThomas E. SpanjaardThe 887a923c67SSascha Wildner.Fn kgetenv_int , 897a923c67SSascha Wildner.Fn kgetenv_quad , 907a923c67SSascha Wildner.Fn kgetenv_string , 917a923c67SSascha Wildnerand 927a923c67SSascha Wildner.Fn kgetenv_ulong 93e083a43cSThomas E. Spanjaardfunctions return 94e083a43cSThomas E. Spanjaard.Dv 0 95*a9ddd36cSSascha Wildnerif unsuccessful, 96*a9ddd36cSSascha Wildner.Dv 1 97*a9ddd36cSSascha Wildnerif successful, and return the found value in the given destination. 98e083a43cSThomas E. Spanjaard.Pp 99e083a43cSThomas E. SpanjaardThe 100e083a43cSThomas E. Spanjaard.Fn kgetenv 101e083a43cSThomas E. Spanjaardfunction returns the value string or 102e083a43cSThomas E. Spanjaard.Dv NULL 103e083a43cSThomas E. Spanjaardif it failed. 104e083a43cSThomas E. Spanjaard.Pp 105e083a43cSThomas E. SpanjaardThe 106e083a43cSThomas E. Spanjaard.Fn ksetenv 107e083a43cSThomas E. Spanjaardfunction sets a given environment key to the given value. It returns 108e083a43cSThomas E. Spanjaard.Dv -1 109e083a43cSThomas E. Spanjaardif either the 110e083a43cSThomas E. Spanjaard.Fa name 111e083a43cSThomas E. Spanjaardor 112e083a43cSThomas E. Spanjaard.Fa value 113e083a43cSThomas E. Spanjaardarguments were too large, the maxmimum number of entries in the dynamic 114e083a43cSThomas E. Spanjaardenvironment was reached, or if the dynamic environment was not setup yet. 115e083a43cSThomas E. SpanjaardThe latter can happen when calling 116e083a43cSThomas E. Spanjaard.Fn ksetenv 117e083a43cSThomas E. Spanjaardbefore the 118e083a43cSThomas E. Spanjaard.Nm kmem 119e083a43cSThomas E. Spanjaardsubsystem is initialized. 120e083a43cSThomas E. Spanjaard.Pp 121e083a43cSThomas E. SpanjaardThe 122e083a43cSThomas E. Spanjaard.Fn ktestenv 123e083a43cSThomas E. Spanjaardfunction tests whether a given key exists in the kernel environment, returning 124e083a43cSThomas E. Spanjaard.Dv 1 125e083a43cSThomas E. Spanjaardif it does and 126e083a43cSThomas E. Spanjaard.Dv 0 127e083a43cSThomas E. Spanjaardif it does not. 128e083a43cSThomas E. Spanjaard.Pp 129e083a43cSThomas E. SpanjaardThe 130e083a43cSThomas E. Spanjaard.Fn kunsetenv 131e083a43cSThomas E. Spanjaardfunction removes a given key and its associated value from the dynamic kernel 132e083a43cSThomas E. Spanjaardenvironment. 133e083a43cSThomas E. SpanjaardIt returns 134e083a43cSThomas E. Spanjaard.Dv -1 135e083a43cSThomas E. Spanjaardif the key does not exist, or if the dynamic was not setup yet. 136e083a43cSThomas E. SpanjaardIf successful, it returns 137e083a43cSThomas E. Spanjaard.Dv 0 . 13806b20a23SThomas E. Spanjaard.Sh SYSCTLS 13906b20a23SThomas E. Spanjaard.Bl -tag -width indent 14006b20a23SThomas E. Spanjaard.It Va kern.environment 14106b20a23SThomas E. SpanjaardCurrent static kernel environment query OID. 14206b20a23SThomas E. Spanjaard.El 14306b20a23SThomas E. Spanjaard.Sh FILES 14406b20a23SThomas E. Spanjaard.Bl -tag -width ".Pa sys/kern/kern_environment.c" 14506b20a23SThomas E. Spanjaard.It Pa sys/kern/kern_environment.c 14606b20a23SThomas E. Spanjaard.El 147e083a43cSThomas E. Spanjaard.Sh SEE ALSO 14806b20a23SThomas E. Spanjaard.Xr sysctl 3 , 149ab8a23cdSSascha Wildner.Xr loader.conf 5 , 150ab8a23cdSSascha Wildner.Xr loader 8 , 15106b20a23SThomas E. Spanjaard.Xr sysctl 8 152e083a43cSThomas E. Spanjaard.Sh HISTORY 153e083a43cSThomas E. SpanjaardA 154e083a43cSThomas E. Spanjaard.Fn getenv 155e083a43cSThomas E. Spanjaardfunction first appeared in 156e083a43cSThomas E. Spanjaard.Fx 3.0 , 157e083a43cSThomas E. Spanjaard.Fn getenv_int 158e083a43cSThomas E. Spanjaardin 159e083a43cSThomas E. Spanjaard.Fx 3.1 , 160e083a43cSThomas E. Spanjaard.Fn getenv_quad 161e083a43cSThomas E. Spanjaardin 162e083a43cSThomas E. Spanjaard.Fx 3.4 , 163e083a43cSThomas E. Spanjaard.Fn getenv_string 164e083a43cSThomas E. Spanjaardin 165e083a43cSThomas E. Spanjaard.Fx 4.5 166e083a43cSThomas E. Spanjaardand other functions first appeared in 167e083a43cSThomas E. Spanjaard.Fx 5.0 168e083a43cSThomas E. Spanjaardand subsequently 169f42602e5SThomas E. Spanjaard.Dx 1.7 . 170e083a43cSThomas E. Spanjaard.Sh AUTHORS 171e083a43cSThomas E. Spanjaard.An -nosplit 172e083a43cSThomas E. SpanjaardThe original 17350e92fdfSThomas E. Spanjaard.Nm kenv 174e083a43cSThomas E. Spanjaardimplementation was written by 175e083a43cSThomas E. Spanjaard.An Michael Smith . 176e083a43cSThomas E. SpanjaardIt was subsequently extended by 177e083a43cSThomas E. Spanjaard.An Matt Jacob , 178e083a43cSThomas E. Spanjaard.An John Baldwin 179e083a43cSThomas E. Spanjaardand 180e083a43cSThomas E. Spanjaard.An Maxime Henrion . 181e083a43cSThomas E. SpanjaardThis manual page was written by 182e083a43cSThomas E. Spanjaard.An Thomas E. Spanjaard . 18306b20a23SThomas E. Spanjaard.Sh BUGS 18406b20a23SThomas E. SpanjaardThe 185e9c76aafSSascha Wildner.Va kern.environment 18606b20a23SThomas E. Spanjaardsysctl OID currently only reports information about the static kernel 18706b20a23SThomas E. Spanjaardenvironment, not the dynamic one. 18806b20a23SThomas E. Spanjaard.Pp 18906b20a23SThomas E. SpanjaardThe return values from various functions could do with some standardisation, 19006b20a23SThomas E. Spanjaardusing the error codes from 19106b20a23SThomas E. Spanjaard.In sys/errno.h . 192