summaryrefslogtreecommitdiff
path: root/pkgtools/libkver/files/lib/kver.3
blob: d8c8bddd410ed9dea87ee062c5a87e801adbe6f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
.\" $NetBSD: kver.3,v 1.5 2012/10/31 22:55:40 wiz Exp $
.\"
.Dd October 31, 2012
.Os
.Dt KVER 3
.Sh NAME
.Nm kver
.Nd override system version library
.Sh SYNOPSIS
LD_PRELOAD=@PREFIX@/lib/libkver.so uname -a
.Sh DESCRIPTION
The
.Nm
library provides implementations of
.Xr sysctl 3 and
.Xr uname 3 that
shadow the real implementation and could be configured to override the
information identifying the current system.
This is useful for, among other things, building packages in a
sandbox/chrooted environment for a different
.Nx
release then the system hosting the sandbox.
.Pp
The library is usually loaded by the run-time link-editor via the
.Ev LD_PRELOAD
hook.
The
.Xr kver 8
utility provides a simple wrapper for convenience.
.Pp
For each variable that may be overridden,
.Nm
first attempts to obtain an override value from an environment variable;
if the environment variable is not set then it uses
.Xr readlink 2
to get the target of a symbolic link, and treats that as the override value;
if that also fails, then the variable is not overridden.
If none of the variables are overridden, or if an error occurs, then
the
.Nm
library emits a warning message on the standard error output,
and allows the program to run without any overrides.
.Pp
The following table lists all the variables that may be overridden,
giving the environment variable name, the symbolic link name,
and a description of the way the value is used.
.Pp
.Bl -column "LIBKVER_MACHINE_ARCH" "/libkver_machine_arch"
.It Sy Environment Ta Sy Symlink Ta Sy Description
.
.It Ev LIBKVER_OSTYPE Ta Pa /libkver_ostype Ta
The operating system type, e.g.\&
.Qq Nx .
Overrides the
.Xr sysctl 7
variable
.Va kern.ostype .
Overrides the result from
.Xr uname 1
with the
.Fl s
flag.
Overrides the
.Va sysname
element of the
.Vt "struct utsname"
result from
.Xr uname 3 .
.
.It Ev LIBKVER_OSRELEASE Ta Pa /libkver_osrelease Ta
The operating system release, e.g.\&
.Qq "6.0_STABLE" .
Overrides the
.Xr sysctl 7
variable
.Va kern.osrelease .
Overrides the result from
.Xr uname 1
with the
.Fl r
flag.
Overrides the
.Va release
element of the
.Vt "struct utsname"
result from
.Xr uname 3 .
.Pp
This value is also converted to an integer, which is used to
override the value of the
.Xr sysctl 7
variable
.Va kern.osrevision .
.
.It Ev LIBKVER_MACHINE Ta Pa /libkver_machine Ta
The operating hardware platform, e.g.\&
.Dq "amd64" .
Overrides the
.Xr sysctl 7
variable
.Va hw.machine .
Overrides the result from
.Xr uname 1
with the
.Fl m
flag.
Overrides the
.Va machine
element of the
.Vt "struct utsname"
result from
.Xr uname 3 .
.
.It Ev LIBKVER_MACHINE_ARCH Ta Pa /libkver_machine_arch Ta
The machine processor architecture, e.g.\&
.Dq "x86_64" .
Overrides the
.Xr sysctl 7
variable
.Va hw.machine_arch .
Overrides the result from
.Xr uname 1
with the
.Fl p
flag.
.El
.Sh EXAMPLES
.Dl env LD_PRELOAD=/lib/libkver.so LIBKVER_OSRELEASE=1.5 uname -r
.Pp
.Dl ln -s 1.6.2 /libkver_osrelease
.Dl env LD_PRELOAD=/lib/libkver.so uname -r
.Sh DIAGNOSTICS
.Bl -diag
.It "libkver: uname"
.Xr uname 3
failed.
.It "libkver: not configured"
None of the configurable variables has been overridden.
.It "libkver: sysctl hw.machine_arch"
.Xr sysctl 3
failed to retrieve the value of the
.Va hw.machine_arch
variable.
.It "libkver: cannot convert osrelease to osrevision: %s"
The osrelease string could not be converted to an integer for use by the
.Va kern.osrevision
.Xr sysctl 7
variable.
.Sh SEE ALSO
.Xr ld.so 1 ,
.Xr uname 1 ,
.Xr sysctl 3 ,
.Xr uname 3 ,
.Xr kver 8
.Sh AUTHORS
.An Stoned Elipot Aq seb@NetBSD.org
.An Alan Barrett Aq apb@NetBSD.org