kern_xxx.c revision 9798
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)kern_xxx.c	8.2 (Berkeley) 11/14/93
34 * $Id: kern_xxx.c,v 1.10 1995/05/30 08:05:49 rgrimes Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/proc.h>
41#include <sys/reboot.h>
42#include <vm/vm.h>
43#include <sys/sysctl.h>
44#include <sys/utsname.h>
45#include <sys/signalvar.h>
46
47/* This implements a "TEXT_SET" for cleanup functions */
48
49static void
50dummy_cleanup() {}
51TEXT_SET(cleanup_set, dummy_cleanup);
52
53typedef void (*cleanup_func_t)(void);
54extern const struct linker_set cleanup_set;
55static const cleanup_func_t *cleanups =
56        (const cleanup_func_t *)&cleanup_set.ls_items[0];
57
58struct reboot_args {
59	int	opt;
60};
61/* ARGSUSED */
62int
63reboot(p, uap, retval)
64	struct proc *p;
65	struct reboot_args *uap;
66	int *retval;
67{
68	int error;
69
70	if ((error = suser(p->p_ucred, &p->p_acflag)))
71		return (error);
72
73	if (!uap->opt & RB_NOSYNC) {
74		printf("\ncleaning up... ");
75                while(*cleanups) {
76                        (**cleanups++)();
77                }
78	}
79
80	boot(uap->opt);
81	return (0);
82}
83
84#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
85
86struct gethostname_args {
87	char	*hostname;
88	u_int	len;
89};
90/* ARGSUSED */
91int
92ogethostname(p, uap, retval)
93	struct proc *p;
94	struct gethostname_args *uap;
95	int *retval;
96{
97	int name;
98
99	name = KERN_HOSTNAME;
100	return (kern_sysctl(&name, 1, uap->hostname, &uap->len, 0, 0, p));
101}
102
103struct sethostname_args {
104	char	*hostname;
105	u_int	len;
106};
107/* ARGSUSED */
108int
109osethostname(p, uap, retval)
110	struct proc *p;
111	register struct sethostname_args *uap;
112	int *retval;
113{
114	int name;
115	int error;
116
117	if ((error = suser(p->p_ucred, &p->p_acflag)))
118		return (error);
119	name = KERN_HOSTNAME;
120	return (kern_sysctl(&name, 1, 0, 0, uap->hostname, uap->len, p));
121}
122
123struct gethostid_args {
124	int	dummy;
125};
126/* ARGSUSED */
127int
128ogethostid(p, uap, retval)
129	struct proc *p;
130	struct gethostid_args *uap;
131	int *retval;
132{
133
134	*(long *)retval = hostid;
135	return (0);
136}
137#endif /* COMPAT_43 || COMPAT_SUNOS */
138
139#ifdef COMPAT_43
140struct sethostid_args {
141	long	hostid;
142};
143/* ARGSUSED */
144int
145osethostid(p, uap, retval)
146	struct proc *p;
147	struct sethostid_args *uap;
148	int *retval;
149{
150	int error;
151
152	if ((error = suser(p->p_ucred, &p->p_acflag)))
153		return (error);
154	hostid = uap->hostid;
155	return (0);
156}
157
158int
159oquota()
160{
161
162	return (ENOSYS);
163}
164#endif /* COMPAT_43 */
165
166void
167shutdown_nice(void)
168{
169	register struct proc *p;
170
171	/* Send a signal to init(8) and have it shutdown the world */
172	if (initproc != NULL)
173		psignal(initproc, SIGINT);
174
175	return;
176}
177
178
179struct uname_args {
180        struct utsname  *name;
181};
182
183/* ARGSUSED */
184int
185uname(p, uap, retval)
186	struct proc *p;
187	struct uname_args *uap;
188	int *retval;
189{
190	int name;
191	int len;
192	int rtval;
193	char *s, *us;
194
195	name = KERN_OSTYPE;
196	len = sizeof uap->name->sysname;
197	rtval = kern_sysctl(&name, 1, uap->name->sysname, &len, 0, 0, p);
198	if( rtval) return rtval;
199	subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
200
201	name = KERN_HOSTNAME;
202	len = sizeof uap->name->nodename;
203	rtval = kern_sysctl(&name, 1, uap->name->nodename, &len, 0, 0, p);
204	if( rtval) return rtval;
205	subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
206
207	name = KERN_OSRELEASE;
208	len = sizeof uap->name->release;
209	rtval = kern_sysctl(&name, 1, uap->name->release, &len, 0, 0, p);
210	if( rtval) return rtval;
211	subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
212
213/*
214	name = KERN_VERSION;
215	len = sizeof uap->name->version;
216	rtval = kern_sysctl(&name, 1, uap->name->version, &len, 0, 0, p);
217	if( rtval) return rtval;
218	subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
219*/
220
221/*
222 * this stupid hackery to make the version field look like FreeBSD 1.1
223 */
224	for(s = version; *s && *s != '#'; s++);
225
226	for(us = uap->name->version; *s && *s != ':'; s++) {
227		rtval = subyte( us++, *s);
228		if( rtval)
229			return rtval;
230	}
231	rtval = subyte( us++, 0);
232	if( rtval)
233		return rtval;
234
235	name = HW_MACHINE;
236	len = sizeof uap->name->machine;
237	rtval = hw_sysctl(&name, 1, uap->name->machine, &len, 0, 0, p);
238	if( rtval) return rtval;
239	subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
240
241	return 0;
242}
243
244struct getdomainname_args {
245        char    *domainname;
246        u_int   len;
247};
248
249/* ARGSUSED */
250int
251getdomainname(p, uap, retval)
252        struct proc *p;
253        struct getdomainname_args *uap;
254        int *retval;
255{
256	if (uap->len > domainnamelen + 1)
257		uap->len = domainnamelen + 1;
258	return (copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len));
259}
260
261struct setdomainname_args {
262        char    *domainname;
263        u_int   len;
264};
265
266/* ARGSUSED */
267int
268setdomainname(p, uap, retval)
269        struct proc *p;
270        struct setdomainname_args *uap;
271        int *retval;
272{
273        int error;
274
275        if ((error = suser(p->p_ucred, &p->p_acflag)))
276                return (error);
277        if (uap->len > sizeof (domainname) - 1)
278                return EINVAL;
279        domainnamelen = uap->len;
280        error = copyin((caddr_t)uap->domainname, domainname, uap->len);
281        domainname[domainnamelen] = 0;
282        return (error);
283}
284
285