kern_sig.c (50754) | kern_sig.c (51791) |
---|---|
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_sig.c 8.7 (Berkeley) 4/18/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_sig.c 8.7 (Berkeley) 4/18/94 |
39 * $FreeBSD: head/sys/kern/kern_sig.c 50754 1999-09-01 16:21:57Z sef $ | 39 * $FreeBSD: head/sys/kern/kern_sig.c 51791 1999-09-29 15:03:48Z marcel $ |
40 */ 41 42#include "opt_compat.h" 43#include "opt_ktrace.h" 44 | 40 */ 41 42#include "opt_compat.h" 43#include "opt_ktrace.h" 44 |
45#define SIGPROP /* include signal properties table */ | |
46#include <sys/param.h> 47#include <sys/kernel.h> 48#include <sys/sysproto.h> 49#include <sys/signalvar.h> 50#include <sys/resourcevar.h> 51#include <sys/namei.h> 52#include <sys/vnode.h> 53#include <sys/proc.h> --- 9 unchanged lines hidden (view full) --- 63#include <sys/sysctl.h> 64#include <sys/malloc.h> 65 66#include <machine/cpu.h> 67#ifdef SMP 68#include <machine/smp.h> 69#endif 70 | 45#include <sys/param.h> 46#include <sys/kernel.h> 47#include <sys/sysproto.h> 48#include <sys/signalvar.h> 49#include <sys/resourcevar.h> 50#include <sys/namei.h> 51#include <sys/vnode.h> 52#include <sys/proc.h> --- 9 unchanged lines hidden (view full) --- 62#include <sys/sysctl.h> 63#include <sys/malloc.h> 64 65#include <machine/cpu.h> 66#ifdef SMP 67#include <machine/smp.h> 68#endif 69 |
71static int killpg1 __P((struct proc *cp, int signum, int pgid, int all)); 72static void setsigvec __P((struct proc *p, int signum, struct sigaction *sa)); | 70static int sigprop __P((int sig)); 71static int sig_ffs __P((sigset_t *set)); 72static int killpg1 __P((struct proc *cp, int sig, int pgid, int all)); 73static int do_sigaction __P((struct proc *p, int sig, struct sigaction *act, 74 struct sigaction *oact)); 75static int do_sigprocmask __P((struct proc *p, int how, sigset_t *set, 76 sigset_t *oset)); |
73static void stop __P((struct proc *)); 74static char *expand_name __P((const char *, uid_t, pid_t)); 75static int coredump __P((struct proc *)); 76 77static int kern_logsigexit = 1; 78SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW, 79 &kern_logsigexit, 0, 80 "Log processes quitting on abnormal signals to syslog(3)"); 81 82/* | 77static void stop __P((struct proc *)); 78static char *expand_name __P((const char *, uid_t, pid_t)); 79static int coredump __P((struct proc *)); 80 81static int kern_logsigexit = 1; 82SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW, 83 &kern_logsigexit, 0, 84 "Log processes quitting on abnormal signals to syslog(3)"); 85 86/* |
83 * Can process p, with pcred pc, send the signal signum to process q? | 87 * Can process p, with pcred pc, send the signal sig to process q? |
84 */ | 88 */ |
85#define CANSIGNAL(p, pc, q, signum) \ | 89#define CANSIGNAL(p, pc, q, sig) \ |
86 (PRISON_CHECK(p, q) && ((pc)->pc_ucred->cr_uid == 0 || \ 87 (pc)->p_ruid == (q)->p_cred->p_ruid || \ 88 (pc)->pc_ucred->cr_uid == (q)->p_cred->p_ruid || \ 89 (pc)->p_ruid == (q)->p_ucred->cr_uid || \ 90 (pc)->pc_ucred->cr_uid == (q)->p_ucred->cr_uid || \ | 90 (PRISON_CHECK(p, q) && ((pc)->pc_ucred->cr_uid == 0 || \ 91 (pc)->p_ruid == (q)->p_cred->p_ruid || \ 92 (pc)->pc_ucred->cr_uid == (q)->p_cred->p_ruid || \ 93 (pc)->p_ruid == (q)->p_ucred->cr_uid || \ 94 (pc)->pc_ucred->cr_uid == (q)->p_ucred->cr_uid || \ |
91 ((signum) == SIGCONT && (q)->p_session == (p)->p_session))) | 95 ((sig) == SIGCONT && (q)->p_session == (p)->p_session))) |
92 93/* 94 * Policy -- Can real uid ruid with ucred uc send a signal to process q? 95 */ 96#define CANSIGIO(ruid, uc, q) \ 97 ((uc)->cr_uid == 0 || \ 98 (ruid) == (q)->p_cred->p_ruid || \ 99 (uc)->cr_uid == (q)->p_cred->p_ruid || \ 100 (ruid) == (q)->p_ucred->cr_uid || \ 101 (uc)->cr_uid == (q)->p_ucred->cr_uid) 102 103int sugid_coredump; 104SYSCTL_INT(_kern, OID_AUTO, sugid_coredump, CTLFLAG_RW, 105 &sugid_coredump, 0, "Enable coredumping set user/group ID processes"); 106 | 96 97/* 98 * Policy -- Can real uid ruid with ucred uc send a signal to process q? 99 */ 100#define CANSIGIO(ruid, uc, q) \ 101 ((uc)->cr_uid == 0 || \ 102 (ruid) == (q)->p_cred->p_ruid || \ 103 (uc)->cr_uid == (q)->p_cred->p_ruid || \ 104 (ruid) == (q)->p_ucred->cr_uid || \ 105 (uc)->cr_uid == (q)->p_ucred->cr_uid) 106 107int sugid_coredump; 108SYSCTL_INT(_kern, OID_AUTO, sugid_coredump, CTLFLAG_RW, 109 &sugid_coredump, 0, "Enable coredumping set user/group ID processes"); 110 |
111/* 112 * Signal properties and actions. 113 * The array below categorizes the signals and their default actions 114 * according to the following properties: 115 */ 116#define SA_KILL 0x01 /* terminates process by default */ 117#define SA_CORE 0x02 /* ditto and coredumps */ 118#define SA_STOP 0x04 /* suspend process */ 119#define SA_TTYSTOP 0x08 /* ditto, from tty */ 120#define SA_IGNORE 0x10 /* ignore by default */ 121#define SA_CONT 0x20 /* continue if suspended */ 122#define SA_CANTMASK 0x40 /* non-maskable, catchable */ 123 124static int sigproptbl[NSIG] = { 125 SA_KILL, /* SIGHUP */ 126 SA_KILL, /* SIGINT */ 127 SA_KILL|SA_CORE, /* SIGQUIT */ 128 SA_KILL|SA_CORE, /* SIGILL */ 129 SA_KILL|SA_CORE, /* SIGTRAP */ 130 SA_KILL|SA_CORE, /* SIGABRT */ 131 SA_KILL|SA_CORE, /* SIGEMT */ 132 SA_KILL|SA_CORE, /* SIGFPE */ 133 SA_KILL, /* SIGKILL */ 134 SA_KILL|SA_CORE, /* SIGBUS */ 135 SA_KILL|SA_CORE, /* SIGSEGV */ 136 SA_KILL|SA_CORE, /* SIGSYS */ 137 SA_KILL, /* SIGPIPE */ 138 SA_KILL, /* SIGALRM */ 139 SA_KILL, /* SIGTERM */ 140 SA_IGNORE, /* SIGURG */ 141 SA_STOP, /* SIGSTOP */ 142 SA_STOP|SA_TTYSTOP, /* SIGTSTP */ 143 SA_IGNORE|SA_CONT, /* SIGCONT */ 144 SA_IGNORE, /* SIGCHLD */ 145 SA_STOP|SA_TTYSTOP, /* SIGTTIN */ 146 SA_STOP|SA_TTYSTOP, /* SIGTTOU */ 147 SA_IGNORE, /* SIGIO */ 148 SA_KILL, /* SIGXCPU */ 149 SA_KILL, /* SIGXFSZ */ 150 SA_KILL, /* SIGVTALRM */ 151 SA_KILL, /* SIGPROF */ 152 SA_IGNORE, /* SIGWINCH */ 153 SA_IGNORE, /* SIGINFO */ 154 SA_KILL, /* SIGUSR1 */ 155 SA_KILL, /* SIGUSR2 */ 156}; 157 158extern __inline int sigprop(int sig) 159{ 160 if (sig > 0 && sig < NSIG) 161 return (sigproptbl[_SIG_IDX(sig)]); 162 else 163 return (0); 164} 165 166extern __inline int sig_ffs(sigset_t *set) 167{ 168 int i; 169 170 for (i = 0; i < _SIG_WORDS; i++) { 171 if (set->__bits[i]) 172 return (ffs(set->__bits[i]) + (i * 32)); 173 } 174 return (0); 175} 176 177/* 178 * do_sigaction 179 * sigaction 180 * osigaction 181 */ 182static int 183do_sigaction(p, sig, act, oact) 184 struct proc *p; 185 register int sig; 186 struct sigaction *act, *oact; 187{ 188 register struct sigacts *ps = p->p_sigacts; 189 190 if (sig <= 0 || sig > _SIG_MAXSIG) 191 return (EINVAL); 192 193 if (oact) { 194 oact->sa_handler = ps->ps_sigact[_SIG_IDX(sig)]; 195 oact->sa_mask = ps->ps_catchmask[_SIG_IDX(sig)]; 196 oact->sa_flags = 0; 197 if (SIGISMEMBER(ps->ps_sigonstack, sig)) 198 oact->sa_flags |= SA_ONSTACK; 199 if (!SIGISMEMBER(ps->ps_sigintr, sig)) 200 oact->sa_flags |= SA_RESTART; 201 if (SIGISMEMBER(ps->ps_sigreset, sig)) 202 oact->sa_flags |= SA_RESETHAND; 203 if (SIGISMEMBER(ps->ps_signodefer, sig)) 204 oact->sa_flags |= SA_NODEFER; 205 if (SIGISMEMBER(ps->ps_siginfo, sig)) 206 oact->sa_flags |= SA_SIGINFO; 207 if (sig == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDSTOP) 208 oact->sa_flags |= SA_NOCLDSTOP; 209 if (sig == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDWAIT) 210 oact->sa_flags |= SA_NOCLDWAIT; 211 } 212 if (act) { 213 if ((sig == SIGKILL || sig == SIGSTOP) && 214 act->sa_handler != SIG_DFL) 215 return (EINVAL); 216 217 /* 218 * Change setting atomically. 219 */ 220 (void) splhigh(); 221 222 ps->ps_catchmask[_SIG_IDX(sig)] = act->sa_mask; 223 SIG_CANTMASK(ps->ps_catchmask[_SIG_IDX(sig)]); 224 if (act->sa_flags & SA_SIGINFO) { 225 ps->ps_sigact[_SIG_IDX(sig)] = act->sa_handler; 226 SIGADDSET(ps->ps_siginfo, sig); 227 } 228 else { 229 ps->ps_sigact[_SIG_IDX(sig)] = 230 (__sighandler_t *)act->sa_sigaction; 231 SIGDELSET(ps->ps_siginfo, sig); 232 } 233 if (!(act->sa_flags & SA_RESTART)) 234 SIGADDSET(ps->ps_sigintr, sig); 235 else 236 SIGDELSET(ps->ps_sigintr, sig); 237 if (act->sa_flags & SA_ONSTACK) 238 SIGADDSET(ps->ps_sigonstack, sig); 239 else 240 SIGDELSET(ps->ps_sigonstack, sig); 241 if (act->sa_flags & SA_RESETHAND) 242 SIGADDSET(ps->ps_sigreset, sig); 243 else 244 SIGDELSET(ps->ps_sigreset, sig); 245 if (act->sa_flags & SA_NODEFER) 246 SIGADDSET(ps->ps_signodefer, sig); 247 else 248 SIGDELSET(ps->ps_signodefer, sig); 249#ifdef COMPAT_SUNOS 250 if (act->sa_flags & SA_USERTRAMP) 251 SIGADDSET(ps->ps_usertramp, sig); 252 else 253 SIGDELSET(ps->ps_usertramp, seg); 254#endif 255 if (sig == SIGCHLD) { 256 if (act->sa_flags & SA_NOCLDSTOP) 257 p->p_procsig->ps_flag |= P_NOCLDSTOP; 258 else 259 p->p_procsig->ps_flag &= ~P_NOCLDSTOP; 260 if (act->sa_flags & SA_NOCLDWAIT) { 261 /* 262 * Paranoia: since SA_NOCLDWAIT is implemented 263 * by reparenting the dying child to PID 1 (and 264 * trust it to reap the zombie), PID 1 itself 265 * is forbidden to set SA_NOCLDWAIT. 266 */ 267 if (p->p_pid == 1) 268 p->p_procsig->ps_flag &= ~P_NOCLDWAIT; 269 else 270 p->p_procsig->ps_flag |= P_NOCLDWAIT; 271 } else 272 p->p_procsig->ps_flag &= ~P_NOCLDWAIT; 273 } 274 /* 275 * Set bit in p_sigignore for signals that are set to SIG_IGN, 276 * and for signals set to SIG_DFL where the default is to 277 * ignore. However, don't put SIGCONT in p_sigignore, as we 278 * have to restart the process. 279 */ 280 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN || 281 (sigprop(sig) & SA_IGNORE && 282 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)) { 283 /* never to be seen again */ 284 SIGDELSET(p->p_siglist, sig); 285 if (sig != SIGCONT) 286 /* easier in psignal */ 287 SIGADDSET(p->p_sigignore, sig); 288 SIGDELSET(p->p_sigcatch, sig); 289 } 290 else { 291 SIGDELSET(p->p_sigignore, sig); 292 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL) 293 SIGDELSET(p->p_sigcatch, sig); 294 else 295 SIGADDSET(p->p_sigcatch, sig); 296 } 297 298 (void) spl0(); 299 } 300 return (0); 301} 302 |
|
107#ifndef _SYS_SYSPROTO_H_ 108struct sigaction_args { | 303#ifndef _SYS_SYSPROTO_H_ 304struct sigaction_args { |
109 int signum; 110 struct sigaction *nsa; 111 struct sigaction *osa; | 305 int sig; 306 struct sigaction *act; 307 struct sigaction *oact; |
112}; 113#endif 114/* ARGSUSED */ 115int 116sigaction(p, uap) 117 struct proc *p; 118 register struct sigaction_args *uap; 119{ | 308}; 309#endif 310/* ARGSUSED */ 311int 312sigaction(p, uap) 313 struct proc *p; 314 register struct sigaction_args *uap; 315{ |
120 struct sigaction vec; 121 register struct sigaction *sa; 122 register struct sigacts *ps = p->p_sigacts; 123 register int signum; 124 int bit, error; | 316 struct sigaction act, oact; 317 register struct sigaction *actp, *oactp; 318 int error; |
125 | 319 |
126 signum = uap->signum; 127 if (signum <= 0 || signum >= NSIG) 128 return (EINVAL); 129 sa = &vec; 130 if (uap->osa) { 131 bit = sigmask(signum); 132 if ((ps->ps_siginfo & bit) != 0) 133 sa->sa_sigaction = 134 (__siginfohandler_t *)ps->ps_sigact[signum]; 135 else 136 sa->sa_handler = ps->ps_sigact[signum]; 137 sa->sa_mask = ps->ps_catchmask[signum]; 138 sa->sa_flags = 0; 139 if ((ps->ps_sigonstack & bit) != 0) 140 sa->sa_flags |= SA_ONSTACK; 141 if ((ps->ps_sigintr & bit) == 0) 142 sa->sa_flags |= SA_RESTART; 143 if ((ps->ps_sigreset & bit) != 0) 144 sa->sa_flags |= SA_RESETHAND; 145 if ((ps->ps_signodefer & bit) != 0) 146 sa->sa_flags |= SA_NODEFER; 147 if ((ps->ps_siginfo & bit) != 0) 148 sa->sa_flags |= SA_SIGINFO; 149 if (signum == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDSTOP) 150 sa->sa_flags |= SA_NOCLDSTOP; 151 if (signum == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDWAIT) 152 sa->sa_flags |= SA_NOCLDWAIT; 153 if ((error = copyout((caddr_t)sa, (caddr_t)uap->osa, 154 sizeof (vec)))) | 320 p->p_flag |= P_NEWSIGSET; 321 322 actp = (uap->act) ? &act : NULL; 323 oactp = (uap->oact) ? &oact : NULL; 324 if (actp) { 325 error = copyin((c_caddr_t)uap->act, (caddr_t)actp, 326 sizeof(act)); 327 if (error) |
155 return (error); 156 } | 328 return (error); 329 } |
157 if (uap->nsa) { 158 if ((error = copyin((caddr_t)uap->nsa, (caddr_t)sa, 159 sizeof (vec)))) 160 return (error); 161 if ((signum == SIGKILL || signum == SIGSTOP) && 162 sa->sa_handler != SIG_DFL) 163 return (EINVAL); 164 setsigvec(p, signum, sa); | 330 error = do_sigaction(p, uap->sig, actp, oactp); 331 if (oactp && !error) { 332 error = copyout((caddr_t)oactp, (caddr_t)uap->oact, 333 sizeof(oact)); |
165 } | 334 } |
166 return (0); | 335 return (error); |
167} 168 | 336} 337 |
169static void 170setsigvec(p, signum, sa) 171 register struct proc *p; 172 int signum; 173 register struct sigaction *sa; | 338#ifndef _SYS_SYSPROTO_H_ 339struct osigaction_args { 340 int signum; 341 struct osigaction *nsa; 342 struct osigaction *osa; 343}; 344#endif 345/* ARGSUSED */ 346int 347osigaction(p, uap) 348 struct proc *p; 349 register struct osigaction_args *uap; |
174{ | 350{ |
175 register struct sigacts *ps = p->p_sigacts; 176 register int bit; | 351 struct osigaction sa; 352 struct sigaction nsa, osa; 353 register struct sigaction *nsap, *osap; 354 int error; |
177 | 355 |
178 bit = sigmask(signum); 179 /* 180 * Change setting atomically. 181 */ 182 (void) splhigh(); 183 ps->ps_catchmask[signum] = sa->sa_mask &~ sigcantmask; 184 if (sa->sa_flags & SA_SIGINFO) { 185 ps->ps_sigact[signum] = sa->sa_handler; 186 ps->ps_siginfo |= bit; 187 } else { 188 ps->ps_sigact[signum] = (__sighandler_t *)sa->sa_sigaction; 189 ps->ps_siginfo &= ~bit; | 356 nsap = (uap->nsa) ? &nsa : NULL; 357 osap = (uap->osa) ? &osa : NULL; 358 if (nsap) { 359 error = copyin((caddr_t)uap->nsa, (caddr_t)&sa, sizeof(sa)); 360 if (error) 361 return (error); 362 nsap->sa_handler = sa.sa_handler; 363 nsap->sa_flags = sa.sa_flags; 364 OSIG2SIG(sa.sa_mask, nsap->sa_mask); |
190 } | 365 } |
191 if ((sa->sa_flags & SA_RESTART) == 0) 192 ps->ps_sigintr |= bit; 193 else 194 ps->ps_sigintr &= ~bit; 195 if (sa->sa_flags & SA_ONSTACK) 196 ps->ps_sigonstack |= bit; 197 else 198 ps->ps_sigonstack &= ~bit; 199 if (sa->sa_flags & SA_RESETHAND) 200 ps->ps_sigreset |= bit; 201 else 202 ps->ps_sigreset &= ~bit; 203 if (sa->sa_flags & SA_NODEFER) 204 ps->ps_signodefer |= bit; 205 else 206 ps->ps_signodefer &= ~bit; 207#ifdef COMPAT_SUNOS 208 if (sa->sa_flags & SA_USERTRAMP) 209 ps->ps_usertramp |= bit; 210 else 211 ps->ps_usertramp &= ~bit; 212#endif 213 if (signum == SIGCHLD) { 214 if (sa->sa_flags & SA_NOCLDSTOP) 215 p->p_procsig->ps_flag |= P_NOCLDSTOP; 216 else 217 p->p_procsig->ps_flag &= ~P_NOCLDSTOP; 218 if (sa->sa_flags & SA_NOCLDWAIT) { 219 /* 220 * Paranoia: since SA_NOCLDWAIT is implemented by 221 * reparenting the dying child to PID 1 (and 222 * trust it to reap the zombie), PID 1 itself is 223 * forbidden to set SA_NOCLDWAIT. 224 */ 225 if (p->p_pid == 1) 226 p->p_procsig->ps_flag &= ~P_NOCLDWAIT; 227 else 228 p->p_procsig->ps_flag |= P_NOCLDWAIT; 229 } else 230 p->p_procsig->ps_flag &= ~P_NOCLDWAIT; | 366 error = do_sigaction(p, uap->signum, nsap, osap); 367 if (osap && !error) { 368 sa.sa_handler = osap->sa_handler; 369 sa.sa_flags = osap->sa_flags; 370 SIG2OSIG(osap->sa_mask, sa.sa_mask); 371 error = copyout((caddr_t)&sa, (caddr_t)uap->osa, sizeof(sa)); |
231 } | 372 } |
232 /* 233 * Set bit in p_sigignore for signals that are set to SIG_IGN, 234 * and for signals set to SIG_DFL where the default is to ignore. 235 * However, don't put SIGCONT in p_sigignore, 236 * as we have to restart the process. 237 */ 238 if (ps->ps_sigact[signum] == SIG_IGN || 239 (sigprop[signum] & SA_IGNORE && ps->ps_sigact[signum] == SIG_DFL)) { 240 p->p_siglist &= ~bit; /* never to be seen again */ 241 if (signum != SIGCONT) 242 p->p_sigignore |= bit; /* easier in psignal */ 243 p->p_sigcatch &= ~bit; 244 } else { 245 p->p_sigignore &= ~bit; 246 if (ps->ps_sigact[signum] == SIG_DFL) 247 p->p_sigcatch &= ~bit; 248 else 249 p->p_sigcatch |= bit; 250 } 251 (void) spl0(); | 373 return (error); |
252} 253 254/* 255 * Initialize signal state for process 0; 256 * set to ignore signals that are ignored by default. 257 */ 258void 259siginit(p) 260 struct proc *p; 261{ 262 register int i; 263 | 374} 375 376/* 377 * Initialize signal state for process 0; 378 * set to ignore signals that are ignored by default. 379 */ 380void 381siginit(p) 382 struct proc *p; 383{ 384 register int i; 385 |
264 for (i = 0; i < NSIG; i++) 265 if (sigprop[i] & SA_IGNORE && i != SIGCONT) 266 p->p_sigignore |= sigmask(i); | 386 for (i = 1; i <= NSIG; i++) 387 if (sigprop(i) & SA_IGNORE && i != SIGCONT) 388 SIGADDSET(p->p_sigignore, i); |
267} 268 269/* 270 * Reset signals for an exec of the specified process. 271 */ 272void 273execsigs(p) 274 register struct proc *p; 275{ 276 register struct sigacts *ps = p->p_sigacts; | 389} 390 391/* 392 * Reset signals for an exec of the specified process. 393 */ 394void 395execsigs(p) 396 register struct proc *p; 397{ 398 register struct sigacts *ps = p->p_sigacts; |
277 register int nc, mask; | 399 register int sig; |
278 279 /* 280 * Reset caught signals. Held signals remain held 281 * through p_sigmask (unless they were caught, 282 * and are now ignored by default). 283 */ | 400 401 /* 402 * Reset caught signals. Held signals remain held 403 * through p_sigmask (unless they were caught, 404 * and are now ignored by default). 405 */ |
284 while (p->p_sigcatch) { 285 nc = ffs((long)p->p_sigcatch); 286 mask = sigmask(nc); 287 p->p_sigcatch &= ~mask; 288 if (sigprop[nc] & SA_IGNORE) { 289 if (nc != SIGCONT) 290 p->p_sigignore |= mask; 291 p->p_siglist &= ~mask; | 406 while (SIGNOTEMPTY(p->p_sigcatch)) { 407 sig = sig_ffs(&p->p_sigcatch); 408 SIGDELSET(p->p_sigcatch, sig); 409 if (sigprop(sig) & SA_IGNORE) { 410 if (sig != SIGCONT) 411 SIGADDSET(p->p_sigignore, sig); 412 SIGDELSET(p->p_siglist, sig); |
292 } | 413 } |
293 ps->ps_sigact[nc] = SIG_DFL; | 414 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL; |
294 } 295 /* 296 * Reset stack state to the user stack. 297 * Clear set of signals caught on the signal stack. 298 */ 299 ps->ps_sigstk.ss_flags = SS_DISABLE; 300 ps->ps_sigstk.ss_size = 0; 301 ps->ps_sigstk.ss_sp = 0; --- 5 unchanged lines hidden (view full) --- 307} 308 309/* 310 * Manipulate signal mask. 311 * Note that we receive new mask, not pointer, 312 * and return old mask as return value; 313 * the library stub does the rest. 314 */ | 415 } 416 /* 417 * Reset stack state to the user stack. 418 * Clear set of signals caught on the signal stack. 419 */ 420 ps->ps_sigstk.ss_flags = SS_DISABLE; 421 ps->ps_sigstk.ss_size = 0; 422 ps->ps_sigstk.ss_sp = 0; --- 5 unchanged lines hidden (view full) --- 428} 429 430/* 431 * Manipulate signal mask. 432 * Note that we receive new mask, not pointer, 433 * and return old mask as return value; 434 * the library stub does the rest. 435 */ |
436static int 437do_sigprocmask(p, how, set, oset) 438 struct proc *p; 439 int how; 440 sigset_t *set, *oset; 441{ 442 int error; 443 444 if (oset != NULL) 445 *oset = p->p_sigmask; 446 447 error = 0; 448 if (set != NULL) { 449 (void) splhigh(); 450 switch (how) { 451 case SIG_BLOCK: 452 SIGSETOR(p->p_sigmask, *set); 453 SIG_CANTMASK(p->p_sigmask); 454 break; 455 case SIG_UNBLOCK: 456 SIGSETNAND(p->p_sigmask, *set); 457 break; 458 case SIG_SETMASK: 459 p->p_sigmask = *set; 460 SIG_CANTMASK(p->p_sigmask); 461 break; 462 default: 463 error = EINVAL; 464 break; 465 } 466 (void) spl0(); 467 } 468 return (error); 469} 470 |
|
315#ifndef _SYS_SYSPROTO_H_ 316struct sigprocmask_args { 317 int how; | 471#ifndef _SYS_SYSPROTO_H_ 472struct sigprocmask_args { 473 int how; |
318 sigset_t mask; | 474 const sigset_t *set; 475 sigset_t *oset; |
319}; 320#endif 321int 322sigprocmask(p, uap) 323 register struct proc *p; 324 struct sigprocmask_args *uap; 325{ | 476}; 477#endif 478int 479sigprocmask(p, uap) 480 register struct proc *p; 481 struct sigprocmask_args *uap; 482{ |
326 int error = 0; | 483 sigset_t set, oset; 484 sigset_t *setp, *osetp; 485 int error; |
327 | 486 |
328 p->p_retval[0] = p->p_sigmask; 329 (void) splhigh(); | 487 setp = (uap->set) ? &set : NULL; 488 osetp = (uap->oset) ? &oset : NULL; 489 if (setp) { 490 error = copyin((c_caddr_t)uap->set, (caddr_t)setp, 491 sizeof(set)); 492 if (error) 493 return (error); 494 } 495 error = do_sigprocmask(p, uap->how, setp, osetp); 496 if (osetp && !error) { 497 error = copyout((caddr_t)osetp, (caddr_t)uap->oset, 498 sizeof(oset)); 499 } 500 return (error); 501} |
330 | 502 |
331 switch (uap->how) { 332 case SIG_BLOCK: 333 p->p_sigmask |= uap->mask &~ sigcantmask; 334 break; | 503#ifndef _SYS_SYSPROTO_H_ 504struct osigprocmask_args { 505 int how; 506 osigset_t mask; 507}; 508#endif 509int 510osigprocmask(p, uap) 511 register struct proc *p; 512 struct osigprocmask_args *uap; 513{ 514 sigset_t set, oset; 515 int error; |
335 | 516 |
336 case SIG_UNBLOCK: 337 p->p_sigmask &= ~uap->mask; 338 break; 339 340 case SIG_SETMASK: 341 p->p_sigmask = uap->mask &~ sigcantmask; 342 break; 343 344 default: 345 error = EINVAL; 346 break; 347 } 348 (void) spl0(); | 517 OSIG2SIG(uap->mask, set); 518 error = do_sigprocmask(p, uap->how, &set, &oset); 519 SIG2OSIG(oset, p->p_retval[0]); |
349 return (error); 350} 351 352#ifndef _SYS_SYSPROTO_H_ 353struct sigpending_args { | 520 return (error); 521} 522 523#ifndef _SYS_SYSPROTO_H_ 524struct sigpending_args { |
354 int dummy; | 525 sigset_t *set; |
355}; 356#endif 357/* ARGSUSED */ 358int 359sigpending(p, uap) 360 struct proc *p; 361 struct sigpending_args *uap; 362{ 363 | 526}; 527#endif 528/* ARGSUSED */ 529int 530sigpending(p, uap) 531 struct proc *p; 532 struct sigpending_args *uap; 533{ 534 |
364 p->p_retval[0] = p->p_siglist; | 535 return (copyout((caddr_t)&p->p_siglist, (caddr_t)uap->set, 536 sizeof(sigset_t))); 537} 538 539#ifndef _SYS_SYSPROTO_H_ 540struct osigpending_args { 541 int dummy; 542}; 543#endif 544/* ARGSUSED */ 545int 546osigpending(p, uap) 547 struct proc *p; 548 struct osigpending_args *uap; 549{ 550 551 SIG2OSIG(p->p_siglist, p->p_retval[0]); |
365 return (0); 366} 367 368#if defined(COMPAT_43) || defined(COMPAT_SUNOS) 369/* 370 * Generalized interface signal handler, 4.3-compatible. 371 */ 372#ifndef _SYS_SYSPROTO_H_ --- 5 unchanged lines hidden (view full) --- 378#endif 379/* ARGSUSED */ 380int 381osigvec(p, uap) 382 struct proc *p; 383 register struct osigvec_args *uap; 384{ 385 struct sigvec vec; | 552 return (0); 553} 554 555#if defined(COMPAT_43) || defined(COMPAT_SUNOS) 556/* 557 * Generalized interface signal handler, 4.3-compatible. 558 */ 559#ifndef _SYS_SYSPROTO_H_ --- 5 unchanged lines hidden (view full) --- 565#endif 566/* ARGSUSED */ 567int 568osigvec(p, uap) 569 struct proc *p; 570 register struct osigvec_args *uap; 571{ 572 struct sigvec vec; |
386 register struct sigacts *ps = p->p_sigacts; 387 register struct sigvec *sv; 388 register int signum; 389 int bit, error; | 573 struct sigaction nsa, osa; 574 register struct sigaction *nsap, *osap; 575 int error; |
390 | 576 |
391 signum = uap->signum; 392 if (signum <= 0 || signum >= NSIG) 393 return (EINVAL); 394 sv = &vec; 395 if (uap->osv) { 396 *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum]; 397 sv->sv_mask = ps->ps_catchmask[signum]; 398 bit = sigmask(signum); 399 sv->sv_flags = 0; 400 if ((ps->ps_sigonstack & bit) != 0) 401 sv->sv_flags |= SV_ONSTACK; 402 if ((ps->ps_sigintr & bit) != 0) 403 sv->sv_flags |= SV_INTERRUPT; 404 if ((ps->ps_sigreset & bit) != 0) 405 sv->sv_flags |= SV_RESETHAND; 406 if ((ps->ps_signodefer & bit) != 0) 407 sv->sv_flags |= SV_NODEFER; 408 if ((ps->ps_siginfo & bit) != 0) 409 sv->sv_flags |= SV_SIGINFO; 410#ifndef COMPAT_SUNOS 411 if (signum == SIGCHLD && p->p_procsig->ps_flag & P_NOCLDSTOP) 412 sv->sv_flags |= SV_NOCLDSTOP; 413#endif 414 if ((error = copyout((caddr_t)sv, (caddr_t)uap->osv, 415 sizeof (vec)))) | 577 nsap = (uap->nsv) ? &nsa : NULL; 578 osap = (uap->osv) ? &osa : NULL; 579 if (nsap) { 580 error = copyin((caddr_t)uap->nsv, (caddr_t)&vec, sizeof(vec)); 581 if (error) |
416 return (error); | 582 return (error); |
583 nsap->sa_handler = vec.sv_handler; 584 OSIG2SIG(vec.sv_mask, nsap->sa_mask); 585 nsap->sa_flags = vec.sv_flags; 586 nsap->sa_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */ 587#ifdef COMPAT_SUNOS 588 nsap->sa_flags |= SA_USERTRAMP; 589#endif |
|
417 } | 590 } |
418 if (uap->nsv) { 419 if ((error = copyin((caddr_t)uap->nsv, (caddr_t)sv, 420 sizeof (vec)))) 421 return (error); 422 if ((signum == SIGKILL || signum == SIGSTOP) && 423 sv->sv_handler != SIG_DFL) 424 return (EINVAL); | 591 error = do_sigaction(p, uap->signum, nsap, osap); 592 if (osap && !error) { 593 vec.sv_handler = osap->sa_handler; 594 SIG2OSIG(osap->sa_mask, vec.sv_mask); 595 vec.sv_flags = osap->sa_flags; 596 vec.sv_flags &= ~SA_NOCLDWAIT; 597 vec.sv_flags ^= SA_RESTART; |
425#ifdef COMPAT_SUNOS | 598#ifdef COMPAT_SUNOS |
426 sv->sv_flags |= SA_USERTRAMP; | 599 vec.sv_flags &= ~SA_NOCLDSTOP; |
427#endif | 600#endif |
428 sv->sv_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */ 429 setsigvec(p, signum, (struct sigaction *)sv); | 601 error = copyout((caddr_t)&vec, (caddr_t)uap->osv, sizeof(vec)); |
430 } | 602 } |
431 return (0); | 603 return (error); |
432} 433 434#ifndef _SYS_SYSPROTO_H_ 435struct osigblock_args { 436 int mask; 437}; 438#endif 439int 440osigblock(p, uap) 441 register struct proc *p; 442 struct osigblock_args *uap; 443{ | 604} 605 606#ifndef _SYS_SYSPROTO_H_ 607struct osigblock_args { 608 int mask; 609}; 610#endif 611int 612osigblock(p, uap) 613 register struct proc *p; 614 struct osigblock_args *uap; 615{ |
616 sigset_t set; |
|
444 | 617 |
618 OSIG2SIG(uap->mask, set); 619 SIG_CANTMASK(set); |
|
445 (void) splhigh(); | 620 (void) splhigh(); |
446 p->p_retval[0] = p->p_sigmask; 447 p->p_sigmask |= uap->mask &~ sigcantmask; | 621 SIG2OSIG(p->p_sigmask, p->p_retval[0]); 622 SIGSETOR(p->p_sigmask, set); |
448 (void) spl0(); 449 return (0); 450} 451 452#ifndef _SYS_SYSPROTO_H_ 453struct osigsetmask_args { 454 int mask; 455}; 456#endif 457int 458osigsetmask(p, uap) 459 struct proc *p; 460 struct osigsetmask_args *uap; 461{ | 623 (void) spl0(); 624 return (0); 625} 626 627#ifndef _SYS_SYSPROTO_H_ 628struct osigsetmask_args { 629 int mask; 630}; 631#endif 632int 633osigsetmask(p, uap) 634 struct proc *p; 635 struct osigsetmask_args *uap; 636{ |
637 sigset_t set; |
|
462 | 638 |
639 OSIG2SIG(uap->mask, set); 640 SIG_CANTMASK(set); |
|
463 (void) splhigh(); | 641 (void) splhigh(); |
464 p->p_retval[0] = p->p_sigmask; 465 p->p_sigmask = uap->mask &~ sigcantmask; | 642 SIG2OSIG(p->p_sigmask, p->p_retval[0]); 643 p->p_sigmask = set; |
466 (void) spl0(); 467 return (0); 468} 469#endif /* COMPAT_43 || COMPAT_SUNOS */ 470 471/* 472 * Suspend process until signal, providing mask to be set 473 * in the meantime. Note nonstandard calling convention: 474 * libc stub passes mask, not pointer, to save a copyin. 475 */ 476#ifndef _SYS_SYSPROTO_H_ 477struct sigsuspend_args { | 644 (void) spl0(); 645 return (0); 646} 647#endif /* COMPAT_43 || COMPAT_SUNOS */ 648 649/* 650 * Suspend process until signal, providing mask to be set 651 * in the meantime. Note nonstandard calling convention: 652 * libc stub passes mask, not pointer, to save a copyin. 653 */ 654#ifndef _SYS_SYSPROTO_H_ 655struct sigsuspend_args { |
478 sigset_t mask; | 656 const sigset_t *sigmask; |
479}; 480#endif 481/* ARGSUSED */ 482int 483sigsuspend(p, uap) 484 register struct proc *p; 485 struct sigsuspend_args *uap; 486{ | 657}; 658#endif 659/* ARGSUSED */ 660int 661sigsuspend(p, uap) 662 register struct proc *p; 663 struct sigsuspend_args *uap; 664{ |
665 sigset_t mask; |
|
487 register struct sigacts *ps = p->p_sigacts; | 666 register struct sigacts *ps = p->p_sigacts; |
667 int error; |
|
488 | 668 |
669 error = copyin((c_caddr_t)uap->sigmask, (caddr_t)&mask, sizeof(mask)); 670 if (error) 671 return (error); 672 |
|
489 /* 490 * When returning from sigpause, we want 491 * the old mask to be restored after the 492 * signal handler has finished. Thus, we 493 * save it here and mark the sigacts structure 494 * to indicate this. 495 */ 496 p->p_oldsigmask = p->p_sigmask; | 673 /* 674 * When returning from sigpause, we want 675 * the old mask to be restored after the 676 * signal handler has finished. Thus, we 677 * save it here and mark the sigacts structure 678 * to indicate this. 679 */ 680 p->p_oldsigmask = p->p_sigmask; |
497 p->p_sigmask = uap->mask &~ sigcantmask; | 681 p->p_sigmask = mask; 682 SIG_CANTMASK(p->p_sigmask); |
498 while (tsleep((caddr_t) ps, PPAUSE|PCATCH, "pause", 0) == 0) 499 /* void */; 500 /* always return EINTR rather than ERESTART... */ 501 return (EINTR); 502} 503 | 683 while (tsleep((caddr_t) ps, PPAUSE|PCATCH, "pause", 0) == 0) 684 /* void */; 685 /* always return EINTR rather than ERESTART... */ 686 return (EINTR); 687} 688 |
689#ifndef _SYS_SYSPROTO_H_ 690struct osigsuspend_args { 691 osigset_t mask; 692}; 693#endif 694/* ARGSUSED */ 695int 696osigsuspend(p, uap) 697 register struct proc *p; 698 struct osigsuspend_args *uap; 699{ 700 sigset_t set; 701 register struct sigacts *ps = p->p_sigacts; 702 703 OSIG2SIG(uap->mask, set); 704 SIG_CANTMASK(set); 705 p->p_oldsigmask = p->p_sigmask; 706 p->p_sigmask = set; 707 while (tsleep((caddr_t) ps, PPAUSE|PCATCH, "pause", 0) == 0) 708 /* void */; 709 /* always return EINTR rather than ERESTART... */ 710 return (EINTR); 711} 712 |
|
504#if defined(COMPAT_43) || defined(COMPAT_SUNOS) 505#ifndef _SYS_SYSPROTO_H_ 506struct osigstack_args { 507 struct sigstack *nss; 508 struct sigstack *oss; 509}; 510#endif 511/* ARGSUSED */ --- 20 unchanged lines hidden (view full) --- 532 psp->ps_flags |= SAS_ALTSTACK; 533 } 534 return (error); 535} 536#endif /* COMPAT_43 || COMPAT_SUNOS */ 537 538#ifndef _SYS_SYSPROTO_H_ 539struct sigaltstack_args { | 713#if defined(COMPAT_43) || defined(COMPAT_SUNOS) 714#ifndef _SYS_SYSPROTO_H_ 715struct osigstack_args { 716 struct sigstack *nss; 717 struct sigstack *oss; 718}; 719#endif 720/* ARGSUSED */ --- 20 unchanged lines hidden (view full) --- 741 psp->ps_flags |= SAS_ALTSTACK; 742 } 743 return (error); 744} 745#endif /* COMPAT_43 || COMPAT_SUNOS */ 746 747#ifndef _SYS_SYSPROTO_H_ 748struct sigaltstack_args { |
540 struct sigaltstack *nss; 541 struct sigaltstack *oss; | 749 stack_t *ss; 750 stack_t *oss; |
542}; 543#endif 544/* ARGSUSED */ 545int 546sigaltstack(p, uap) 547 struct proc *p; 548 register struct sigaltstack_args *uap; 549{ 550 struct sigacts *psp; | 751}; 752#endif 753/* ARGSUSED */ 754int 755sigaltstack(p, uap) 756 struct proc *p; 757 register struct sigaltstack_args *uap; 758{ 759 struct sigacts *psp; |
551 struct sigaltstack ss; | 760 stack_t ss; |
552 int error; 553 554 psp = p->p_sigacts; 555 if ((psp->ps_flags & SAS_ALTSTACK) == 0) 556 psp->ps_sigstk.ss_flags |= SS_DISABLE; 557 if (uap->oss && (error = copyout((caddr_t)&psp->ps_sigstk, | 761 int error; 762 763 psp = p->p_sigacts; 764 if ((psp->ps_flags & SAS_ALTSTACK) == 0) 765 psp->ps_sigstk.ss_flags |= SS_DISABLE; 766 if (uap->oss && (error = copyout((caddr_t)&psp->ps_sigstk, |
558 (caddr_t)uap->oss, sizeof (struct sigaltstack)))) | 767 (caddr_t)uap->oss, sizeof (stack_t)))) |
559 return (error); | 768 return (error); |
560 if (uap->nss == 0) | 769 if (uap->ss == 0) |
561 return (0); | 770 return (0); |
562 if ((error = copyin((caddr_t)uap->nss, (caddr_t)&ss, sizeof (ss)))) | 771 if ((error = copyin((caddr_t)uap->ss, (caddr_t)&ss, sizeof (ss)))) |
563 return (error); 564 if (ss.ss_flags & SS_DISABLE) { 565 if (psp->ps_sigstk.ss_flags & SS_ONSTACK) 566 return (EINVAL); 567 psp->ps_flags &= ~SAS_ALTSTACK; 568 psp->ps_sigstk.ss_flags = ss.ss_flags; 569 return (0); 570 } 571 if (ss.ss_size < MINSIGSTKSZ) 572 return (ENOMEM); 573 psp->ps_flags |= SAS_ALTSTACK; | 772 return (error); 773 if (ss.ss_flags & SS_DISABLE) { 774 if (psp->ps_sigstk.ss_flags & SS_ONSTACK) 775 return (EINVAL); 776 psp->ps_flags &= ~SAS_ALTSTACK; 777 psp->ps_sigstk.ss_flags = ss.ss_flags; 778 return (0); 779 } 780 if (ss.ss_size < MINSIGSTKSZ) 781 return (ENOMEM); 782 psp->ps_flags |= SAS_ALTSTACK; |
574 psp->ps_sigstk= ss; | 783 psp->ps_sigstk = ss; |
575 return (0); 576} 577 578/* 579 * Common code for kill process group/broadcast kill. 580 * cp is calling process. 581 */ 582int | 784 return (0); 785} 786 787/* 788 * Common code for kill process group/broadcast kill. 789 * cp is calling process. 790 */ 791int |
583killpg1(cp, signum, pgid, all) | 792killpg1(cp, sig, pgid, all) |
584 register struct proc *cp; | 793 register struct proc *cp; |
585 int signum, pgid, all; | 794 int sig, pgid, all; |
586{ 587 register struct proc *p; 588 register struct pcred *pc = cp->p_cred; 589 struct pgrp *pgrp; 590 int nfound = 0; 591 592 if (all) 593 /* 594 * broadcast 595 */ 596 for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) { 597 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || | 795{ 796 register struct proc *p; 797 register struct pcred *pc = cp->p_cred; 798 struct pgrp *pgrp; 799 int nfound = 0; 800 801 if (all) 802 /* 803 * broadcast 804 */ 805 for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) { 806 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || |
598 p == cp || !CANSIGNAL(cp, pc, p, signum)) | 807 p == cp || !CANSIGNAL(cp, pc, p, sig)) |
599 continue; 600 nfound++; | 808 continue; 809 nfound++; |
601 if (signum) 602 psignal(p, signum); | 810 if (sig) 811 psignal(p, sig); |
603 } 604 else { 605 if (pgid == 0) 606 /* 607 * zero pgid means send to my process group. 608 */ 609 pgrp = cp->p_pgrp; 610 else { 611 pgrp = pgfind(pgid); 612 if (pgrp == NULL) 613 return (ESRCH); 614 } 615 for (p = pgrp->pg_members.lh_first; p != 0; 616 p = p->p_pglist.le_next) { 617 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || 618 p->p_stat == SZOMB || | 812 } 813 else { 814 if (pgid == 0) 815 /* 816 * zero pgid means send to my process group. 817 */ 818 pgrp = cp->p_pgrp; 819 else { 820 pgrp = pgfind(pgid); 821 if (pgrp == NULL) 822 return (ESRCH); 823 } 824 for (p = pgrp->pg_members.lh_first; p != 0; 825 p = p->p_pglist.le_next) { 826 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM || 827 p->p_stat == SZOMB || |
619 !CANSIGNAL(cp, pc, p, signum)) | 828 !CANSIGNAL(cp, pc, p, sig)) |
620 continue; 621 nfound++; | 829 continue; 830 nfound++; |
622 if (signum) 623 psignal(p, signum); | 831 if (sig) 832 psignal(p, sig); |
624 } 625 } 626 return (nfound ? 0 : ESRCH); 627} 628 629#ifndef _SYS_SYSPROTO_H_ 630struct kill_args { 631 int pid; --- 4 unchanged lines hidden (view full) --- 636int 637kill(cp, uap) 638 register struct proc *cp; 639 register struct kill_args *uap; 640{ 641 register struct proc *p; 642 register struct pcred *pc = cp->p_cred; 643 | 833 } 834 } 835 return (nfound ? 0 : ESRCH); 836} 837 838#ifndef _SYS_SYSPROTO_H_ 839struct kill_args { 840 int pid; --- 4 unchanged lines hidden (view full) --- 845int 846kill(cp, uap) 847 register struct proc *cp; 848 register struct kill_args *uap; 849{ 850 register struct proc *p; 851 register struct pcred *pc = cp->p_cred; 852 |
644 if ((u_int)uap->signum >= NSIG) | 853 if ((u_int)uap->signum > _SIG_MAXSIG) |
645 return (EINVAL); 646 if (uap->pid > 0) { 647 /* kill single process */ 648 if ((p = pfind(uap->pid)) == NULL) 649 return (ESRCH); 650 if (!CANSIGNAL(cp, pc, p, uap->signum)) 651 return (EPERM); 652 if (uap->signum) --- 20 unchanged lines hidden (view full) --- 673#endif 674/* ARGSUSED */ 675int 676okillpg(p, uap) 677 struct proc *p; 678 register struct okillpg_args *uap; 679{ 680 | 854 return (EINVAL); 855 if (uap->pid > 0) { 856 /* kill single process */ 857 if ((p = pfind(uap->pid)) == NULL) 858 return (ESRCH); 859 if (!CANSIGNAL(cp, pc, p, uap->signum)) 860 return (EPERM); 861 if (uap->signum) --- 20 unchanged lines hidden (view full) --- 882#endif 883/* ARGSUSED */ 884int 885okillpg(p, uap) 886 struct proc *p; 887 register struct okillpg_args *uap; 888{ 889 |
681 if ((u_int)uap->signum >= NSIG) | 890 if ((u_int)uap->signum > _SIG_MAXSIG) |
682 return (EINVAL); 683 return (killpg1(p, uap->signum, uap->pgid, 0)); 684} 685#endif /* COMPAT_43 || COMPAT_SUNOS */ 686 687/* 688 * Send a signal to a process group. 689 */ 690void | 891 return (EINVAL); 892 return (killpg1(p, uap->signum, uap->pgid, 0)); 893} 894#endif /* COMPAT_43 || COMPAT_SUNOS */ 895 896/* 897 * Send a signal to a process group. 898 */ 899void |
691gsignal(pgid, signum) 692 int pgid, signum; | 900gsignal(pgid, sig) 901 int pgid, sig; |
693{ 694 struct pgrp *pgrp; 695 696 if (pgid && (pgrp = pgfind(pgid))) | 902{ 903 struct pgrp *pgrp; 904 905 if (pgid && (pgrp = pgfind(pgid))) |
697 pgsignal(pgrp, signum, 0); | 906 pgsignal(pgrp, sig, 0); |
698} 699 700/* 701 * Send a signal to a process group. If checktty is 1, 702 * limit to members which have a controlling terminal. 703 */ 704void | 907} 908 909/* 910 * Send a signal to a process group. If checktty is 1, 911 * limit to members which have a controlling terminal. 912 */ 913void |
705pgsignal(pgrp, signum, checkctty) | 914pgsignal(pgrp, sig, checkctty) |
706 struct pgrp *pgrp; | 915 struct pgrp *pgrp; |
707 int signum, checkctty; | 916 int sig, checkctty; |
708{ 709 register struct proc *p; 710 711 if (pgrp) 712 for (p = pgrp->pg_members.lh_first; p != 0; 713 p = p->p_pglist.le_next) 714 if (checkctty == 0 || p->p_flag & P_CONTROLT) | 917{ 918 register struct proc *p; 919 920 if (pgrp) 921 for (p = pgrp->pg_members.lh_first; p != 0; 922 p = p->p_pglist.le_next) 923 if (checkctty == 0 || p->p_flag & P_CONTROLT) |
715 psignal(p, signum); | 924 psignal(p, sig); |
716} 717 718/* 719 * Send a signal caused by a trap to the current process. 720 * If it will be caught immediately, deliver it with correct code. 721 * Otherwise, post it normally. 722 */ 723void | 925} 926 927/* 928 * Send a signal caused by a trap to the current process. 929 * If it will be caught immediately, deliver it with correct code. 930 * Otherwise, post it normally. 931 */ 932void |
724trapsignal(p, signum, code) | 933trapsignal(p, sig, code) |
725 struct proc *p; | 934 struct proc *p; |
726 register int signum; | 935 register int sig; |
727 u_long code; 728{ 729 register struct sigacts *ps = p->p_sigacts; | 936 u_long code; 937{ 938 register struct sigacts *ps = p->p_sigacts; |
730 int mask; | |
731 | 939 |
732 mask = sigmask(signum); 733 if ((p->p_flag & P_TRACED) == 0 && (p->p_sigcatch & mask) != 0 && 734 (p->p_sigmask & mask) == 0) { | 940 if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(p->p_sigcatch, sig) && 941 SIGISMEMBER(p->p_sigmask, sig)) { |
735 p->p_stats->p_ru.ru_nsignals++; 736#ifdef KTRACE 737 if (KTRPOINT(p, KTR_PSIG)) | 942 p->p_stats->p_ru.ru_nsignals++; 943#ifdef KTRACE 944 if (KTRPOINT(p, KTR_PSIG)) |
738 ktrpsig(p->p_tracep, signum, ps->ps_sigact[signum], 739 p->p_sigmask, code); | 945 ktrpsig(p->p_tracep, sig, ps->ps_sigact[_SIG_IDX(sig)], 946 &p->p_sigmask, code); |
740#endif | 947#endif |
741 (*p->p_sysent->sv_sendsig)(ps->ps_sigact[signum], signum, 742 p->p_sigmask, code); 743 p->p_sigmask |= ps->ps_catchmask[signum] | 744 (mask & ~ps->ps_signodefer); 745 if ((ps->ps_sigreset & mask) != 0) { | 948 (*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)], sig, 949 &p->p_sigmask, code); 950 SIGSETOR(p->p_sigmask, ps->ps_catchmask[_SIG_IDX(sig)]); 951 if (!SIGISMEMBER(ps->ps_signodefer, sig)) 952 SIGADDSET(p->p_sigmask, sig); 953 if (SIGISMEMBER(ps->ps_sigreset, sig)) { |
746 /* | 954 /* |
747 * See setsigvec() for origin of this code. | 955 * See do_sigaction() for origin of this code. |
748 */ | 956 */ |
749 p->p_sigcatch &= ~mask; 750 if (signum != SIGCONT && sigprop[signum] & SA_IGNORE) 751 p->p_sigignore |= mask; 752 ps->ps_sigact[signum] = SIG_DFL; | 957 SIGDELSET(p->p_sigcatch, sig); 958 if (sig != SIGCONT && 959 sigprop(sig) & SA_IGNORE) 960 SIGADDSET(p->p_sigignore, sig); 961 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL; |
753 } | 962 } |
754 } else { | 963 } 964 else { |
755 p->p_code = code; /* XXX for core dump/debugger */ | 965 p->p_code = code; /* XXX for core dump/debugger */ |
756 p->p_sig = signum; /* XXX to verify code */ 757 psignal(p, signum); | 966 p->p_sig = sig; /* XXX to verify code */ 967 psignal(p, sig); |
758 } 759} 760 761/* 762 * Send the signal to the process. If the signal has an action, the action 763 * is usually performed by the target process rather than the caller; we add 764 * the signal to the set of pending signals for the process. 765 * 766 * Exceptions: 767 * o When a stop signal is sent to a sleeping process that takes the 768 * default action, the process is stopped without awakening it. 769 * o SIGCONT restarts stopped processes (or puts them back to sleep) 770 * regardless of the signal action (eg, blocked or ignored). 771 * 772 * Other ignored signals are discarded immediately. 773 */ 774void | 968 } 969} 970 971/* 972 * Send the signal to the process. If the signal has an action, the action 973 * is usually performed by the target process rather than the caller; we add 974 * the signal to the set of pending signals for the process. 975 * 976 * Exceptions: 977 * o When a stop signal is sent to a sleeping process that takes the 978 * default action, the process is stopped without awakening it. 979 * o SIGCONT restarts stopped processes (or puts them back to sleep) 980 * regardless of the signal action (eg, blocked or ignored). 981 * 982 * Other ignored signals are discarded immediately. 983 */ 984void |
775psignal(p, signum) | 985psignal(p, sig) |
776 register struct proc *p; | 986 register struct proc *p; |
777 register int signum; | 987 register int sig; |
778{ 779 register int s, prop; 780 register sig_t action; | 988{ 989 register int s, prop; 990 register sig_t action; |
781 int mask; | |
782 | 991 |
783 if ((u_int)signum >= NSIG || signum == 0) { 784 printf("psignal: signum %d\n", signum); | 992 if (sig > _SIG_MAXSIG || sig <= 0) { 993 printf("psignal: signal %d\n", sig); |
785 panic("psignal signal number"); 786 } | 994 panic("psignal signal number"); 995 } |
787 mask = sigmask(signum); 788 prop = sigprop[signum]; | |
789 | 996 |
997 prop = sigprop(sig); 998 |
|
790 /* 791 * If proc is traced, always give parent a chance; 792 * if signal event is tracked by procfs, give *that* 793 * a chance, as well. 794 */ 795 if ((p->p_flag & P_TRACED) || (p->p_stops & S_SIG)) 796 action = SIG_DFL; 797 else { 798 /* 799 * If the signal is being ignored, 800 * then we forget about it immediately. 801 * (Note: we don't set SIGCONT in p_sigignore, 802 * and if it is set to SIG_IGN, 803 * action will be SIG_DFL here.) 804 */ | 999 /* 1000 * If proc is traced, always give parent a chance; 1001 * if signal event is tracked by procfs, give *that* 1002 * a chance, as well. 1003 */ 1004 if ((p->p_flag & P_TRACED) || (p->p_stops & S_SIG)) 1005 action = SIG_DFL; 1006 else { 1007 /* 1008 * If the signal is being ignored, 1009 * then we forget about it immediately. 1010 * (Note: we don't set SIGCONT in p_sigignore, 1011 * and if it is set to SIG_IGN, 1012 * action will be SIG_DFL here.) 1013 */ |
805 if ((p->p_sigignore & mask) || (p->p_flag & P_WEXIT)) | 1014 if (SIGISMEMBER(p->p_sigignore, sig) || (p->p_flag & P_WEXIT)) |
806 return; | 1015 return; |
807 if (p->p_sigmask & mask) | 1016 if (SIGISMEMBER(p->p_sigmask, sig)) |
808 action = SIG_HOLD; | 1017 action = SIG_HOLD; |
809 else if (p->p_sigcatch & mask) | 1018 else if (SIGISMEMBER(p->p_sigcatch, sig)) |
810 action = SIG_CATCH; 811 else 812 action = SIG_DFL; 813 } 814 815 if (p->p_nice > NZERO && action == SIG_DFL && (prop & SA_KILL) && 816 (p->p_flag & P_TRACED) == 0) 817 p->p_nice = NZERO; 818 819 if (prop & SA_CONT) | 1019 action = SIG_CATCH; 1020 else 1021 action = SIG_DFL; 1022 } 1023 1024 if (p->p_nice > NZERO && action == SIG_DFL && (prop & SA_KILL) && 1025 (p->p_flag & P_TRACED) == 0) 1026 p->p_nice = NZERO; 1027 1028 if (prop & SA_CONT) |
820 p->p_siglist &= ~stopsigmask; | 1029 SIG_STOPSIGMASK(p->p_siglist); |
821 822 if (prop & SA_STOP) { 823 /* 824 * If sending a tty stop signal to a member of an orphaned 825 * process group, discard the signal here if the action 826 * is default; don't stop the process below if sleeping, 827 * and don't clear any pending SIGCONT. 828 */ 829 if (prop & SA_TTYSTOP && p->p_pgrp->pg_jobc == 0 && 830 action == SIG_DFL) 831 return; | 1030 1031 if (prop & SA_STOP) { 1032 /* 1033 * If sending a tty stop signal to a member of an orphaned 1034 * process group, discard the signal here if the action 1035 * is default; don't stop the process below if sleeping, 1036 * and don't clear any pending SIGCONT. 1037 */ 1038 if (prop & SA_TTYSTOP && p->p_pgrp->pg_jobc == 0 && 1039 action == SIG_DFL) 1040 return; |
832 p->p_siglist &= ~contsigmask; | 1041 SIG_CONTSIGMASK(p->p_siglist); |
833 } | 1042 } |
834 p->p_siglist |= mask; | 1043 SIGADDSET(p->p_siglist, sig); |
835 836 /* 837 * Defer further processing for signals which are held, 838 * except that stopped processes must be continued by SIGCONT. 839 */ | 1044 1045 /* 1046 * Defer further processing for signals which are held, 1047 * except that stopped processes must be continued by SIGCONT. 1048 */ |
840 if (action == SIG_HOLD && ((prop & SA_CONT) == 0 || p->p_stat != SSTOP)) | 1049 if (action == SIG_HOLD && (!(prop & SA_CONT) || p->p_stat != SSTOP)) |
841 return; 842 s = splhigh(); 843 switch (p->p_stat) { 844 845 case SSLEEP: 846 /* 847 * If process is sleeping uninterruptibly 848 * we can't interrupt the sleep... the signal will --- 10 unchanged lines hidden (view full) --- 859 if (p->p_flag & P_TRACED) 860 goto run; 861 /* 862 * If SIGCONT is default (or ignored) and process is 863 * asleep, we are finished; the process should not 864 * be awakened. 865 */ 866 if ((prop & SA_CONT) && action == SIG_DFL) { | 1050 return; 1051 s = splhigh(); 1052 switch (p->p_stat) { 1053 1054 case SSLEEP: 1055 /* 1056 * If process is sleeping uninterruptibly 1057 * we can't interrupt the sleep... the signal will --- 10 unchanged lines hidden (view full) --- 1068 if (p->p_flag & P_TRACED) 1069 goto run; 1070 /* 1071 * If SIGCONT is default (or ignored) and process is 1072 * asleep, we are finished; the process should not 1073 * be awakened. 1074 */ 1075 if ((prop & SA_CONT) && action == SIG_DFL) { |
867 p->p_siglist &= ~mask; | 1076 SIGDELSET(p->p_siglist, sig); |
868 goto out; 869 } 870 /* 871 * When a sleeping process receives a stop 872 * signal, process immediately if possible. 873 * All other (caught or default) signals 874 * cause the process to run. 875 */ 876 if (prop & SA_STOP) { 877 if (action != SIG_DFL) 878 goto runfast; 879 /* 880 * If a child holding parent blocked, 881 * stopping could cause deadlock. 882 */ 883 if (p->p_flag & P_PPWAIT) 884 goto out; | 1077 goto out; 1078 } 1079 /* 1080 * When a sleeping process receives a stop 1081 * signal, process immediately if possible. 1082 * All other (caught or default) signals 1083 * cause the process to run. 1084 */ 1085 if (prop & SA_STOP) { 1086 if (action != SIG_DFL) 1087 goto runfast; 1088 /* 1089 * If a child holding parent blocked, 1090 * stopping could cause deadlock. 1091 */ 1092 if (p->p_flag & P_PPWAIT) 1093 goto out; |
885 p->p_siglist &= ~mask; 886 p->p_xstat = signum; | 1094 SIGDELSET(p->p_siglist, sig); 1095 p->p_xstat = sig; |
887 if ((p->p_pptr->p_procsig->ps_flag & P_NOCLDSTOP) == 0) 888 psignal(p->p_pptr, SIGCHLD); 889 stop(p); 890 goto out; 891 } else 892 goto runfast; 893 /*NOTREACHED*/ 894 895 case SSTOP: 896 /* 897 * If traced process is already stopped, 898 * then no further action is necessary. 899 */ 900 if (p->p_flag & P_TRACED) 901 goto out; 902 903 /* 904 * Kill signal always sets processes running. 905 */ | 1096 if ((p->p_pptr->p_procsig->ps_flag & P_NOCLDSTOP) == 0) 1097 psignal(p->p_pptr, SIGCHLD); 1098 stop(p); 1099 goto out; 1100 } else 1101 goto runfast; 1102 /*NOTREACHED*/ 1103 1104 case SSTOP: 1105 /* 1106 * If traced process is already stopped, 1107 * then no further action is necessary. 1108 */ 1109 if (p->p_flag & P_TRACED) 1110 goto out; 1111 1112 /* 1113 * Kill signal always sets processes running. 1114 */ |
906 if (signum == SIGKILL) | 1115 if (sig == SIGKILL) |
907 goto runfast; 908 909 if (prop & SA_CONT) { 910 /* 911 * If SIGCONT is default (or ignored), we continue the 912 * process but don't leave the signal in p_siglist, as 913 * it has no further action. If SIGCONT is held, we 914 * continue the process and leave the signal in 915 * p_siglist. If the process catches SIGCONT, let it 916 * handle the signal itself. If it isn't waiting on 917 * an event, then it goes back to run state. 918 * Otherwise, process goes back to sleep state. 919 */ 920 if (action == SIG_DFL) | 1116 goto runfast; 1117 1118 if (prop & SA_CONT) { 1119 /* 1120 * If SIGCONT is default (or ignored), we continue the 1121 * process but don't leave the signal in p_siglist, as 1122 * it has no further action. If SIGCONT is held, we 1123 * continue the process and leave the signal in 1124 * p_siglist. If the process catches SIGCONT, let it 1125 * handle the signal itself. If it isn't waiting on 1126 * an event, then it goes back to run state. 1127 * Otherwise, process goes back to sleep state. 1128 */ 1129 if (action == SIG_DFL) |
921 p->p_siglist &= ~mask; | 1130 SIGDELSET(p->p_siglist, sig); |
922 if (action == SIG_CATCH) 923 goto runfast; 924 if (p->p_wchan == 0) 925 goto run; 926 p->p_stat = SSLEEP; 927 goto out; 928 } 929 930 if (prop & SA_STOP) { 931 /* 932 * Already stopped, don't need to stop again. 933 * (If we did the shell could get confused.) 934 */ | 1131 if (action == SIG_CATCH) 1132 goto runfast; 1133 if (p->p_wchan == 0) 1134 goto run; 1135 p->p_stat = SSLEEP; 1136 goto out; 1137 } 1138 1139 if (prop & SA_STOP) { 1140 /* 1141 * Already stopped, don't need to stop again. 1142 * (If we did the shell could get confused.) 1143 */ |
935 p->p_siglist &= ~mask; /* take it away */ | 1144 SIGDELSET(p->p_siglist, sig); |
936 goto out; 937 } 938 939 /* 940 * If process is sleeping interruptibly, then simulate a 941 * wakeup so that when it is continued, it will be made 942 * runnable and can look at the signal. But don't make 943 * the process runnable, leave it stopped. --- 34 unchanged lines hidden (view full) --- 978 * If the current process has received a signal (should be caught or cause 979 * termination, should interrupt current syscall), return the signal number. 980 * Stop signals with default action are processed immediately, then cleared; 981 * they aren't returned. This is checked after each entry to the system for 982 * a syscall or trap (though this can usually be done without calling issignal 983 * by checking the pending signal masks in the CURSIG macro.) The normal call 984 * sequence is 985 * | 1145 goto out; 1146 } 1147 1148 /* 1149 * If process is sleeping interruptibly, then simulate a 1150 * wakeup so that when it is continued, it will be made 1151 * runnable and can look at the signal. But don't make 1152 * the process runnable, leave it stopped. --- 34 unchanged lines hidden (view full) --- 1187 * If the current process has received a signal (should be caught or cause 1188 * termination, should interrupt current syscall), return the signal number. 1189 * Stop signals with default action are processed immediately, then cleared; 1190 * they aren't returned. This is checked after each entry to the system for 1191 * a syscall or trap (though this can usually be done without calling issignal 1192 * by checking the pending signal masks in the CURSIG macro.) The normal call 1193 * sequence is 1194 * |
986 * while (signum = CURSIG(curproc)) 987 * postsig(signum); | 1195 * while (sig = CURSIG(curproc)) 1196 * postsig(sig); |
988 */ 989int 990issignal(p) 991 register struct proc *p; 992{ | 1197 */ 1198int 1199issignal(p) 1200 register struct proc *p; 1201{ |
993 register int signum, mask, prop; | 1202 sigset_t mask; 1203 register int sig, prop; |
994 995 for (;;) { 996 int traced = (p->p_flag & P_TRACED) || (p->p_stops & S_SIG); 997 | 1204 1205 for (;;) { 1206 int traced = (p->p_flag & P_TRACED) || (p->p_stops & S_SIG); 1207 |
998 mask = p->p_siglist & ~p->p_sigmask; | 1208 mask = p->p_siglist; 1209 SIGSETNAND(mask, p->p_sigmask); |
999 if (p->p_flag & P_PPWAIT) | 1210 if (p->p_flag & P_PPWAIT) |
1000 mask &= ~stopsigmask; 1001 if (mask == 0) /* no signal to send */ | 1211 SIG_STOPSIGMASK(mask); 1212 if (!SIGNOTEMPTY(mask)) /* no signal to send */ |
1002 return (0); | 1213 return (0); |
1003 signum = ffs((long)mask); 1004 mask = sigmask(signum); 1005 prop = sigprop[signum]; | 1214 sig = sig_ffs(&mask); 1215 prop = sigprop(sig); |
1006 | 1216 |
1007 STOPEVENT(p, S_SIG, signum); | 1217 STOPEVENT(p, S_SIG, sig); |
1008 1009 /* 1010 * We should see pending but ignored signals 1011 * only if P_TRACED was on when they were posted. 1012 */ | 1218 1219 /* 1220 * We should see pending but ignored signals 1221 * only if P_TRACED was on when they were posted. 1222 */ |
1013 if ((mask & p->p_sigignore) && (traced == 0)) { 1014 p->p_siglist &= ~mask; | 1223 if (SIGISMEMBER(p->p_sigignore, sig) && (traced == 0)) { 1224 SIGDELSET(p->p_siglist, sig); |
1015 continue; 1016 } 1017 if (p->p_flag & P_TRACED && (p->p_flag & P_PPWAIT) == 0) { 1018 /* 1019 * If traced, always stop, and stay 1020 * stopped until released by the parent. 1021 */ | 1225 continue; 1226 } 1227 if (p->p_flag & P_TRACED && (p->p_flag & P_PPWAIT) == 0) { 1228 /* 1229 * If traced, always stop, and stay 1230 * stopped until released by the parent. 1231 */ |
1022 p->p_xstat = signum; | 1232 p->p_xstat = sig; |
1023 psignal(p->p_pptr, SIGCHLD); 1024 do { 1025 stop(p); 1026 mi_switch(); 1027 } while (!trace_req(p) 1028 && p->p_flag & P_TRACED); 1029 1030 /* --- 4 unchanged lines hidden (view full) --- 1035 if ((p->p_flag & P_TRACED) == 0) 1036 continue; 1037 1038 /* 1039 * If parent wants us to take the signal, 1040 * then it will leave it in p->p_xstat; 1041 * otherwise we just look for signals again. 1042 */ | 1233 psignal(p->p_pptr, SIGCHLD); 1234 do { 1235 stop(p); 1236 mi_switch(); 1237 } while (!trace_req(p) 1238 && p->p_flag & P_TRACED); 1239 1240 /* --- 4 unchanged lines hidden (view full) --- 1245 if ((p->p_flag & P_TRACED) == 0) 1246 continue; 1247 1248 /* 1249 * If parent wants us to take the signal, 1250 * then it will leave it in p->p_xstat; 1251 * otherwise we just look for signals again. 1252 */ |
1043 p->p_siglist &= ~mask; /* clear the old signal */ 1044 signum = p->p_xstat; 1045 if (signum == 0) | 1253 SIGDELSET(p->p_siglist, sig); /* clear old signal */ 1254 sig = p->p_xstat; 1255 if (sig == 0) |
1046 continue; 1047 1048 /* 1049 * Put the new signal into p_siglist. If the 1050 * signal is being masked, look for other signals. 1051 */ | 1256 continue; 1257 1258 /* 1259 * Put the new signal into p_siglist. If the 1260 * signal is being masked, look for other signals. 1261 */ |
1052 mask = sigmask(signum); 1053 p->p_siglist |= mask; 1054 if (p->p_sigmask & mask) | 1262 SIGADDSET(p->p_siglist, sig); 1263 if (SIGISMEMBER(p->p_sigmask, sig)) |
1055 continue; 1056 } 1057 1058 /* 1059 * Decide whether the signal should be returned. 1060 * Return the signal's number, or fall through 1061 * to clear it from the pending mask. 1062 */ | 1264 continue; 1265 } 1266 1267 /* 1268 * Decide whether the signal should be returned. 1269 * Return the signal's number, or fall through 1270 * to clear it from the pending mask. 1271 */ |
1063 switch ((int)(intptr_t)p->p_sigacts->ps_sigact[signum]) { | 1272 switch ((int)(intptr_t)p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) { |
1064 1065 case (int)SIG_DFL: 1066 /* 1067 * Don't take default actions on system processes. 1068 */ 1069 if (p->p_pid <= 1) { 1070#ifdef DIAGNOSTIC 1071 /* 1072 * Are you sure you want to ignore SIGSEGV 1073 * in init? XXX 1074 */ 1075 printf("Process (pid %lu) got signal %d\n", | 1273 1274 case (int)SIG_DFL: 1275 /* 1276 * Don't take default actions on system processes. 1277 */ 1278 if (p->p_pid <= 1) { 1279#ifdef DIAGNOSTIC 1280 /* 1281 * Are you sure you want to ignore SIGSEGV 1282 * in init? XXX 1283 */ 1284 printf("Process (pid %lu) got signal %d\n", |
1076 (u_long)p->p_pid, signum); | 1285 (u_long)p->p_pid, sig); |
1077#endif 1078 break; /* == ignore */ 1079 } 1080 /* 1081 * If there is a pending stop signal to process 1082 * with default action, stop here, 1083 * then clear the signal. However, 1084 * if process is member of an orphaned 1085 * process group, ignore tty stop signals. 1086 */ 1087 if (prop & SA_STOP) { 1088 if (p->p_flag & P_TRACED || 1089 (p->p_pgrp->pg_jobc == 0 && 1090 prop & SA_TTYSTOP)) 1091 break; /* == ignore */ | 1286#endif 1287 break; /* == ignore */ 1288 } 1289 /* 1290 * If there is a pending stop signal to process 1291 * with default action, stop here, 1292 * then clear the signal. However, 1293 * if process is member of an orphaned 1294 * process group, ignore tty stop signals. 1295 */ 1296 if (prop & SA_STOP) { 1297 if (p->p_flag & P_TRACED || 1298 (p->p_pgrp->pg_jobc == 0 && 1299 prop & SA_TTYSTOP)) 1300 break; /* == ignore */ |
1092 p->p_xstat = signum; | 1301 p->p_xstat = sig; |
1093 stop(p); 1094 if ((p->p_pptr->p_procsig->ps_flag & P_NOCLDSTOP) == 0) 1095 psignal(p->p_pptr, SIGCHLD); 1096 mi_switch(); 1097 break; 1098 } else if (prop & SA_IGNORE) { 1099 /* 1100 * Except for SIGCONT, shouldn't get here. 1101 * Default action is to ignore; drop it. 1102 */ 1103 break; /* == ignore */ 1104 } else | 1302 stop(p); 1303 if ((p->p_pptr->p_procsig->ps_flag & P_NOCLDSTOP) == 0) 1304 psignal(p->p_pptr, SIGCHLD); 1305 mi_switch(); 1306 break; 1307 } else if (prop & SA_IGNORE) { 1308 /* 1309 * Except for SIGCONT, shouldn't get here. 1310 * Default action is to ignore; drop it. 1311 */ 1312 break; /* == ignore */ 1313 } else |
1105 return (signum); | 1314 return (sig); |
1106 /*NOTREACHED*/ 1107 1108 case (int)SIG_IGN: 1109 /* 1110 * Masking above should prevent us ever trying 1111 * to take action on an ignored signal other 1112 * than SIGCONT, unless process is traced. 1113 */ 1114 if ((prop & SA_CONT) == 0 && 1115 (p->p_flag & P_TRACED) == 0) 1116 printf("issignal\n"); 1117 break; /* == ignore */ 1118 1119 default: 1120 /* 1121 * This signal has an action, let 1122 * postsig() process it. 1123 */ | 1315 /*NOTREACHED*/ 1316 1317 case (int)SIG_IGN: 1318 /* 1319 * Masking above should prevent us ever trying 1320 * to take action on an ignored signal other 1321 * than SIGCONT, unless process is traced. 1322 */ 1323 if ((prop & SA_CONT) == 0 && 1324 (p->p_flag & P_TRACED) == 0) 1325 printf("issignal\n"); 1326 break; /* == ignore */ 1327 1328 default: 1329 /* 1330 * This signal has an action, let 1331 * postsig() process it. 1332 */ |
1124 return (signum); | 1333 return (sig); |
1125 } | 1334 } |
1126 p->p_siglist &= ~mask; /* take the signal! */ | 1335 SIGDELSET(p->p_siglist, sig); /* take the signal! */ |
1127 } 1128 /* NOTREACHED */ 1129} 1130 1131/* 1132 * Put the argument process into the stopped state and notify the parent 1133 * via wakeup. Signals are handled elsewhere. The process must not be 1134 * on the run queue. --- 8 unchanged lines hidden (view full) --- 1143 wakeup((caddr_t)p->p_pptr); 1144} 1145 1146/* 1147 * Take the action for the specified signal 1148 * from the current set of pending signals. 1149 */ 1150void | 1336 } 1337 /* NOTREACHED */ 1338} 1339 1340/* 1341 * Put the argument process into the stopped state and notify the parent 1342 * via wakeup. Signals are handled elsewhere. The process must not be 1343 * on the run queue. --- 8 unchanged lines hidden (view full) --- 1352 wakeup((caddr_t)p->p_pptr); 1353} 1354 1355/* 1356 * Take the action for the specified signal 1357 * from the current set of pending signals. 1358 */ 1359void |
1151postsig(signum) 1152 register int signum; | 1360postsig(sig) 1361 register int sig; |
1153{ 1154 register struct proc *p = curproc; | 1362{ 1363 register struct proc *p = curproc; |
1155 register struct sigacts *ps = p->p_sigacts; 1156 register sig_t action; 1157 int code, mask, returnmask; | 1364 struct sigacts *ps = p->p_sigacts; 1365 sig_t action; 1366 sigset_t returnmask; 1367 int code; |
1158 | 1368 |
1159 KASSERT(signum != 0, ("postsig")); | 1369 KASSERT(sig != 0, ("postsig")); |
1160 | 1370 |
1161 mask = sigmask(signum); 1162 p->p_siglist &= ~mask; 1163 action = ps->ps_sigact[signum]; | 1371 SIGDELSET(p->p_siglist, sig); 1372 action = ps->ps_sigact[_SIG_IDX(sig)]; |
1164#ifdef KTRACE 1165 if (KTRPOINT(p, KTR_PSIG)) 1166 ktrpsig(p->p_tracep, | 1373#ifdef KTRACE 1374 if (KTRPOINT(p, KTR_PSIG)) 1375 ktrpsig(p->p_tracep, |
1167 signum, action, p->p_oldsigmask ? 1168 p->p_oldsigmask : p->p_sigmask, 0); | 1376 sig, action, SIGNOTEMPTY(p->p_oldsigmask) ? 1377 &p->p_oldsigmask : &p->p_sigmask, 0); |
1169#endif | 1378#endif |
1170 STOPEVENT(p, S_SIG, signum); | 1379 STOPEVENT(p, S_SIG, sig); |
1171 1172 if (action == SIG_DFL) { 1173 /* 1174 * Default action, where the default is to kill 1175 * the process. (Other cases were ignored above.) 1176 */ | 1380 1381 if (action == SIG_DFL) { 1382 /* 1383 * Default action, where the default is to kill 1384 * the process. (Other cases were ignored above.) 1385 */ |
1177 sigexit(p, signum); | 1386 sigexit(p, sig); |
1178 /* NOTREACHED */ 1179 } else { 1180 /* 1181 * If we get here, the signal must be caught. 1182 */ | 1387 /* NOTREACHED */ 1388 } else { 1389 /* 1390 * If we get here, the signal must be caught. 1391 */ |
1183 KASSERT(action != SIG_IGN && (p->p_sigmask & mask) == 0, | 1392 KASSERT(action != SIG_IGN && !SIGISMEMBER(p->p_sigmask, sig), |
1184 ("postsig action")); 1185 /* 1186 * Set the new mask value and also defer further 1187 * occurences of this signal. 1188 * 1189 * Special case: user has done a sigpause. Here the 1190 * current mask is not of interest, but rather the 1191 * mask from before the sigpause is what we want 1192 * restored after the signal processing is completed. 1193 */ 1194 (void) splhigh(); | 1393 ("postsig action")); 1394 /* 1395 * Set the new mask value and also defer further 1396 * occurences of this signal. 1397 * 1398 * Special case: user has done a sigpause. Here the 1399 * current mask is not of interest, but rather the 1400 * mask from before the sigpause is what we want 1401 * restored after the signal processing is completed. 1402 */ 1403 (void) splhigh(); |
1195 if (p->p_oldsigmask) { | 1404 if (SIGNOTEMPTY(p->p_oldsigmask)) { |
1196 returnmask = p->p_oldsigmask; | 1405 returnmask = p->p_oldsigmask; |
1197 p->p_oldsigmask = 0; | 1406 SIGEMPTYSET(p->p_oldsigmask); |
1198 } else 1199 returnmask = p->p_sigmask; | 1407 } else 1408 returnmask = p->p_sigmask; |
1200 p->p_sigmask |= ps->ps_catchmask[signum] | 1201 (mask & ~ps->ps_signodefer); 1202 if ((ps->ps_sigreset & mask) != 0) { | 1409 1410 SIGSETOR(p->p_sigmask, ps->ps_catchmask[_SIG_IDX(sig)]); 1411 if (!SIGISMEMBER(ps->ps_signodefer, sig)) 1412 SIGADDSET(p->p_sigmask, sig); 1413 1414 if (SIGISMEMBER(ps->ps_sigreset, sig)) { |
1203 /* | 1415 /* |
1204 * See setsigvec() for origin of this code. | 1416 * See do_sigaction() for origin of this code. |
1205 */ | 1417 */ |
1206 p->p_sigcatch &= ~mask; 1207 if (signum != SIGCONT && sigprop[signum] & SA_IGNORE) 1208 p->p_sigignore |= mask; 1209 ps->ps_sigact[signum] = SIG_DFL; | 1418 SIGDELSET(p->p_sigcatch, sig); 1419 if (sig != SIGCONT && 1420 sigprop(sig) & SA_IGNORE) 1421 SIGADDSET(p->p_sigignore, sig); 1422 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL; |
1210 } 1211 (void) spl0(); 1212 p->p_stats->p_ru.ru_nsignals++; | 1423 } 1424 (void) spl0(); 1425 p->p_stats->p_ru.ru_nsignals++; |
1213 if (p->p_sig != signum) { | 1426 if (p->p_sig != sig) { |
1214 code = 0; 1215 } else { 1216 code = p->p_code; 1217 p->p_code = 0; 1218 p->p_sig = 0; 1219 } | 1427 code = 0; 1428 } else { 1429 code = p->p_code; 1430 p->p_code = 0; 1431 p->p_sig = 0; 1432 } |
1220 (*p->p_sysent->sv_sendsig)(action, signum, returnmask, code); | 1433 (*p->p_sysent->sv_sendsig)(action, sig, &returnmask, code); |
1221 } 1222} 1223 1224/* 1225 * Kill the current process for stated reason. 1226 */ 1227void 1228killproc(p, why) --- 9 unchanged lines hidden (view full) --- 1238 * Force the current process to exit with the specified signal, dumping core 1239 * if appropriate. We bypass the normal tests for masked and caught signals, 1240 * allowing unrecoverable failures to terminate the process without changing 1241 * signal state. Mark the accounting record with the signal termination. 1242 * If dumping core, save the signal number for the debugger. Calls exit and 1243 * does not return. 1244 */ 1245void | 1434 } 1435} 1436 1437/* 1438 * Kill the current process for stated reason. 1439 */ 1440void 1441killproc(p, why) --- 9 unchanged lines hidden (view full) --- 1451 * Force the current process to exit with the specified signal, dumping core 1452 * if appropriate. We bypass the normal tests for masked and caught signals, 1453 * allowing unrecoverable failures to terminate the process without changing 1454 * signal state. Mark the accounting record with the signal termination. 1455 * If dumping core, save the signal number for the debugger. Calls exit and 1456 * does not return. 1457 */ 1458void |
1246sigexit(p, signum) | 1459sigexit(p, sig) |
1247 register struct proc *p; | 1460 register struct proc *p; |
1248 int signum; | 1461 int sig; |
1249{ 1250 1251 p->p_acflag |= AXSIG; | 1462{ 1463 1464 p->p_acflag |= AXSIG; |
1252 if (sigprop[signum] & SA_CORE) { 1253 p->p_sig = signum; | 1465 if (sigprop(sig) & SA_CORE) { 1466 p->p_sig = sig; |
1254 /* 1255 * Log signals which would cause core dumps 1256 * (Log as LOG_INFO to appease those who don't want 1257 * these messages.) 1258 * XXX : Todo, as well as euid, write out ruid too 1259 */ 1260 if (coredump(p) == 0) | 1467 /* 1468 * Log signals which would cause core dumps 1469 * (Log as LOG_INFO to appease those who don't want 1470 * these messages.) 1471 * XXX : Todo, as well as euid, write out ruid too 1472 */ 1473 if (coredump(p) == 0) |
1261 signum |= WCOREFLAG; | 1474 sig |= WCOREFLAG; |
1262 if (kern_logsigexit) 1263 log(LOG_INFO, 1264 "pid %d (%s), uid %d: exited on signal %d%s\n", 1265 p->p_pid, p->p_comm, 1266 p->p_cred && p->p_ucred ? p->p_ucred->cr_uid : -1, | 1475 if (kern_logsigexit) 1476 log(LOG_INFO, 1477 "pid %d (%s), uid %d: exited on signal %d%s\n", 1478 p->p_pid, p->p_comm, 1479 p->p_cred && p->p_ucred ? p->p_ucred->cr_uid : -1, |
1267 signum &~ WCOREFLAG, 1268 signum & WCOREFLAG ? " (core dumped)" : ""); | 1480 sig &~ WCOREFLAG, 1481 sig & WCOREFLAG ? " (core dumped)" : ""); |
1269 } | 1482 } |
1270 exit1(p, W_EXITCODE(0, signum)); | 1483 exit1(p, W_EXITCODE(0, sig)); |
1271 /* NOTREACHED */ 1272} 1273 1274static char corefilename[MAXPATHLEN+1] = {"%N.core"}; 1275SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RW, corefilename, 1276 sizeof(corefilename), "process corefile name format string"); 1277 1278/* --- 159 unchanged lines hidden (view full) --- 1438 return (EINVAL); 1439} 1440 1441/* 1442 * Send a signal to a SIGIO or SIGURG to a process or process group using 1443 * stored credentials rather than those of the current process. 1444 */ 1445void | 1484 /* NOTREACHED */ 1485} 1486 1487static char corefilename[MAXPATHLEN+1] = {"%N.core"}; 1488SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RW, corefilename, 1489 sizeof(corefilename), "process corefile name format string"); 1490 1491/* --- 159 unchanged lines hidden (view full) --- 1651 return (EINVAL); 1652} 1653 1654/* 1655 * Send a signal to a SIGIO or SIGURG to a process or process group using 1656 * stored credentials rather than those of the current process. 1657 */ 1658void |
1446pgsigio(sigio, signum, checkctty) | 1659pgsigio(sigio, sig, checkctty) |
1447 struct sigio *sigio; | 1660 struct sigio *sigio; |
1448 int signum, checkctty; | 1661 int sig, checkctty; |
1449{ 1450 if (sigio == NULL) 1451 return; 1452 1453 if (sigio->sio_pgid > 0) { 1454 if (CANSIGIO(sigio->sio_ruid, sigio->sio_ucred, 1455 sigio->sio_proc)) | 1662{ 1663 if (sigio == NULL) 1664 return; 1665 1666 if (sigio->sio_pgid > 0) { 1667 if (CANSIGIO(sigio->sio_ruid, sigio->sio_ucred, 1668 sigio->sio_proc)) |
1456 psignal(sigio->sio_proc, signum); | 1669 psignal(sigio->sio_proc, sig); |
1457 } else if (sigio->sio_pgid < 0) { 1458 struct proc *p; 1459 1460 for (p = sigio->sio_pgrp->pg_members.lh_first; p != NULL; 1461 p = p->p_pglist.le_next) 1462 if (CANSIGIO(sigio->sio_ruid, sigio->sio_ucred, p) && 1463 (checkctty == 0 || (p->p_flag & P_CONTROLT))) | 1670 } else if (sigio->sio_pgid < 0) { 1671 struct proc *p; 1672 1673 for (p = sigio->sio_pgrp->pg_members.lh_first; p != NULL; 1674 p = p->p_pglist.le_next) 1675 if (CANSIGIO(sigio->sio_ruid, sigio->sio_ucred, p) && 1676 (checkctty == 0 || (p->p_flag & P_CONTROLT))) |
1464 psignal(p, signum); | 1677 psignal(p, sig); |
1465 } 1466} | 1678 } 1679} |