xref: /freebsd/sys/kern/kern_exit.c (revision 68fe945a06a38b0bfd4482548b2ca57d4dfc6f99)
1 /*
2  * Copyright (c) 1982, 1986, 1989, 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)kern_exit.c	8.7 (Berkeley) 2/12/94
39  * $FreeBSD$
40  */
41 
42 #include "opt_compat.h"
43 #include "opt_ktrace.h"
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/sysproto.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/lock.h>
51 #include <sys/mutex.h>
52 #include <sys/proc.h>
53 #include <sys/pioctl.h>
54 #include <sys/tty.h>
55 #include <sys/wait.h>
56 #include <sys/vnode.h>
57 #include <sys/resourcevar.h>
58 #include <sys/signalvar.h>
59 #include <sys/sx.h>
60 #include <sys/ptrace.h>
61 #include <sys/acct.h>		/* for acct_process() function prototype */
62 #include <sys/filedesc.h>
63 #include <sys/shm.h>
64 #include <sys/sem.h>
65 #include <sys/aio.h>
66 #include <sys/jail.h>
67 
68 #include <vm/vm.h>
69 #include <vm/vm_param.h>
70 #include <vm/pmap.h>
71 #include <vm/vm_map.h>
72 #include <vm/vm_zone.h>
73 #include <sys/user.h>
74 
75 /* Required to be non-static for SysVR4 emulator */
76 MALLOC_DEFINE(M_ZOMBIE, "zombie", "zombie proc status");
77 
78 static MALLOC_DEFINE(M_ATEXIT, "atexit", "atexit callback");
79 
80 static int wait1 __P((struct proc *, struct wait_args *, int));
81 
82 /*
83  * callout list for things to do at exit time
84  */
85 struct exitlist {
86 	exitlist_fn function;
87 	TAILQ_ENTRY(exitlist) next;
88 };
89 
90 TAILQ_HEAD(exit_list_head, exitlist);
91 static struct exit_list_head exit_list = TAILQ_HEAD_INITIALIZER(exit_list);
92 
93 /*
94  * exit --
95  *	Death of process.
96  */
97 void
98 sys_exit(p, uap)
99 	struct proc *p;
100 	struct sys_exit_args /* {
101 		int	rval;
102 	} */ *uap;
103 {
104 
105 	exit1(p, W_EXITCODE(uap->rval, 0));
106 	/* NOTREACHED */
107 }
108 
109 /*
110  * Exit: deallocate address space and other resources, change proc state
111  * to zombie, and unlink proc from allproc and parent's lists.  Save exit
112  * status and rusage for wait().  Check for child processes and orphan them.
113  */
114 void
115 exit1(p, rv)
116 	register struct proc *p;
117 	int rv;
118 {
119 	register struct proc *q, *nq;
120 	register struct vmspace *vm;
121 	struct exitlist *ep;
122 
123 	GIANT_REQUIRED;
124 
125 	if (p->p_pid == 1) {
126 		printf("init died (signal %d, exit %d)\n",
127 		    WTERMSIG(rv), WEXITSTATUS(rv));
128 		panic("Going nowhere without my init!");
129 	}
130 
131 	aio_proc_rundown(p);
132 
133 	/* are we a task leader? */
134 	PROC_LOCK(p);
135 	if(p == p->p_leader) {
136 		q = p->p_peers;
137 		while (q != NULL) {
138 			PROC_LOCK(q);
139 			psignal(q, SIGKILL);
140 			PROC_UNLOCK(q);
141 			q = q->p_peers;
142 		}
143 		while (p->p_peers)
144 			msleep((caddr_t)p, &p->p_mtx, PWAIT, "exit1", 0);
145 	}
146 	PROC_UNLOCK(p);
147 
148 #ifdef PGINPROF
149 	vmsizmon();
150 #endif
151 	STOPEVENT(p, S_EXIT, rv);
152 	wakeup(&p->p_stype);	/* Wakeup anyone in procfs' PIOCWAIT */
153 
154 	/*
155 	 * Check if any loadable modules need anything done at process exit.
156 	 * e.g. SYSV IPC stuff
157 	 * XXX what if one of these generates an error?
158 	 */
159 	TAILQ_FOREACH(ep, &exit_list, next)
160 		(*ep->function)(p);
161 
162 	stopprofclock(p);
163 
164 	MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage),
165 		M_ZOMBIE, M_WAITOK);
166 	/*
167 	 * If parent is waiting for us to exit or exec,
168 	 * P_PPWAIT is set; we will wakeup the parent below.
169 	 */
170 	PROC_LOCK(p);
171 	p->p_flag &= ~(P_TRACED | P_PPWAIT);
172 	p->p_flag |= P_WEXIT;
173 	SIGEMPTYSET(p->p_siglist);
174 	PROC_UNLOCK(p);
175 	if (timevalisset(&p->p_realtimer.it_value))
176 		callout_stop(&p->p_itcallout);
177 
178 	/*
179 	 * Reset any sigio structures pointing to us as a result of
180 	 * F_SETOWN with our pid.
181 	 */
182 	funsetownlst(&p->p_sigiolst);
183 
184 	/*
185 	 * Close open files and release open-file table.
186 	 * This may block!
187 	 */
188 	fdfree(p);
189 
190 	/*
191 	 * Remove ourself from our leader's peer list and wake our leader.
192 	 */
193 	PROC_LOCK(p->p_leader);
194 	if(p->p_leader->p_peers) {
195 		q = p->p_leader;
196 		while(q->p_peers != p)
197 			q = q->p_peers;
198 		q->p_peers = p->p_peers;
199 		wakeup((caddr_t)p->p_leader);
200 	}
201 	PROC_UNLOCK(p->p_leader);
202 
203 	/*
204 	 * XXX Shutdown SYSV semaphores
205 	 */
206 	semexit(p);
207 
208 	/* The next two chunks should probably be moved to vmspace_exit. */
209 	vm = p->p_vmspace;
210 	/*
211 	 * Release user portion of address space.
212 	 * This releases references to vnodes,
213 	 * which could cause I/O if the file has been unlinked.
214 	 * Need to do this early enough that we can still sleep.
215 	 * Can't free the entire vmspace as the kernel stack
216 	 * may be mapped within that space also.
217 	 */
218 	if (vm->vm_refcnt == 1) {
219 		if (vm->vm_shm)
220 			shmexit(p);
221 		pmap_remove_pages(vmspace_pmap(vm), VM_MIN_ADDRESS,
222 		    VM_MAXUSER_ADDRESS);
223 		(void) vm_map_remove(&vm->vm_map, VM_MIN_ADDRESS,
224 		    VM_MAXUSER_ADDRESS);
225 	}
226 
227 	PROC_LOCK(p);
228 	if (SESS_LEADER(p)) {
229 		register struct session *sp = p->p_session;
230 
231 		PROC_UNLOCK(p);
232 		if (sp->s_ttyvp) {
233 			/*
234 			 * Controlling process.
235 			 * Signal foreground pgrp,
236 			 * drain controlling terminal
237 			 * and revoke access to controlling terminal.
238 			 */
239 			if (sp->s_ttyp && (sp->s_ttyp->t_session == sp)) {
240 				if (sp->s_ttyp->t_pgrp)
241 					pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
242 				(void) ttywait(sp->s_ttyp);
243 				/*
244 				 * The tty could have been revoked
245 				 * if we blocked.
246 				 */
247 				if (sp->s_ttyvp)
248 					VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
249 			}
250 			if (sp->s_ttyvp)
251 				vrele(sp->s_ttyvp);
252 			sp->s_ttyvp = NULL;
253 			/*
254 			 * s_ttyp is not zero'd; we use this to indicate
255 			 * that the session once had a controlling terminal.
256 			 * (for logging and informational purposes)
257 			 */
258 		}
259 		sp->s_leader = NULL;
260 	} else
261 		PROC_UNLOCK(p);
262 	fixjobc(p, p->p_pgrp, 0);
263 	(void)acct_process(p);
264 #ifdef KTRACE
265 	/*
266 	 * release trace file
267 	 */
268 	p->p_traceflag = 0;	/* don't trace the vrele() */
269 	if (p->p_tracep)
270 		vrele(p->p_tracep);
271 #endif
272 	/*
273 	 * Remove proc from allproc queue and pidhash chain.
274 	 * Place onto zombproc.  Unlink from parent's child list.
275 	 */
276 	sx_xlock(&allproc_lock);
277 	LIST_REMOVE(p, p_list);
278 	LIST_INSERT_HEAD(&zombproc, p, p_list);
279 	LIST_REMOVE(p, p_hash);
280 	sx_xunlock(&allproc_lock);
281 
282 	sx_xlock(&proctree_lock);
283 	q = LIST_FIRST(&p->p_children);
284 	if (q != NULL)		/* only need this if any child is S_ZOMB */
285 		wakeup((caddr_t) initproc);
286 	for (; q != NULL; q = nq) {
287 		nq = LIST_NEXT(q, p_sibling);
288 		PROC_LOCK(q);
289 		proc_reparent(q, initproc);
290 		q->p_sigparent = SIGCHLD;
291 		/*
292 		 * Traced processes are killed
293 		 * since their existence means someone is screwing up.
294 		 */
295 		if (q->p_flag & P_TRACED) {
296 			q->p_flag &= ~P_TRACED;
297 			psignal(q, SIGKILL);
298 		}
299 		PROC_UNLOCK(q);
300 	}
301 
302 	/*
303 	 * Save exit status and final rusage info, adding in child rusage
304 	 * info and self times.
305 	 */
306 	p->p_xstat = rv;
307 	*p->p_ru = p->p_stats->p_ru;
308 	mtx_lock_spin(&sched_lock);
309 	calcru(p, &p->p_ru->ru_utime, &p->p_ru->ru_stime, NULL);
310 	mtx_unlock_spin(&sched_lock);
311 	ruadd(p->p_ru, &p->p_stats->p_cru);
312 
313 	/*
314 	 * Pretend that an mi_switch() to the next process occurs now.  We
315 	 * must set `switchtime' directly since we will call cpu_switch()
316 	 * directly.  Set it now so that the rest of the exit time gets
317 	 * counted somewhere if possible.
318 	 */
319 	mtx_lock_spin(&sched_lock);
320 	microuptime(PCPU_PTR(switchtime));
321 	PCPU_SET(switchticks, ticks);
322 	mtx_unlock_spin(&sched_lock);
323 
324 	/*
325 	 * notify interested parties of our demise.
326 	 */
327 	PROC_LOCK(p);
328 	KNOTE(&p->p_klist, NOTE_EXIT);
329 
330 	/*
331 	 * Notify parent that we're gone.  If parent has the PS_NOCLDWAIT
332 	 * flag set, or if the handler is set to SIG_IGN, notify process
333 	 * 1 instead (and hope it will handle this situation).
334 	 */
335 	if ((p->p_pptr->p_procsig->ps_flag & PS_NOCLDWAIT)
336 	    || p->p_pptr->p_sigacts->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN) {
337 		struct proc *pp = p->p_pptr;
338 		proc_reparent(p, initproc);
339 		/*
340 		 * If this was the last child of our parent, notify
341 		 * parent, so in case he was wait(2)ing, he will
342 		 * continue.
343 		 */
344 		if (LIST_EMPTY(&pp->p_children))
345 			wakeup((caddr_t)pp);
346 	}
347 
348 	PROC_LOCK(p->p_pptr);
349 	if (p->p_sigparent && p->p_pptr != initproc)
350 	        psignal(p->p_pptr, p->p_sigparent);
351 	else
352 	        psignal(p->p_pptr, SIGCHLD);
353 	PROC_UNLOCK(p->p_pptr);
354 
355 	/*
356 	 * If this is a kthread, then wakeup anyone waiting for it to exit.
357 	 */
358 	if (p->p_flag & P_KTHREAD)
359 		wakeup((caddr_t)p);
360 	PROC_UNLOCK(p);
361 	sx_xunlock(&proctree_lock);
362 
363 	/*
364 	 * Clear curproc after we've done all operations
365 	 * that could block, and before tearing down the rest
366 	 * of the process state that might be used from clock, etc.
367 	 * Also, can't clear curproc while we're still runnable,
368 	 * as we're not on a run queue (we are current, just not
369 	 * a proper proc any longer!).
370 	 *
371 	 * Other substructures are freed from wait().
372 	 */
373 	mtx_assert(&Giant, MA_OWNED);
374 	if (--p->p_limit->p_refcnt == 0) {
375 		FREE(p->p_limit, M_SUBPROC);
376 		p->p_limit = NULL;
377 	}
378 
379 	/*
380 	 * Finally, call machine-dependent code to release the remaining
381 	 * resources including address space, the kernel stack and pcb.
382 	 * The address space is released by "vmspace_free(p->p_vmspace)";
383 	 * This is machine-dependent, as we may have to change stacks
384 	 * or ensure that the current one isn't reallocated before we
385 	 * finish.  cpu_exit will end with a call to cpu_switch(), finishing
386 	 * our execution (pun intended).
387 	 */
388 	cpu_exit(p);
389 }
390 
391 #ifdef COMPAT_43
392 int
393 owait(p, uap)
394 	struct proc *p;
395 	register struct owait_args /* {
396 		int     dummy;
397 	} */ *uap;
398 {
399 	struct wait_args w;
400 
401 	w.options = 0;
402 	w.rusage = NULL;
403 	w.pid = WAIT_ANY;
404 	w.status = NULL;
405 	return (wait1(p, &w, 1));
406 }
407 #endif /* COMPAT_43 */
408 
409 int
410 wait4(p, uap)
411 	struct proc *p;
412 	struct wait_args *uap;
413 {
414 
415 	return (wait1(p, uap, 0));
416 }
417 
418 static int
419 wait1(q, uap, compat)
420 	register struct proc *q;
421 	register struct wait_args /* {
422 		int pid;
423 		int *status;
424 		int options;
425 		struct rusage *rusage;
426 	} */ *uap;
427 	int compat;
428 {
429 	register int nfound;
430 	register struct proc *p, *t;
431 	int status, error;
432 
433 	if (uap->pid == 0)
434 		uap->pid = -q->p_pgid;
435 	if (uap->options &~ (WUNTRACED|WNOHANG|WLINUXCLONE))
436 		return (EINVAL);
437 loop:
438 	nfound = 0;
439 	sx_slock(&proctree_lock);
440 	LIST_FOREACH(p, &q->p_children, p_sibling) {
441 		if (uap->pid != WAIT_ANY &&
442 		    p->p_pid != uap->pid && p->p_pgid != -uap->pid)
443 			continue;
444 
445 		/*
446 		 * This special case handles a kthread spawned by linux_clone
447 		 * (see linux_misc.c).  The linux_wait4 and linux_waitpid
448 		 * functions need to be able to distinguish between waiting
449 		 * on a process and waiting on a thread.  It is a thread if
450 		 * p_sigparent is not SIGCHLD, and the WLINUXCLONE option
451 		 * signifies we want to wait for threads and not processes.
452 		 */
453 		PROC_LOCK(p);
454 		if ((p->p_sigparent != SIGCHLD) ^
455 		    ((uap->options & WLINUXCLONE) != 0)) {
456 			PROC_UNLOCK(p);
457 			continue;
458 		}
459 
460 		nfound++;
461 		mtx_lock_spin(&sched_lock);
462 		if (p->p_stat == SZOMB) {
463 			/* charge childs scheduling cpu usage to parent */
464 			if (curproc->p_pid != 1) {
465 				curproc->p_estcpu =
466 				    ESTCPULIM(curproc->p_estcpu + p->p_estcpu);
467 			}
468 
469 			mtx_unlock_spin(&sched_lock);
470 			PROC_UNLOCK(p);
471 			sx_sunlock(&proctree_lock);
472 
473 			q->p_retval[0] = p->p_pid;
474 #ifdef COMPAT_43
475 			if (compat)
476 				q->p_retval[1] = p->p_xstat;
477 			else
478 #endif
479 			if (uap->status) {
480 				status = p->p_xstat;	/* convert to int */
481 				if ((error = copyout((caddr_t)&status,
482 				    (caddr_t)uap->status, sizeof(status))))
483 					return (error);
484 			}
485 			if (uap->rusage && (error = copyout((caddr_t)p->p_ru,
486 			    (caddr_t)uap->rusage, sizeof (struct rusage))))
487 				return (error);
488 			/*
489 			 * If we got the child via a ptrace 'attach',
490 			 * we need to give it back to the old parent.
491 			 */
492 			sx_xlock(&proctree_lock);
493 			if (p->p_oppid) {
494 				if ((t = pfind(p->p_oppid)) != NULL) {
495 					PROC_LOCK(p);
496 					p->p_oppid = 0;
497 					proc_reparent(p, t);
498 					PROC_UNLOCK(p);
499 					psignal(t, SIGCHLD);
500 					wakeup((caddr_t)t);
501 					PROC_UNLOCK(t);
502 					sx_xunlock(&proctree_lock);
503 					return (0);
504 				}
505 			}
506 			sx_xunlock(&proctree_lock);
507 			PROC_LOCK(p);
508 			p->p_xstat = 0;
509 			PROC_UNLOCK(p);
510 			ruadd(&q->p_stats->p_cru, p->p_ru);
511 			FREE(p->p_ru, M_ZOMBIE);
512 			p->p_ru = NULL;
513 
514 			/*
515 			 * Decrement the count of procs running with this uid.
516 			 */
517 			(void)chgproccnt(p->p_ucred->cr_ruidinfo, -1, 0);
518 
519 			/*
520 			 * Release reference to text vnode
521 			 */
522 			if (p->p_textvp)
523 				vrele(p->p_textvp);
524 
525 			/*
526 			 * Finally finished with old proc entry.
527 			 * Unlink it from its process group and free it.
528 			 */
529 			leavepgrp(p);
530 
531 			sx_xlock(&allproc_lock);
532 			LIST_REMOVE(p, p_list);	/* off zombproc */
533 			sx_xunlock(&allproc_lock);
534 
535 			sx_xlock(&proctree_lock);
536 			LIST_REMOVE(p, p_sibling);
537 			sx_xunlock(&proctree_lock);
538 
539 			/*
540 			 * Free up credentials.
541 			 */
542 			crfree(p->p_ucred);
543 			p->p_ucred = NULL;
544 
545 			/*
546 			 * Remove unused arguments
547 			 */
548 			if (p->p_args && --p->p_args->ar_ref == 0)
549 				FREE(p->p_args, M_PARGS);
550 
551 			if (--p->p_procsig->ps_refcnt == 0) {
552 				if (p->p_sigacts != &p->p_addr->u_sigacts)
553 					FREE(p->p_sigacts, M_SUBPROC);
554 			        FREE(p->p_procsig, M_SUBPROC);
555 				p->p_procsig = NULL;
556 			}
557 
558 			/*
559 			 * Give machine-dependent layer a chance
560 			 * to free anything that cpu_exit couldn't
561 			 * release while still running in process context.
562 			 */
563 			cpu_wait(p);
564 			mtx_destroy(&p->p_mtx);
565 			zfree(proc_zone, p);
566 			nprocs--;
567 			return (0);
568 		}
569 		if (p->p_stat == SSTOP && (p->p_flag & P_WAITED) == 0 &&
570 		    (p->p_flag & P_TRACED || uap->options & WUNTRACED)) {
571 			mtx_unlock_spin(&sched_lock);
572 			p->p_flag |= P_WAITED;
573 			PROC_UNLOCK(p);
574 			sx_sunlock(&proctree_lock);
575 			q->p_retval[0] = p->p_pid;
576 #ifdef COMPAT_43
577 			if (compat) {
578 				q->p_retval[1] = W_STOPCODE(p->p_xstat);
579 				error = 0;
580 			} else
581 #endif
582 			if (uap->status) {
583 				status = W_STOPCODE(p->p_xstat);
584 				error = copyout((caddr_t)&status,
585 					(caddr_t)uap->status, sizeof(status));
586 			} else
587 				error = 0;
588 			return (error);
589 		}
590 		mtx_unlock_spin(&sched_lock);
591 		PROC_UNLOCK(p);
592 	}
593 	sx_sunlock(&proctree_lock);
594 	if (nfound == 0)
595 		return (ECHILD);
596 	if (uap->options & WNOHANG) {
597 		q->p_retval[0] = 0;
598 		return (0);
599 	}
600 	if ((error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)))
601 		return (error);
602 	goto loop;
603 }
604 
605 /*
606  * Make process 'parent' the new parent of process 'child'.
607  * Must be called with an exclusive hold of proctree lock.
608  */
609 void
610 proc_reparent(child, parent)
611 	register struct proc *child;
612 	register struct proc *parent;
613 {
614 
615 	SX_ASSERT_XLOCKED(&proctree_lock);
616 	PROC_LOCK_ASSERT(child, MA_OWNED);
617 	if (child->p_pptr == parent)
618 		return;
619 
620 	LIST_REMOVE(child, p_sibling);
621 	LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
622 	child->p_pptr = parent;
623 }
624 
625 /*
626  * The next two functions are to handle adding/deleting items on the
627  * exit callout list
628  *
629  * at_exit():
630  * Take the arguments given and put them onto the exit callout list,
631  * However first make sure that it's not already there.
632  * returns 0 on success.
633  */
634 
635 int
636 at_exit(function)
637 	exitlist_fn function;
638 {
639 	struct exitlist *ep;
640 
641 #ifdef INVARIANTS
642 	/* Be noisy if the programmer has lost track of things */
643 	if (rm_at_exit(function))
644 		printf("WARNING: exit callout entry (%p) already present\n",
645 		    function);
646 #endif
647 	ep = malloc(sizeof(*ep), M_ATEXIT, M_NOWAIT);
648 	if (ep == NULL)
649 		return (ENOMEM);
650 	ep->function = function;
651 	TAILQ_INSERT_TAIL(&exit_list, ep, next);
652 	return (0);
653 }
654 
655 /*
656  * Scan the exit callout list for the given item and remove it.
657  * Returns the number of items removed (0 or 1)
658  */
659 int
660 rm_at_exit(function)
661 	exitlist_fn function;
662 {
663 	struct exitlist *ep;
664 
665 	TAILQ_FOREACH(ep, &exit_list, next) {
666 		if (ep->function == function) {
667 			TAILQ_REMOVE(&exit_list, ep, next);
668 			free(ep, M_ATEXIT);
669 			return(1);
670 		}
671 	}
672 	return (0);
673 }
674 
675 void check_sigacts (void)
676 {
677 	struct proc *p = curproc;
678 	struct sigacts *pss;
679 	int s;
680 
681 	PROC_LOCK(p);
682 	if (p->p_procsig->ps_refcnt == 1 &&
683 	    p->p_sigacts != &p->p_addr->u_sigacts) {
684 		pss = p->p_sigacts;
685 		s = splhigh();
686 		p->p_addr->u_sigacts = *pss;
687 		p->p_sigacts = &p->p_addr->u_sigacts;
688 		splx(s);
689 		FREE(pss, M_SUBPROC);
690 	}
691 	PROC_UNLOCK(p);
692 }
693 
694