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.13 1995/08/20 04:42:25 davidg 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 49 static void 50 dummy_cleanup() {} 51 TEXT_SET(cleanup_set, dummy_cleanup); 52 53 typedef void (*cleanup_func_t)(void); 54 extern const struct linker_set cleanup_set; 55 static const cleanup_func_t *cleanups = 56 (const cleanup_func_t *)&cleanup_set.ls_items[0]; 57 58 struct reboot_args { 59 int opt; 60 }; 61 /* ARGSUSED */ 62 int 63 reboot(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 86 struct gethostname_args { 87 char *hostname; 88 u_int len; 89 }; 90 /* ARGSUSED */ 91 int 92 ogethostname(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 103 struct sethostname_args { 104 char *hostname; 105 u_int len; 106 }; 107 /* ARGSUSED */ 108 int 109 osethostname(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 123 struct gethostid_args { 124 int dummy; 125 }; 126 /* ARGSUSED */ 127 int 128 ogethostid(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 140 struct sethostid_args { 141 long hostid; 142 }; 143 /* ARGSUSED */ 144 int 145 osethostid(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 158 int 159 oquota() 160 { 161 162 return (ENOSYS); 163 } 164 #endif /* COMPAT_43 */ 165 166 void 167 shutdown_nice(void) 168 { 169 /* Send a signal to init(8) and have it shutdown the world */ 170 if (initproc != NULL) { 171 psignal(initproc, SIGINT); 172 } else { 173 /* No init(8) running, so simply reboot */ 174 boot(RB_NOSYNC); 175 } 176 return; 177 } 178 179 180 struct uname_args { 181 struct utsname *name; 182 }; 183 184 /* ARGSUSED */ 185 int 186 uname(p, uap, retval) 187 struct proc *p; 188 struct uname_args *uap; 189 int *retval; 190 { 191 int name; 192 int len; 193 int rtval; 194 char *s, *us; 195 196 name = KERN_OSTYPE; 197 len = sizeof uap->name->sysname; 198 rtval = kern_sysctl(&name, 1, uap->name->sysname, &len, 0, 0, p); 199 if( rtval) return rtval; 200 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 201 202 name = KERN_HOSTNAME; 203 len = sizeof uap->name->nodename; 204 rtval = kern_sysctl(&name, 1, uap->name->nodename, &len, 0, 0, p); 205 if( rtval) return rtval; 206 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 207 208 name = KERN_OSRELEASE; 209 len = sizeof uap->name->release; 210 rtval = kern_sysctl(&name, 1, uap->name->release, &len, 0, 0, p); 211 if( rtval) return rtval; 212 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 213 214 /* 215 name = KERN_VERSION; 216 len = sizeof uap->name->version; 217 rtval = kern_sysctl(&name, 1, uap->name->version, &len, 0, 0, p); 218 if( rtval) return rtval; 219 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 220 */ 221 222 /* 223 * this stupid hackery to make the version field look like FreeBSD 1.1 224 */ 225 for(s = version; *s && *s != '#'; s++); 226 227 for(us = uap->name->version; *s && *s != ':'; s++) { 228 rtval = subyte( us++, *s); 229 if( rtval) 230 return rtval; 231 } 232 rtval = subyte( us++, 0); 233 if( rtval) 234 return rtval; 235 236 name = HW_MACHINE; 237 len = sizeof uap->name->machine; 238 rtval = hw_sysctl(&name, 1, uap->name->machine, &len, 0, 0, p); 239 if( rtval) return rtval; 240 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 241 242 return 0; 243 } 244 245 struct getdomainname_args { 246 char *domainname; 247 u_int len; 248 }; 249 250 /* ARGSUSED */ 251 int 252 getdomainname(p, uap, retval) 253 struct proc *p; 254 struct getdomainname_args *uap; 255 int *retval; 256 { 257 if (uap->len > domainnamelen + 1) 258 uap->len = domainnamelen + 1; 259 return (copyout((caddr_t)domainname, (caddr_t)uap->domainname, uap->len)); 260 } 261 262 struct setdomainname_args { 263 char *domainname; 264 u_int len; 265 }; 266 267 /* ARGSUSED */ 268 int 269 setdomainname(p, uap, retval) 270 struct proc *p; 271 struct setdomainname_args *uap; 272 int *retval; 273 { 274 int error; 275 276 if ((error = suser(p->p_ucred, &p->p_acflag))) 277 return (error); 278 if (uap->len > sizeof (domainname) - 1) 279 return EINVAL; 280 domainnamelen = uap->len; 281 error = copyin((caddr_t)uap->domainname, domainname, uap->len); 282 domainname[domainnamelen] = 0; 283 return (error); 284 } 285 286