kern_exit.c (91066) | kern_exit.c (91140) |
---|---|
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. --- 22 unchanged lines hidden (view full) --- 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 | 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. --- 22 unchanged lines hidden (view full) --- 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: head/sys/kern/kern_exit.c 91066 2002-02-22 13:32:01Z phk $ | 39 * $FreeBSD: head/sys/kern/kern_exit.c 91140 2002-02-23 11:12:57Z tanimura $ |
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> --- 72 unchanged lines hidden (view full) --- 120 register struct thread *td; 121 int rv; 122{ 123 struct proc *p = td->td_proc; 124 register struct proc *q, *nq; 125 register struct vmspace *vm; 126 struct vnode *vtmp; 127 struct exitlist *ep; | 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> --- 72 unchanged lines hidden (view full) --- 120 register struct thread *td; 121 int rv; 122{ 123 struct proc *p = td->td_proc; 124 register struct proc *q, *nq; 125 register struct vmspace *vm; 126 struct vnode *vtmp; 127 struct exitlist *ep; |
128 struct vnode *ttyvp; 129 struct tty *tp; |
|
128 129 GIANT_REQUIRED; 130 131 if (p->p_pid == 1) { 132 printf("init died (signal %d, exit %d)\n", 133 WTERMSIG(rv), WEXITSTATUS(rv)); 134 panic("Going nowhere without my init!"); 135 } --- 45 unchanged lines hidden (view full) --- 181 PROC_UNLOCK(p); 182 if (timevalisset(&p->p_realtimer.it_value)) 183 callout_stop(&p->p_itcallout); 184 185 /* 186 * Reset any sigio structures pointing to us as a result of 187 * F_SETOWN with our pid. 188 */ | 130 131 GIANT_REQUIRED; 132 133 if (p->p_pid == 1) { 134 printf("init died (signal %d, exit %d)\n", 135 WTERMSIG(rv), WEXITSTATUS(rv)); 136 panic("Going nowhere without my init!"); 137 } --- 45 unchanged lines hidden (view full) --- 183 PROC_UNLOCK(p); 184 if (timevalisset(&p->p_realtimer.it_value)) 185 callout_stop(&p->p_itcallout); 186 187 /* 188 * Reset any sigio structures pointing to us as a result of 189 * F_SETOWN with our pid. 190 */ |
191 PROC_LOCK(p); |
|
189 funsetownlst(&p->p_sigiolst); | 192 funsetownlst(&p->p_sigiolst); |
193 PROC_UNLOCK(p); |
|
190 191 /* 192 * Close open files and release open-file table. 193 * This may block! 194 */ 195 fdfree(td); /* XXXKSE *//* may not be the one in proc */ 196 197 /* --- 24 unchanged lines hidden (view full) --- 222 shmexit(p); 223 pmap_remove_pages(vmspace_pmap(vm), VM_MIN_ADDRESS, 224 VM_MAXUSER_ADDRESS); 225 (void) vm_map_remove(&vm->vm_map, VM_MIN_ADDRESS, 226 VM_MAXUSER_ADDRESS); 227 vm->vm_freer = p; 228 } 229 | 194 195 /* 196 * Close open files and release open-file table. 197 * This may block! 198 */ 199 fdfree(td); /* XXXKSE *//* may not be the one in proc */ 200 201 /* --- 24 unchanged lines hidden (view full) --- 226 shmexit(p); 227 pmap_remove_pages(vmspace_pmap(vm), VM_MIN_ADDRESS, 228 VM_MAXUSER_ADDRESS); 229 (void) vm_map_remove(&vm->vm_map, VM_MIN_ADDRESS, 230 VM_MAXUSER_ADDRESS); 231 vm->vm_freer = p; 232 } 233 |
230 PROC_LOCK(p); | 234 PGRPSESS_XLOCK(); |
231 if (SESS_LEADER(p)) { | 235 if (SESS_LEADER(p)) { |
232 register struct session *sp = p->p_session; | 236 register struct session *sp; |
233 | 237 |
234 PROC_UNLOCK(p); | 238 sp = p->p_session; |
235 if (sp->s_ttyvp) { 236 /* 237 * Controlling process. 238 * Signal foreground pgrp, 239 * drain controlling terminal 240 * and revoke access to controlling terminal. 241 */ 242 if (sp->s_ttyp && (sp->s_ttyp->t_session == sp)) { | 239 if (sp->s_ttyvp) { 240 /* 241 * Controlling process. 242 * Signal foreground pgrp, 243 * drain controlling terminal 244 * and revoke access to controlling terminal. 245 */ 246 if (sp->s_ttyp && (sp->s_ttyp->t_session == sp)) { |
243 if (sp->s_ttyp->t_pgrp) | 247 tp = sp->s_ttyp; 248 if (sp->s_ttyp->t_pgrp) { 249 PGRP_LOCK(sp->s_ttyp->t_pgrp); |
244 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1); | 250 pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1); |
245 (void) ttywait(sp->s_ttyp); | 251 PGRP_UNLOCK(sp->s_ttyp->t_pgrp); 252 } 253 /* XXX tp should be locked. */ 254 (void) ttywait(tp); |
246 /* 247 * The tty could have been revoked 248 * if we blocked. 249 */ | 255 /* 256 * The tty could have been revoked 257 * if we blocked. 258 */ |
250 if (sp->s_ttyvp) 251 VOP_REVOKE(sp->s_ttyvp, REVOKEALL); | 259 if (sp->s_ttyvp) { 260 ttyvp = sp->s_ttyvp; 261 SESS_LOCK(p->p_session); 262 sp->s_ttyvp = NULL; 263 SESS_UNLOCK(p->p_session); 264 PGRPSESS_XUNLOCK(); 265 VOP_REVOKE(ttyvp, REVOKEALL); 266 PGRPSESS_XLOCK(); 267 vrele(ttyvp); 268 } |
252 } | 269 } |
253 if (sp->s_ttyvp) 254 vrele(sp->s_ttyvp); 255 sp->s_ttyvp = NULL; | 270 if (sp->s_ttyvp) { 271 ttyvp = sp->s_ttyvp; 272 SESS_LOCK(p->p_session); 273 sp->s_ttyvp = NULL; 274 SESS_UNLOCK(p->p_session); 275 vrele(ttyvp); 276 } |
256 /* 257 * s_ttyp is not zero'd; we use this to indicate 258 * that the session once had a controlling terminal. 259 * (for logging and informational purposes) 260 */ 261 } | 277 /* 278 * s_ttyp is not zero'd; we use this to indicate 279 * that the session once had a controlling terminal. 280 * (for logging and informational purposes) 281 */ 282 } |
283 SESS_LOCK(p->p_session); |
|
262 sp->s_leader = NULL; | 284 sp->s_leader = NULL; |
263 } else 264 PROC_UNLOCK(p); | 285 SESS_UNLOCK(p->p_session); 286 } |
265 fixjobc(p, p->p_pgrp, 0); | 287 fixjobc(p, p->p_pgrp, 0); |
288 PGRPSESS_XUNLOCK(); |
|
266 (void)acct_process(td); 267#ifdef KTRACE 268 /* 269 * release trace file 270 */ 271 p->p_traceflag = 0; /* don't trace the vrele() */ 272 if ((vtmp = p->p_tracep) != NULL) { 273 p->p_tracep = NULL; --- 30 unchanged lines hidden (view full) --- 304 /* 305 * Traced processes are killed 306 * since their existence means someone is screwing up. 307 */ 308 if (q->p_flag & P_TRACED) { 309 q->p_flag &= ~P_TRACED; 310 psignal(q, SIGKILL); 311 } | 289 (void)acct_process(td); 290#ifdef KTRACE 291 /* 292 * release trace file 293 */ 294 p->p_traceflag = 0; /* don't trace the vrele() */ 295 if ((vtmp = p->p_tracep) != NULL) { 296 p->p_tracep = NULL; --- 30 unchanged lines hidden (view full) --- 327 /* 328 * Traced processes are killed 329 * since their existence means someone is screwing up. 330 */ 331 if (q->p_flag & P_TRACED) { 332 q->p_flag &= ~P_TRACED; 333 psignal(q, SIGKILL); 334 } |
312 PROC_UNLOCK(q); | 335 PROC_UNLOCK(q); |
313 } 314 315 /* 316 * Save exit status and final rusage info, adding in child rusage 317 * info and self times. 318 */ 319 p->p_xstat = rv; 320 *p->p_ru = p->p_stats->p_ru; --- 12 unchanged lines hidden (view full) --- 333 binuptime(PCPU_PTR(switchtime)); 334 PCPU_SET(switchticks, ticks); 335 mtx_unlock_spin(&sched_lock); 336 337 /* 338 * notify interested parties of our demise. 339 */ 340 PROC_LOCK(p); | 336 } 337 338 /* 339 * Save exit status and final rusage info, adding in child rusage 340 * info and self times. 341 */ 342 p->p_xstat = rv; 343 *p->p_ru = p->p_stats->p_ru; --- 12 unchanged lines hidden (view full) --- 356 binuptime(PCPU_PTR(switchtime)); 357 PCPU_SET(switchticks, ticks); 358 mtx_unlock_spin(&sched_lock); 359 360 /* 361 * notify interested parties of our demise. 362 */ 363 PROC_LOCK(p); |
364 PROC_LOCK(p->p_pptr); |
|
341 KNOTE(&p->p_klist, NOTE_EXIT); 342 343 /* 344 * Notify parent that we're gone. If parent has the PS_NOCLDWAIT 345 * flag set, notify process 1 instead (and hope it will handle 346 * this situation). 347 */ 348 if (p->p_pptr->p_procsig->ps_flag & PS_NOCLDWAIT) { 349 struct proc *pp = p->p_pptr; | 365 KNOTE(&p->p_klist, NOTE_EXIT); 366 367 /* 368 * Notify parent that we're gone. If parent has the PS_NOCLDWAIT 369 * flag set, notify process 1 instead (and hope it will handle 370 * this situation). 371 */ 372 if (p->p_pptr->p_procsig->ps_flag & PS_NOCLDWAIT) { 373 struct proc *pp = p->p_pptr; |
374 PROC_UNLOCK(pp); |
|
350 proc_reparent(p, initproc); | 375 proc_reparent(p, initproc); |
376 PROC_LOCK(p->p_pptr); |
|
351 /* 352 * If this was the last child of our parent, notify 353 * parent, so in case he was wait(2)ing, he will 354 * continue. 355 */ 356 if (LIST_EMPTY(&pp->p_children)) 357 wakeup((caddr_t)pp); 358 } 359 | 377 /* 378 * If this was the last child of our parent, notify 379 * parent, so in case he was wait(2)ing, he will 380 * continue. 381 */ 382 if (LIST_EMPTY(&pp->p_children)) 383 wakeup((caddr_t)pp); 384 } 385 |
360 PROC_LOCK(p->p_pptr); | |
361 if (p->p_sigparent && p->p_pptr != initproc) 362 psignal(p->p_pptr, p->p_sigparent); 363 else 364 psignal(p->p_pptr, SIGCHLD); 365 PROC_UNLOCK(p->p_pptr); 366 367 /* 368 * If this is a kthread, then wakeup anyone waiting for it to exit. --- 106 unchanged lines hidden (view full) --- 475 int compat; 476{ 477 register int nfound; 478 register struct proc *q, *p, *t; 479 int status, error; 480 481 mtx_lock(&Giant); 482 q = td->td_proc; | 386 if (p->p_sigparent && p->p_pptr != initproc) 387 psignal(p->p_pptr, p->p_sigparent); 388 else 389 psignal(p->p_pptr, SIGCHLD); 390 PROC_UNLOCK(p->p_pptr); 391 392 /* 393 * If this is a kthread, then wakeup anyone waiting for it to exit. --- 106 unchanged lines hidden (view full) --- 500 int compat; 501{ 502 register int nfound; 503 register struct proc *q, *p, *t; 504 int status, error; 505 506 mtx_lock(&Giant); 507 q = td->td_proc; |
483 if (uap->pid == 0) | 508 if (uap->pid == 0) { 509 PROC_LOCK(q); |
484 uap->pid = -q->p_pgid; | 510 uap->pid = -q->p_pgid; |
511 PROC_UNLOCK(q); 512 } |
|
485 if (uap->options &~ (WUNTRACED|WNOHANG|WLINUXCLONE)) { 486 error = EINVAL; 487 goto done2; 488 } 489loop: 490 nfound = 0; 491 sx_slock(&proctree_lock); 492 LIST_FOREACH(p, &q->p_children, p_sibling) { | 513 if (uap->options &~ (WUNTRACED|WNOHANG|WLINUXCLONE)) { 514 error = EINVAL; 515 goto done2; 516 } 517loop: 518 nfound = 0; 519 sx_slock(&proctree_lock); 520 LIST_FOREACH(p, &q->p_children, p_sibling) { |
521 PROC_LOCK(p); |
|
493 if (uap->pid != WAIT_ANY && | 522 if (uap->pid != WAIT_ANY && |
494 p->p_pid != uap->pid && p->p_pgid != -uap->pid) | 523 p->p_pid != uap->pid && p->p_pgid != -uap->pid) { 524 PROC_UNLOCK(p); |
495 continue; | 525 continue; |
526 } |
|
496 497 /* 498 * This special case handles a kthread spawned by linux_clone 499 * (see linux_misc.c). The linux_wait4 and linux_waitpid 500 * functions need to be able to distinguish between waiting 501 * on a process and waiting on a thread. It is a thread if 502 * p_sigparent is not SIGCHLD, and the WLINUXCLONE option 503 * signifies we want to wait for threads and not processes. 504 */ | 527 528 /* 529 * This special case handles a kthread spawned by linux_clone 530 * (see linux_misc.c). The linux_wait4 and linux_waitpid 531 * functions need to be able to distinguish between waiting 532 * on a process and waiting on a thread. It is a thread if 533 * p_sigparent is not SIGCHLD, and the WLINUXCLONE option 534 * signifies we want to wait for threads and not processes. 535 */ |
505 PROC_LOCK(p); | |
506 if ((p->p_sigparent != SIGCHLD) ^ 507 ((uap->options & WLINUXCLONE) != 0)) { 508 PROC_UNLOCK(p); 509 continue; 510 } 511 512 nfound++; 513 mtx_lock_spin(&sched_lock); --- 227 unchanged lines hidden --- | 536 if ((p->p_sigparent != SIGCHLD) ^ 537 ((uap->options & WLINUXCLONE) != 0)) { 538 PROC_UNLOCK(p); 539 continue; 540 } 541 542 nfound++; 543 mtx_lock_spin(&sched_lock); --- 227 unchanged lines hidden --- |