]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libutil/getlocalbase.3
setusercontext(): Set umask in a separate function, setclassumask()
[FreeBSD/FreeBSD.git] / lib / libutil / getlocalbase.3
1 .\"
2 .\" SPDX-License-Identifier: BSD-2-Clause
3 .\"
4 .\" Copyright 2020 Scott Long
5 .\" Copyright 2020 Stefan Eßer
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .Dd July 11, 2023
29 .Dt GETLOCALBASE 3
30 .Os
31 .Sh NAME
32 .Nm getlocalbase
33 .Nd "return the path to the local software directory"
34 .Sh LIBRARY
35 .Lb libutil
36 .Sh SYNOPSIS
37 .In libutil.h
38 .Ft const char*
39 .Fn getlocalbase "void"
40 .Sh DESCRIPTION
41 The
42 .Fn getlocalbase
43 function returns the path to the local software base directory.
44 Normally this is the
45 .Pa /usr/local
46 directory.
47 First the
48 .Ev LOCALBASE
49 environment variable is checked.
50 If that does not exist then the
51 .Va user.localbase
52 sysctl is checked.
53 If that also does not exist then the value of the
54 .Dv LOCALBASE_PATH
55 compile-time variable is used.
56 If that is undefined then the system default,
57 .Pa _PATH_LOCALBASE
58 is used.
59 .Pp
60 The contents of the string returned by the
61 .Fn getlocalbase
62 function shall not be modified.
63 .Sh IMPLEMENTATION NOTES
64 Calls to
65 .Fn getlocalbase
66 will perform a setugid check on the running binary before checking the
67 environment.
68 .Pp
69 The address returned by
70 .Fn getlocalbase
71 will point into the executing processes environment if it is the result of
72 .Fn getenv "LOCALBASE" ,
73 to a static buffer if it is the result of
74 .Fn sysctl "user.localbase" ,
75 and to a constant string if the compiled in default value is returned.
76 .Pp
77 The same value will be returned on successive calls during the run-time
78 of the program, ignoring any changes to the environment variable or the
79 sysctl value that might have been made.
80 .Pp
81 The
82 .Fn getlocalbase
83 function can be compiled with a non-default value of LOCALBASE_CTL_LEN.
84 A value of 0 will disable fetching of the sysctl value, a value less than
85 MAXPATHLEN will put a limit on the maximum string length supported for
86 this sysctl value.
87 If built with a non-default value of LOCALBASE_CTL_LEN, a value of the
88 user.localbase sysctl variable longer than this value will make
89 .Fn getlocalbase
90 return a valid string that is not a valid path prefix in any filesystem.
91 .Sh RETURN VALUES
92 The
93 .Fn getlocalbase
94 function returns a pointer to a string, whose length may exceed MAXPATHLEN,
95 if it has been obtained from the environment.
96 .Sh ENVIRONMENT
97 The
98 .Fn getlocalbase
99 library function retrieves the
100 .Ev LOCALBASE
101 environment variable.
102 .Sh ERRORS
103 The
104 .Fn getlocalbase
105 function always succeeds and returns a valid pointer to a string.
106 .Sh SEE ALSO
107 .Xr env 1 ,
108 .Xr src.conf 5 ,
109 .Xr sysctl 8
110 .Sh HISTORY
111 The
112 .Nm
113 library function first appeared in
114 .Fx 13.0 .
115 .Sh AUTHORS
116 .An -nosplit
117 This
118 manual page was written by
119 .An Scott Long Aq Mt scottl@FreeBSD.org
120 and
121 .An Stefan Eßer Aq Mt se@FreeBSD.org .