xref: /csrg-svn/sys/kern/kern_xxx.c (revision 12793)
1 /*	kern_xxx.c	4.1	83/05/27	*/
2 
3 #include "../h/param.h"
4 #include "../h/systm.h"
5 #include "../h/dir.h"
6 #include "../h/user.h"
7 #include "../h/kernel.h"
8 #include "../h/proc.h"
9 #include "../h/reboot.h"
10 #include "../h/quota.h"
11 
12 gethostid()
13 {
14 
15 	u.u_r.r_val1 = hostid;
16 }
17 
18 sethostid()
19 {
20 	struct a {
21 		int	hostid;
22 	} *uap = (struct a *)u.u_ap;
23 
24 	if (suser())
25 		hostid = uap->hostid;
26 }
27 
28 gethostname()
29 {
30 	register struct a {
31 		char	*hostname;
32 		int	len;
33 	} *uap = (struct a *)u.u_ap;
34 	register u_int len;
35 
36 	len = uap->len;
37 	if (len > hostnamelen + 1)
38 		len = hostnamelen + 1;
39 	u.u_error = copyout((caddr_t)hostname, (caddr_t)uap->hostname, len);
40 }
41 
42 sethostname()
43 {
44 	register struct a {
45 		char	*hostname;
46 		u_int	len;
47 	} *uap = (struct a *)u.u_ap;
48 
49 	if (!suser())
50 		return;
51 	if (uap->len > sizeof (hostname) - 1) {
52 		u.u_error = EINVAL;
53 		return;
54 	}
55 	hostnamelen = uap->len;
56 	u.u_error = copyin((caddr_t)uap->hostname, hostname, uap->len);
57 	hostname[hostnamelen] = 0;
58 }
59 
60 reboot()
61 {
62 	register struct a {
63 		int	opt;
64 	};
65 
66 	if (suser())
67 		boot(RB_BOOT, ((struct a *)u.u_ap)->opt);
68 }
69 
70 #ifndef NOCOMPAT
71 osetuid()
72 {
73 	register uid;
74 	register struct a {
75 		int	uid;
76 	} *uap;
77 
78 	uap = (struct a *)u.u_ap;
79 	uid = uap->uid;
80 	if (u.u_ruid == uid || u.u_uid == uid || suser()) {
81 #ifdef QUOTA
82 		if (u.u_quota->q_uid != uid) {
83 			qclean();
84 			qstart(getquota(uid, 0, 0));
85 		}
86 #endif
87 		u.u_uid = uid;
88 		u.u_procp->p_uid = uid;
89 		u.u_ruid = uid;
90 	}
91 }
92 
93 osetgid()
94 {
95 	register gid;
96 	register struct a {
97 		int	gid;
98 	} *uap;
99 
100 	uap = (struct a *)u.u_ap;
101 	gid = uap->gid;
102 	if (u.u_rgid == gid || u.u_gid == gid || suser()) {
103 		leavegroup(u.u_rgid);
104 		(void) entergroup(gid);
105 		u.u_gid = gid;
106 		u.u_rgid = gid;
107 	}
108 }
109 
110 /*
111  * Pid of zero implies current process.
112  * Pgrp -1 is getpgrp system call returning
113  * current process group.
114  */
115 osetpgrp()
116 {
117 	register struct proc *p;
118 	register struct a {
119 		int	pid;
120 		int	pgrp;
121 	} *uap;
122 
123 	uap = (struct a *)u.u_ap;
124 	if (uap->pid == 0)
125 		p = u.u_procp;
126 	else {
127 		p = pfind(uap->pid);
128 		if (p == 0) {
129 			u.u_error = ESRCH;
130 			return;
131 		}
132 	}
133 	if (uap->pgrp <= 0) {
134 		u.u_r.r_val1 = p->p_pgrp;
135 		return;
136 	}
137 	if (p->p_uid != u.u_uid && u.u_uid && !inferior(p)) {
138 		u.u_error = EPERM;
139 		return;
140 	}
141 	p->p_pgrp = uap->pgrp;
142 }
143 
144 otime()
145 {
146 
147 	u.u_r.r_time = time.tv_sec;
148 }
149 
150 ostime()
151 {
152 	register struct a {
153 		int	time;
154 	} *uap = (struct a *)u.u_ap;
155 	struct timeval tv;
156 
157 	tv.tv_sec = uap->time;
158 	tv.tv_usec = 0;
159 	setthetime(&tv);
160 }
161 
162 /* from old timeb.h */
163 struct timeb {
164 	time_t	time;
165 	u_short	millitm;
166 	short	timezone;
167 	short	dstflag;
168 };
169 
170 oftime()
171 {
172 	register struct a {
173 		struct	timeb	*tp;
174 	} *uap;
175 	struct timeb tb;
176 
177 	uap = (struct a *)u.u_ap;
178 	(void) spl7();
179 	tb.time = time.tv_sec;
180 	tb.millitm = time.tv_usec / 1000;
181 	(void) spl0();
182 	tb.timezone = tz.tz_minuteswest;
183 	tb.dstflag = tz.tz_dsttime;
184 	u.u_error = copyout((caddr_t)&tb, (caddr_t)uap->tp, sizeof (tb));
185 }
186 
187 oalarm()
188 {
189 	register struct a {
190 		int	deltat;
191 	} *uap = (struct a *)u.u_ap;
192 	register struct proc *p = u.u_procp;
193 	int s = spl7();
194 
195 	untimeout(realitexpire, (caddr_t)p);
196 	timerclear(&p->p_realtimer.it_interval);
197 	u.u_r.r_val1 = 0;
198 	if (timerisset(&p->p_realtimer.it_value) &&
199 	    timercmp(&p->p_realtimer.it_value, &time, >))
200 		u.u_r.r_val1 = p->p_realtimer.it_value.tv_sec - time.tv_sec;
201 	if (uap->deltat == 0) {
202 		timerclear(&p->p_realtimer.it_value);
203 		splx(s);
204 		return;
205 	}
206 	p->p_realtimer.it_value = time;
207 	p->p_realtimer.it_value.tv_sec += uap->deltat;
208 	timeout(realitexpire, (caddr_t)p, hzto(&p->p_realtimer.it_value));
209 	splx(s);
210 }
211 
212 onice()
213 {
214 	register struct a {
215 		int	niceness;
216 	} *uap = (struct a *)u.u_ap;
217 	register struct proc *p = u.u_procp;
218 
219 	donice(p, (p->p_nice-NZERO)+uap->niceness);
220 }
221 
222 #include "../h/times.h"
223 
224 otimes()
225 {
226 	register struct a {
227 		struct	tms *tmsb;
228 	} *uap = (struct a *)u.u_ap;
229 	struct tms atms;
230 
231 	atms.tms_utime = scale60(&u.u_ru.ru_utime);
232 	atms.tms_stime = scale60(&u.u_ru.ru_stime);
233 	atms.tms_cutime = scale60(&u.u_cru.ru_utime);
234 	atms.tms_cstime = scale60(&u.u_cru.ru_stime);
235 	u.u_error = copyout((caddr_t)&atms, (caddr_t)uap->tmsb, sizeof (atms));
236 }
237 
238 scale60(tvp)
239 	register struct timeval *tvp;
240 {
241 
242 	return (tvp->tv_sec * 60 + tvp->tv_usec / 16667);
243 }
244 
245 #include "../h/vtimes.h"
246 
247 ovtimes()
248 {
249 	register struct a {
250 		struct	vtimes *par;
251 		struct	vtimes *chi;
252 	} *uap = (struct a *)u.u_ap;
253 	struct vtimes avt;
254 
255 	if (uap->par) {
256 		getvtimes(&u.u_ru, &avt);
257 		u.u_error = copyout((caddr_t)&avt, (caddr_t)uap->par,
258 			sizeof (avt));
259 		if (u.u_error)
260 			return;
261 	}
262 	if (uap->chi) {
263 		getvtimes(&u.u_cru, &avt);
264 		u.u_error = copyout((caddr_t)&avt, (caddr_t)uap->chi,
265 			sizeof (avt));
266 		if (u.u_error)
267 			return;
268 	}
269 }
270 
271 getvtimes(aru, avt)
272 	register struct rusage *aru;
273 	register struct vtimes *avt;
274 {
275 
276 	avt->vm_utime = scale60(&aru->ru_utime);
277 	avt->vm_stime = scale60(&aru->ru_stime);
278 	avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / hz) * 60;
279 	avt->vm_ixrss = aru->ru_ixrss / hz * 60;
280 	avt->vm_maxrss = aru->ru_maxrss;
281 	avt->vm_majflt = aru->ru_majflt;
282 	avt->vm_minflt = aru->ru_minflt;
283 	avt->vm_nswap = aru->ru_nswap;
284 	avt->vm_inblk = aru->ru_inblock;
285 	avt->vm_oublk = aru->ru_oublock;
286 }
287 
288 ovlimit()
289 {
290 
291 	u.u_error = EACCES;
292 }
293 
294 okill()
295 {
296 	register struct a {
297 		int	pid;
298 		int	signo;
299 	} *uap = (struct a *)u.u_ap;
300 
301 	u.u_error = kill1(uap->signo < 0,
302 		uap->signo < 0 ? -uap->signo : uap->signo, uap->pid);
303 }
304 
305 ossig()
306 {
307 	register int (*f)();
308 	struct a {
309 		int	signo;
310 		int	(*fun)();
311 	} *uap;
312 	register struct proc *p = u.u_procp;
313 	register a;
314 	long sigmask;
315 
316 	uap = (struct a *)u.u_ap;
317 	a = uap->signo & SIGNUMMASK;
318 	f = uap->fun;
319 	if (a<=0 || a>=NSIG || a==SIGKILL || a==SIGSTOP ||
320 	    a==SIGCONT && (f == SIG_IGN || f == SIG_HOLD)) {
321 		u.u_error = EINVAL;
322 		return;
323 	}
324 	if ((uap->signo &~ SIGNUMMASK) || (f != SIG_DFL && f != SIG_IGN &&
325 	    SIGISDEFER(f)))
326 		u.u_procp->p_flag |= SNUSIG;
327 	/*
328 	 * Don't clobber registers if we are to simulate
329 	 * a ret+rti.
330 	 */
331 	if ((uap->signo&SIGDORTI) == 0)
332 		u.u_r.r_val1 = (int)u.u_signal[a];
333 	/*
334 	 * Change setting atomically.
335 	 */
336 	(void) spl6();
337 	sigmask = 1L << (a-1);
338 	if (f == SIG_IGN)
339 		p->p_sig &= ~sigmask;		/* never to be seen again */
340 	u.u_signal[a] = f;
341 	if (f != SIG_DFL && f != SIG_IGN && f != SIG_HOLD)
342 		f = SIG_CATCH;
343 	if ((int)f & 1)
344 		p->p_siga0 |= sigmask;
345 	else
346 		p->p_siga0 &= ~sigmask;
347 	if ((int)f & 2)
348 		p->p_siga1 |= sigmask;
349 	else
350 		p->p_siga1 &= ~sigmask;
351 	(void) spl0();
352 	/*
353 	 * Now handle options.
354 	 */
355 	if (uap->signo & SIGDOPAUSE) {
356 		/*
357 		 * Simulate a PDP11 style wait instrution which
358 		 * atomically lowers priority, enables interrupts
359 		 * and hangs.
360 		 */
361 		opause();
362 		/*NOTREACHED*/
363 	}
364 	if (uap->signo & SIGDORTI)
365 		u.u_eosys = SIMULATERTI;
366 }
367 #endif
368