kern_sig.c (ea566832d78e0c81f7be7587ada8055876394558) | kern_sig.c (b4490c6e937e404832d1169ca7dbac3b2e712355) |
---|---|
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. --- 2213 unchanged lines hidden (view full) --- 2222 * an event, it goes back to run state. 2223 * Otherwise, process goes back to sleep state. 2224 */ 2225 p->p_flag &= ~P_STOPPED_SIG; 2226 PROC_SLOCK(p); 2227 if (p->p_numthreads == p->p_suspcount) { 2228 PROC_SUNLOCK(p); 2229 p->p_flag |= P_CONTINUED; | 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. --- 2213 unchanged lines hidden (view full) --- 2222 * an event, it goes back to run state. 2223 * Otherwise, process goes back to sleep state. 2224 */ 2225 p->p_flag &= ~P_STOPPED_SIG; 2226 PROC_SLOCK(p); 2227 if (p->p_numthreads == p->p_suspcount) { 2228 PROC_SUNLOCK(p); 2229 p->p_flag |= P_CONTINUED; |
2230 p->p_xstat = SIGCONT; | 2230 p->p_xsig = SIGCONT; |
2231 PROC_LOCK(p->p_pptr); 2232 childproc_continued(p); 2233 PROC_UNLOCK(p->p_pptr); 2234 PROC_SLOCK(p); 2235 } 2236 if (action == SIG_DFL) { 2237 thread_unsuspend(p); 2238 PROC_SUNLOCK(p); --- 62 unchanged lines hidden (view full) --- 2301 } 2302 2303 MPASS(action == SIG_DFL); 2304 2305 if (prop & SA_STOP) { 2306 if (p->p_flag & (P_PPWAIT|P_WEXIT)) 2307 goto out; 2308 p->p_flag |= P_STOPPED_SIG; | 2231 PROC_LOCK(p->p_pptr); 2232 childproc_continued(p); 2233 PROC_UNLOCK(p->p_pptr); 2234 PROC_SLOCK(p); 2235 } 2236 if (action == SIG_DFL) { 2237 thread_unsuspend(p); 2238 PROC_SUNLOCK(p); --- 62 unchanged lines hidden (view full) --- 2301 } 2302 2303 MPASS(action == SIG_DFL); 2304 2305 if (prop & SA_STOP) { 2306 if (p->p_flag & (P_PPWAIT|P_WEXIT)) 2307 goto out; 2308 p->p_flag |= P_STOPPED_SIG; |
2309 p->p_xstat = sig; | 2309 p->p_xsig = sig; |
2310 PROC_SLOCK(p); 2311 sig_suspend_threads(td, p, 1); 2312 if (p->p_numthreads == p->p_suspcount) { 2313 /* 2314 * only thread sending signal to another 2315 * process can reach here, if thread is sending 2316 * signal to its process, because thread does 2317 * not suspend itself here, p_numthreads 2318 * should never be equal to p_suspcount. 2319 */ 2320 thread_stopped(p); 2321 PROC_SUNLOCK(p); | 2310 PROC_SLOCK(p); 2311 sig_suspend_threads(td, p, 1); 2312 if (p->p_numthreads == p->p_suspcount) { 2313 /* 2314 * only thread sending signal to another 2315 * process can reach here, if thread is sending 2316 * signal to its process, because thread does 2317 * not suspend itself here, p_numthreads 2318 * should never be equal to p_suspcount. 2319 */ 2320 thread_stopped(p); 2321 PROC_SUNLOCK(p); |
2322 sigqueue_delete_proc(p, p->p_xstat); | 2322 sigqueue_delete_proc(p, p->p_xsig); |
2323 } else 2324 PROC_SUNLOCK(p); 2325 goto out; 2326 } 2327 } else { 2328 /* Not in "NORMAL" state. discard the signal. */ 2329 sigqueue_delete(sigqueue, sig); 2330 goto out; --- 155 unchanged lines hidden (view full) --- 2486 td->td_dbgflags &= ~TDB_XSIG; 2487 PROC_SUNLOCK(p); 2488 return (sig); 2489 } 2490 /* 2491 * Just make wait() to work, the last stopped thread 2492 * will win. 2493 */ | 2323 } else 2324 PROC_SUNLOCK(p); 2325 goto out; 2326 } 2327 } else { 2328 /* Not in "NORMAL" state. discard the signal. */ 2329 sigqueue_delete(sigqueue, sig); 2330 goto out; --- 155 unchanged lines hidden (view full) --- 2486 td->td_dbgflags &= ~TDB_XSIG; 2487 PROC_SUNLOCK(p); 2488 return (sig); 2489 } 2490 /* 2491 * Just make wait() to work, the last stopped thread 2492 * will win. 2493 */ |
2494 p->p_xstat = sig; | 2494 p->p_xsig = sig; |
2495 p->p_xthread = td; 2496 p->p_flag |= (P_STOPPED_SIG|P_STOPPED_TRACE); 2497 sig_suspend_threads(td, p, 0); 2498 if ((td->td_dbgflags & TDB_STOPATFORK) != 0) { 2499 td->td_dbgflags &= ~TDB_STOPATFORK; 2500 cv_broadcast(&p->p_dbgwait); 2501 } 2502stopme: --- 176 unchanged lines hidden (view full) --- 2679 mtx_unlock(&ps->ps_mtx); 2680 newsig = ptracestop(td, sig); 2681 mtx_lock(&ps->ps_mtx); 2682 2683 if (sig != newsig) { 2684 2685 /* 2686 * If parent wants us to take the signal, | 2495 p->p_xthread = td; 2496 p->p_flag |= (P_STOPPED_SIG|P_STOPPED_TRACE); 2497 sig_suspend_threads(td, p, 0); 2498 if ((td->td_dbgflags & TDB_STOPATFORK) != 0) { 2499 td->td_dbgflags &= ~TDB_STOPATFORK; 2500 cv_broadcast(&p->p_dbgwait); 2501 } 2502stopme: --- 176 unchanged lines hidden (view full) --- 2679 mtx_unlock(&ps->ps_mtx); 2680 newsig = ptracestop(td, sig); 2681 mtx_lock(&ps->ps_mtx); 2682 2683 if (sig != newsig) { 2684 2685 /* 2686 * If parent wants us to take the signal, |
2687 * then it will leave it in p->p_xstat; | 2687 * then it will leave it in p->p_xsig; |
2688 * otherwise we just look for signals again. 2689 */ 2690 if (newsig == 0) 2691 continue; 2692 sig = newsig; 2693 2694 /* 2695 * Put the new signal into td_sigqueue. If the --- 60 unchanged lines hidden (view full) --- 2756 if (p->p_flag & (P_TRACED|P_WEXIT) || 2757 (p->p_pgrp->pg_jobc == 0 && 2758 prop & SA_TTYSTOP)) 2759 break; /* == ignore */ 2760 mtx_unlock(&ps->ps_mtx); 2761 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, 2762 &p->p_mtx.lock_object, "Catching SIGSTOP"); 2763 p->p_flag |= P_STOPPED_SIG; | 2688 * otherwise we just look for signals again. 2689 */ 2690 if (newsig == 0) 2691 continue; 2692 sig = newsig; 2693 2694 /* 2695 * Put the new signal into td_sigqueue. If the --- 60 unchanged lines hidden (view full) --- 2756 if (p->p_flag & (P_TRACED|P_WEXIT) || 2757 (p->p_pgrp->pg_jobc == 0 && 2758 prop & SA_TTYSTOP)) 2759 break; /* == ignore */ 2760 mtx_unlock(&ps->ps_mtx); 2761 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, 2762 &p->p_mtx.lock_object, "Catching SIGSTOP"); 2763 p->p_flag |= P_STOPPED_SIG; |
2764 p->p_xstat = sig; | 2764 p->p_xsig = sig; |
2765 PROC_SLOCK(p); 2766 sig_suspend_threads(td, p, 0); 2767 thread_suspend_switch(td, p); 2768 PROC_SUNLOCK(p); 2769 mtx_lock(&ps->ps_mtx); 2770 break; 2771 } else if (prop & SA_IGNORE) { 2772 /* --- 187 unchanged lines hidden (view full) --- 2960 log(LOG_INFO, 2961 "pid %d (%s), uid %d: exited on signal %d%s\n", 2962 p->p_pid, p->p_comm, 2963 td->td_ucred ? td->td_ucred->cr_uid : -1, 2964 sig &~ WCOREFLAG, 2965 sig & WCOREFLAG ? " (core dumped)" : ""); 2966 } else 2967 PROC_UNLOCK(p); | 2765 PROC_SLOCK(p); 2766 sig_suspend_threads(td, p, 0); 2767 thread_suspend_switch(td, p); 2768 PROC_SUNLOCK(p); 2769 mtx_lock(&ps->ps_mtx); 2770 break; 2771 } else if (prop & SA_IGNORE) { 2772 /* --- 187 unchanged lines hidden (view full) --- 2960 log(LOG_INFO, 2961 "pid %d (%s), uid %d: exited on signal %d%s\n", 2962 p->p_pid, p->p_comm, 2963 td->td_ucred ? td->td_ucred->cr_uid : -1, 2964 sig &~ WCOREFLAG, 2965 sig & WCOREFLAG ? " (core dumped)" : ""); 2966 } else 2967 PROC_UNLOCK(p); |
2968 exit1(td, W_EXITCODE(0, sig)); | 2968 exit1(td, 0, sig); |
2969 /* NOTREACHED */ 2970} 2971 2972/* 2973 * Send queued SIGCHLD to parent when child process's state 2974 * is changed. 2975 */ 2976static void --- 38 unchanged lines hidden (view full) --- 3015 sigparent(p, reason, sig); 3016 } else 3017 mtx_unlock(&ps->ps_mtx); 3018} 3019 3020void 3021childproc_stopped(struct proc *p, int reason) 3022{ | 2969 /* NOTREACHED */ 2970} 2971 2972/* 2973 * Send queued SIGCHLD to parent when child process's state 2974 * is changed. 2975 */ 2976static void --- 38 unchanged lines hidden (view full) --- 3015 sigparent(p, reason, sig); 3016 } else 3017 mtx_unlock(&ps->ps_mtx); 3018} 3019 3020void 3021childproc_stopped(struct proc *p, int reason) 3022{ |
3023 /* p_xstat is a plain signal number, not a full wait() status here. */ 3024 childproc_jobstate(p, reason, p->p_xstat); | 3023 3024 childproc_jobstate(p, reason, p->p_xsig); |
3025} 3026 3027void 3028childproc_continued(struct proc *p) 3029{ 3030 childproc_jobstate(p, CLD_CONTINUED, SIGCONT); 3031} 3032 3033void 3034childproc_exited(struct proc *p) 3035{ | 3025} 3026 3027void 3028childproc_continued(struct proc *p) 3029{ 3030 childproc_jobstate(p, CLD_CONTINUED, SIGCONT); 3031} 3032 3033void 3034childproc_exited(struct proc *p) 3035{ |
3036 int reason; 3037 int xstat = p->p_xstat; /* convert to int */ 3038 int status; | 3036 int reason, status; |
3039 | 3037 |
3040 if (WCOREDUMP(xstat)) 3041 reason = CLD_DUMPED, status = WTERMSIG(xstat); 3042 else if (WIFSIGNALED(xstat)) 3043 reason = CLD_KILLED, status = WTERMSIG(xstat); 3044 else 3045 reason = CLD_EXITED, status = WEXITSTATUS(xstat); | 3038 if (WCOREDUMP(p->p_xsig)) { 3039 reason = CLD_DUMPED; 3040 status = WTERMSIG(p->p_xsig); 3041 } else if (WIFSIGNALED(p->p_xsig)) { 3042 reason = CLD_KILLED; 3043 status = WTERMSIG(p->p_xsig); 3044 } else { 3045 reason = CLD_EXITED; 3046 status = p->p_xexit; 3047 } |
3046 /* 3047 * XXX avoid calling wakeup(p->p_pptr), the work is 3048 * done in exit1(). 3049 */ 3050 sigparent(p, reason, status); 3051} 3052 3053/* --- 501 unchanged lines hidden --- | 3048 /* 3049 * XXX avoid calling wakeup(p->p_pptr), the work is 3050 * done in exit1(). 3051 */ 3052 sigparent(p, reason, status); 3053} 3054 3055/* --- 501 unchanged lines hidden --- |