1*18308Smckusick /* kern_sig.c 6.11 85/03/12 */ 27421Sroot 39755Ssam #include "../machine/reg.h" 49755Ssam #include "../machine/pte.h" 59755Ssam #include "../machine/psl.h" 69755Ssam 717092Sbloom #include "param.h" 817092Sbloom #include "systm.h" 917092Sbloom #include "dir.h" 1017092Sbloom #include "user.h" 1117092Sbloom #include "inode.h" 1217092Sbloom #include "proc.h" 1317092Sbloom #include "timeb.h" 1417092Sbloom #include "times.h" 1517092Sbloom #include "conf.h" 1617092Sbloom #include "buf.h" 1717092Sbloom #include "mount.h" 1817092Sbloom #include "text.h" 1917092Sbloom #include "seg.h" 2017092Sbloom #include "vm.h" 2117092Sbloom #include "acct.h" 2217092Sbloom #include "uio.h" 2317092Sbloom #include "kernel.h" 247421Sroot 2517153Sbloom #define cantmask (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP)) 2612951Ssam 2717013Smckusick /* 2817013Smckusick * Generalized interface signal handler. 2917013Smckusick */ 307499Sroot sigvec() 317421Sroot { 3212951Ssam register struct a { 3312882Ssam int signo; 3412951Ssam struct sigvec *nsv; 3512951Ssam struct sigvec *osv; 3612882Ssam } *uap = (struct a *)u.u_ap; 3712951Ssam struct sigvec vec; 3812951Ssam register struct sigvec *sv; 3912882Ssam register int sig; 40*18308Smckusick int bit; 417421Sroot 4212882Ssam sig = uap->signo; 4312951Ssam if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) { 4412882Ssam u.u_error = EINVAL; 4512882Ssam return; 4612882Ssam } 4712951Ssam sv = &vec; 4812951Ssam if (uap->osv) { 4912951Ssam sv->sv_handler = u.u_signal[sig]; 5012951Ssam sv->sv_mask = u.u_sigmask[sig]; 51*18308Smckusick bit = sigmask(sig); 52*18308Smckusick sv->sv_flags = 0; 53*18308Smckusick if ((u.u_sigonstack & bit) != 0) 54*18308Smckusick sv->sv_flags |= SV_ONSTACK; 55*18308Smckusick if ((u.u_sigintr & bit) != 0) 56*18308Smckusick sv->sv_flags |= SV_INTERRUPT; 5712951Ssam u.u_error = 5812951Ssam copyout((caddr_t)sv, (caddr_t)uap->osv, sizeof (vec)); 5912951Ssam if (u.u_error) 6012951Ssam return; 6112951Ssam } 6212951Ssam if (uap->nsv) { 6312951Ssam u.u_error = 6412951Ssam copyin((caddr_t)uap->nsv, (caddr_t)sv, sizeof (vec)); 6512951Ssam if (u.u_error) 6612951Ssam return; 6712951Ssam if (sig == SIGCONT && sv->sv_handler == SIG_IGN) { 6812951Ssam u.u_error = EINVAL; 6912951Ssam return; 7012951Ssam } 7112951Ssam setsigvec(sig, sv); 7212951Ssam } 737421Sroot } 747421Sroot 7512951Ssam setsigvec(sig, sv) 7612951Ssam int sig; 7712951Ssam register struct sigvec *sv; 7812882Ssam { 7912882Ssam register struct proc *p; 8012951Ssam register int bit; 8112882Ssam 8217153Sbloom bit = sigmask(sig); 8312882Ssam p = u.u_procp; 8412882Ssam /* 8512882Ssam * Change setting atomically. 8612882Ssam */ 8717153Sbloom (void) splhigh(); 8812951Ssam u.u_signal[sig] = sv->sv_handler; 8912951Ssam u.u_sigmask[sig] = sv->sv_mask &~ cantmask; 90*18308Smckusick if (sv->sv_flags & SV_INTERRUPT) 91*18308Smckusick u.u_sigintr |= bit; 92*18308Smckusick else 93*18308Smckusick u.u_sigintr &= ~bit; 94*18308Smckusick if (sv->sv_flags & SV_ONSTACK) 9512951Ssam u.u_sigonstack |= bit; 9612951Ssam else 9712951Ssam u.u_sigonstack &= ~bit; 9812951Ssam if (sv->sv_handler == SIG_IGN) { 9912951Ssam p->p_sig &= ~bit; /* never to be seen again */ 10012951Ssam p->p_sigignore |= bit; 10112951Ssam p->p_sigcatch &= ~bit; 10212882Ssam } else { 10312951Ssam p->p_sigignore &= ~bit; 10412951Ssam if (sv->sv_handler == SIG_DFL) 10512951Ssam p->p_sigcatch &= ~bit; 10612882Ssam else 10712951Ssam p->p_sigcatch |= bit; 10812882Ssam } 10912882Ssam (void) spl0(); 11012882Ssam } 11112882Ssam 1127499Sroot sigblock() 1137421Sroot { 11412882Ssam struct a { 11517153Sbloom int mask; 11612882Ssam } *uap = (struct a *)u.u_ap; 11712951Ssam register struct proc *p = u.u_procp; 1187499Sroot 11917153Sbloom (void) splhigh(); 12012882Ssam u.u_r.r_val1 = p->p_sigmask; 12117153Sbloom p->p_sigmask |= uap->mask &~ cantmask; 12212882Ssam (void) spl0(); 1237499Sroot } 1247499Sroot 1257499Sroot sigsetmask() 1267499Sroot { 12712882Ssam struct a { 12817153Sbloom int mask; 12912882Ssam } *uap = (struct a *)u.u_ap; 13012882Ssam register struct proc *p = u.u_procp; 1317499Sroot 13217153Sbloom (void) splhigh(); 13312882Ssam u.u_r.r_val1 = p->p_sigmask; 13417153Sbloom p->p_sigmask = uap->mask &~ cantmask; 13512882Ssam (void) spl0(); 1367499Sroot } 1377499Sroot 1387499Sroot sigpause() 1397499Sroot { 14012882Ssam struct a { 14117153Sbloom int mask; 14212882Ssam } *uap = (struct a *)u.u_ap; 14312882Ssam register struct proc *p = u.u_procp; 1447499Sroot 14512882Ssam /* 14612882Ssam * When returning from sigpause, we want 14712882Ssam * the old mask to be restored after the 14812882Ssam * signal handler has finished. Thus, we 14912882Ssam * save it here and mark the proc structure 15012882Ssam * to indicate this (should be in u.). 15112882Ssam */ 15212882Ssam u.u_oldmask = p->p_sigmask; 15312882Ssam p->p_flag |= SOMASK; 15417153Sbloom p->p_sigmask = uap->mask &~ cantmask; 15512882Ssam for (;;) 15612882Ssam sleep((caddr_t)&u, PSLEP); 15712882Ssam /*NOTREACHED*/ 1587499Sroot } 15912951Ssam #undef cantmask 1607499Sroot 1617499Sroot sigstack() 1627499Sroot { 16312951Ssam register struct a { 16412951Ssam struct sigstack *nss; 16512951Ssam struct sigstack *oss; 16612882Ssam } *uap = (struct a *)u.u_ap; 16712951Ssam struct sigstack ss; 1687499Sroot 16912951Ssam if (uap->oss) { 17012951Ssam u.u_error = copyout((caddr_t)&u.u_sigstack, (caddr_t)uap->oss, 17112951Ssam sizeof (struct sigstack)); 17212951Ssam if (u.u_error) 17312951Ssam return; 17412951Ssam } 17512951Ssam if (uap->nss) { 17612951Ssam u.u_error = 17712951Ssam copyin((caddr_t)uap->nss, (caddr_t)&ss, sizeof (ss)); 17812951Ssam if (u.u_error == 0) 17912951Ssam u.u_sigstack = ss; 18012951Ssam } 1817499Sroot } 1827499Sroot 18313227Ssam /* KILL SHOULD BE UPDATED */ 18413227Ssam 1858032Sroot kill() 1868032Sroot { 18712882Ssam register struct a { 18812882Ssam int pid; 18912882Ssam int signo; 19012882Ssam } *uap = (struct a *)u.u_ap; 1918032Sroot 19213227Ssam u.u_error = kill1(uap->signo < 0, 19313227Ssam uap->signo < 0 ? -uap->signo : uap->signo, uap->pid); 1948032Sroot } 1958032Sroot 1968032Sroot killpg() 1978032Sroot { 1989989Ssam register struct a { 1999989Ssam int pgrp; 2009989Ssam int signo; 2019989Ssam } *uap = (struct a *)u.u_ap; 2028032Sroot 20312750Ssam u.u_error = kill1(1, uap->signo, uap->pgrp); 2048032Sroot } 2058032Sroot 20612882Ssam /* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */ 20712882Ssam 20812750Ssam kill1(ispgrp, signo, who) 2099989Ssam int ispgrp, signo, who; 2109989Ssam { 2119989Ssam register struct proc *p; 2129989Ssam int f, priv = 0; 2139989Ssam 21412835Ssam if (signo < 0 || signo > NSIG) 2159989Ssam return (EINVAL); 2169989Ssam if (who > 0 && !ispgrp) { 2179989Ssam p = pfind(who); 21814926Smckusick if (p == 0) 2199989Ssam return (ESRCH); 22014926Smckusick if (u.u_uid && u.u_uid != p->p_uid) 22114926Smckusick return (EPERM); 22212835Ssam if (signo) 22312835Ssam psignal(p, signo); 2249989Ssam return (0); 2257421Sroot } 2269989Ssam if (who == -1 && u.u_uid == 0) 2279989Ssam priv++, who = 0, ispgrp = 1; /* like sending to pgrp */ 2289989Ssam else if (who == 0) { 2297421Sroot /* 2307421Sroot * Zero process id means send to my process group. 2317421Sroot */ 2329989Ssam ispgrp = 1; 2339989Ssam who = u.u_procp->p_pgrp; 2349989Ssam if (who == 0) 2359989Ssam return (EINVAL); 2367421Sroot } 23716531Skarels for (f = 0, p = allproc; p != NULL; p = p->p_nxt) { 2389989Ssam if (!ispgrp) { 2399989Ssam if (p->p_pid != who) 2407421Sroot continue; 2419989Ssam } else if (p->p_pgrp != who && priv == 0 || p->p_ppid == 0 || 2429989Ssam (p->p_flag&SSYS) || (priv && p == u.u_procp)) 2437421Sroot continue; 2447421Sroot if (u.u_uid != 0 && u.u_uid != p->p_uid && 2459989Ssam (signo != SIGCONT || !inferior(p))) 2467421Sroot continue; 2477421Sroot f++; 24812835Ssam if (signo) 24912835Ssam psignal(p, signo); 2507421Sroot } 25112750Ssam return (f == 0 ? ESRCH : 0); 2527421Sroot } 2537421Sroot 2547421Sroot /* 2557421Sroot * Send the specified signal to 2567421Sroot * all processes with 'pgrp' as 2577421Sroot * process group. 2587421Sroot */ 2597421Sroot gsignal(pgrp, sig) 2607421Sroot register int pgrp; 2617421Sroot { 2627421Sroot register struct proc *p; 2637421Sroot 2647421Sroot if (pgrp == 0) 2657421Sroot return; 26616531Skarels for (p = allproc; p != NULL; p = p->p_nxt) 2677421Sroot if (p->p_pgrp == pgrp) 2687421Sroot psignal(p, sig); 2697421Sroot } 2707421Sroot 2717421Sroot /* 2727421Sroot * Send the specified signal to 2737421Sroot * the specified process. 2747421Sroot */ 2757421Sroot psignal(p, sig) 2767421Sroot register struct proc *p; 2777421Sroot register int sig; 2787421Sroot { 2797421Sroot register int s; 2807421Sroot register int (*action)(); 28117153Sbloom int mask; 2827421Sroot 2837421Sroot if ((unsigned)sig >= NSIG) 2847421Sroot return; 28517153Sbloom mask = sigmask(sig); 2867421Sroot 2877421Sroot /* 2887421Sroot * If proc is traced, always give parent a chance. 2897421Sroot */ 2907421Sroot if (p->p_flag & STRC) 2917421Sroot action = SIG_DFL; 2927421Sroot else { 2937421Sroot /* 29412882Ssam * If the signal is being ignored, 29512882Ssam * then we forget about it immediately. 2967421Sroot */ 29717153Sbloom if (p->p_sigignore & mask) 2987421Sroot return; 29917153Sbloom if (p->p_sigmask & mask) 30012882Ssam action = SIG_HOLD; 30117153Sbloom else if (p->p_sigcatch & mask) 30212882Ssam action = SIG_CATCH; 30312882Ssam else 30412882Ssam action = SIG_DFL; 3057421Sroot } 30617153Sbloom #define stops (sigmask(SIGSTOP)|sigmask(SIGTSTP)| \ 30717153Sbloom sigmask(SIGTTIN)|sigmask(SIGTTOU)) 3087421Sroot if (sig) { 30917153Sbloom p->p_sig |= mask; 3107421Sroot switch (sig) { 3117421Sroot 3127421Sroot case SIGTERM: 31312882Ssam if ((p->p_flag&STRC) || action != SIG_DFL) 3147421Sroot break; 3157421Sroot /* fall into ... */ 3167421Sroot 3177421Sroot case SIGKILL: 3187421Sroot if (p->p_nice > NZERO) 3197421Sroot p->p_nice = NZERO; 3207421Sroot break; 3217421Sroot 3227421Sroot case SIGCONT: 3237421Sroot p->p_sig &= ~stops; 3247421Sroot break; 3257421Sroot 3267421Sroot case SIGSTOP: 3277421Sroot case SIGTSTP: 3287421Sroot case SIGTTIN: 3297421Sroot case SIGTTOU: 33017153Sbloom p->p_sig &= ~sigmask(SIGCONT); 3317421Sroot break; 3327421Sroot } 3337421Sroot } 3347421Sroot #undef stops 3357421Sroot /* 3367421Sroot * Defer further processing for signals which are held. 3377421Sroot */ 3387421Sroot if (action == SIG_HOLD) 3397421Sroot return; 34017153Sbloom s = splhigh(); 3417421Sroot switch (p->p_stat) { 3427421Sroot 3437421Sroot case SSLEEP: 3447421Sroot /* 3457421Sroot * If process is sleeping at negative priority 3467421Sroot * we can't interrupt the sleep... the signal will 3477421Sroot * be noticed when the process returns through 3487421Sroot * trap() or syscall(). 3497421Sroot */ 3507421Sroot if (p->p_pri <= PZERO) 3517421Sroot goto out; 3527421Sroot /* 3537421Sroot * Process is sleeping and traced... make it runnable 3547421Sroot * so it can discover the signal in issig() and stop 3557421Sroot * for the parent. 3567421Sroot */ 3577421Sroot if (p->p_flag&STRC) 3587421Sroot goto run; 3597421Sroot switch (sig) { 3607421Sroot 3617421Sroot case SIGSTOP: 3627421Sroot case SIGTSTP: 3637421Sroot case SIGTTIN: 3647421Sroot case SIGTTOU: 3657421Sroot /* 3667421Sroot * These are the signals which by default 3677421Sroot * stop a process. 3687421Sroot */ 3697421Sroot if (action != SIG_DFL) 3707421Sroot goto run; 3717421Sroot /* 3727421Sroot * Don't clog system with children of init 3737421Sroot * stopped from the keyboard. 3747421Sroot */ 3757421Sroot if (sig != SIGSTOP && p->p_pptr == &proc[1]) { 3767421Sroot psignal(p, SIGKILL); 37717153Sbloom p->p_sig &= ~mask; 3787421Sroot splx(s); 3797421Sroot return; 3807421Sroot } 3817421Sroot /* 3827421Sroot * If a child in vfork(), stopping could 3837421Sroot * cause deadlock. 3847421Sroot */ 3857421Sroot if (p->p_flag&SVFORK) 3867421Sroot goto out; 38717153Sbloom p->p_sig &= ~mask; 3887421Sroot p->p_cursig = sig; 3897421Sroot stop(p); 3907421Sroot goto out; 3917421Sroot 3927421Sroot case SIGIO: 3937421Sroot case SIGURG: 3947421Sroot case SIGCHLD: 39517597Sbloom case SIGWINCH: 3967421Sroot /* 3977421Sroot * These signals are special in that they 3987421Sroot * don't get propogated... if the process 3997421Sroot * isn't interested, forget it. 4007421Sroot */ 4017421Sroot if (action != SIG_DFL) 4027421Sroot goto run; 40317153Sbloom p->p_sig &= ~mask; /* take it away */ 4047421Sroot goto out; 4057421Sroot 4067421Sroot default: 4077421Sroot /* 4087421Sroot * All other signals cause the process to run 4097421Sroot */ 4107421Sroot goto run; 4117421Sroot } 4127421Sroot /*NOTREACHED*/ 4137421Sroot 4147421Sroot case SSTOP: 4157421Sroot /* 4167421Sroot * If traced process is already stopped, 4177421Sroot * then no further action is necessary. 4187421Sroot */ 4197421Sroot if (p->p_flag&STRC) 4207421Sroot goto out; 4217421Sroot switch (sig) { 4227421Sroot 4237421Sroot case SIGKILL: 4247421Sroot /* 4257421Sroot * Kill signal always sets processes running. 4267421Sroot */ 4277421Sroot goto run; 4287421Sroot 4297421Sroot case SIGCONT: 4307421Sroot /* 4317421Sroot * If the process catches SIGCONT, let it handle 4327421Sroot * the signal itself. If it isn't waiting on 4337421Sroot * an event, then it goes back to run state. 4347421Sroot * Otherwise, process goes back to sleep state. 4357421Sroot */ 4367421Sroot if (action != SIG_DFL || p->p_wchan == 0) 4377421Sroot goto run; 4387421Sroot p->p_stat = SSLEEP; 4397421Sroot goto out; 4407421Sroot 4417421Sroot case SIGSTOP: 4427421Sroot case SIGTSTP: 4437421Sroot case SIGTTIN: 4447421Sroot case SIGTTOU: 4457421Sroot /* 4467421Sroot * Already stopped, don't need to stop again. 4477421Sroot * (If we did the shell could get confused.) 4487421Sroot */ 44917153Sbloom p->p_sig &= ~mask; /* take it away */ 4507421Sroot goto out; 4517421Sroot 4527421Sroot default: 4537421Sroot /* 4547421Sroot * If process is sleeping interruptibly, then 4557421Sroot * unstick it so that when it is continued 4567421Sroot * it can look at the signal. 4577421Sroot * But don't setrun the process as its not to 4587421Sroot * be unstopped by the signal alone. 4597421Sroot */ 4607421Sroot if (p->p_wchan && p->p_pri > PZERO) 4617421Sroot unsleep(p); 4627421Sroot goto out; 4637421Sroot } 4647421Sroot /*NOTREACHED*/ 4657421Sroot 4667421Sroot default: 4677421Sroot /* 4687421Sroot * SRUN, SIDL, SZOMB do nothing with the signal, 4697421Sroot * other than kicking ourselves if we are running. 4707421Sroot * It will either never be noticed, or noticed very soon. 4717421Sroot */ 4727421Sroot if (p == u.u_procp && !noproc) 4738444Sroot #include "../vax/mtpr.h" 4747421Sroot aston(); 4757421Sroot goto out; 4767421Sroot } 4777421Sroot /*NOTREACHED*/ 4787421Sroot run: 4797421Sroot /* 4807421Sroot * Raise priority to at least PUSER. 4817421Sroot */ 4827421Sroot if (p->p_pri > PUSER) 48317399Skarels p->p_pri = PUSER; 4847421Sroot setrun(p); 4857421Sroot out: 4867421Sroot splx(s); 4877421Sroot } 4887421Sroot 4897421Sroot /* 4907421Sroot * Returns true if the current 4917421Sroot * process has a signal to process. 4927421Sroot * The signal to process is put in p_cursig. 4937421Sroot * This is asked at least once each time a process enters the 4947421Sroot * system (though this can usually be done without actually 4957421Sroot * calling issig by checking the pending signal masks.) 4967421Sroot * A signal does not do anything 4977421Sroot * directly to a process; it sets 4987421Sroot * a flag that asks the process to 4997421Sroot * do something to itself. 5007421Sroot */ 5017421Sroot issig() 5027421Sroot { 5037421Sroot register struct proc *p; 5047421Sroot register int sig; 50517153Sbloom int sigbits, mask; 5067421Sroot 5077421Sroot p = u.u_procp; 5087421Sroot for (;;) { 50914782Ssam sigbits = p->p_sig &~ p->p_sigmask; 5107421Sroot if ((p->p_flag&STRC) == 0) 51114782Ssam sigbits &= ~p->p_sigignore; 5127421Sroot if (p->p_flag&SVFORK) 5137421Sroot #define bit(a) (1<<(a-1)) 5147421Sroot sigbits &= ~(bit(SIGSTOP)|bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU)); 5157421Sroot if (sigbits == 0) 5167421Sroot break; 51712882Ssam sig = ffs(sigbits); 51817153Sbloom mask = sigmask(sig); 51917153Sbloom p->p_sig &= ~mask; /* take the signal! */ 5207421Sroot p->p_cursig = sig; 52112882Ssam if (p->p_flag&STRC && (p->p_flag&SVFORK) == 0) { 5227421Sroot /* 5237421Sroot * If traced, always stop, and stay 5247421Sroot * stopped until released by the parent. 5257421Sroot */ 5267421Sroot do { 5277421Sroot stop(p); 5287421Sroot swtch(); 5297421Sroot } while (!procxmt() && p->p_flag&STRC); 5307421Sroot 5317421Sroot /* 53214782Ssam * If the traced bit got turned off, 53314782Ssam * then put the signal taken above back into p_sig 53414782Ssam * and go back up to the top to rescan signals. 53514782Ssam * This ensures that p_sig* and u_signal are consistent. 5367421Sroot */ 53714782Ssam if ((p->p_flag&STRC) == 0) { 53817153Sbloom p->p_sig |= mask; 5397421Sroot continue; 5407421Sroot } 5417421Sroot 5427421Sroot /* 5437421Sroot * If parent wants us to take the signal, 5447421Sroot * then it will leave it in p->p_cursig; 5457421Sroot * otherwise we just look for signals again. 5467421Sroot */ 5477421Sroot sig = p->p_cursig; 5487421Sroot if (sig == 0) 5497421Sroot continue; 55014782Ssam 55114782Ssam /* 55214782Ssam * If signal is being masked put it back 55314782Ssam * into p_sig and look for other signals. 55414782Ssam */ 55517153Sbloom mask = sigmask(sig); 55617153Sbloom if (p->p_sigmask & mask) { 55717153Sbloom p->p_sig |= mask; 55814782Ssam continue; 55914782Ssam } 5607421Sroot } 5617421Sroot switch (u.u_signal[sig]) { 5627421Sroot 5637421Sroot case SIG_DFL: 5647421Sroot /* 5657421Sroot * Don't take default actions on system processes. 5667421Sroot */ 5677421Sroot if (p->p_ppid == 0) 5687421Sroot break; 5697421Sroot switch (sig) { 5707421Sroot 5717421Sroot case SIGTSTP: 5727421Sroot case SIGTTIN: 5737421Sroot case SIGTTOU: 5747421Sroot /* 5757421Sroot * Children of init aren't allowed to stop 5767421Sroot * on signals from the keyboard. 5777421Sroot */ 5787421Sroot if (p->p_pptr == &proc[1]) { 5797421Sroot psignal(p, SIGKILL); 5807421Sroot continue; 5817421Sroot } 5827421Sroot /* fall into ... */ 5837421Sroot 5847421Sroot case SIGSTOP: 5857421Sroot if (p->p_flag&STRC) 5867421Sroot continue; 5877421Sroot stop(p); 5887421Sroot swtch(); 5897421Sroot continue; 5907421Sroot 5917421Sroot case SIGCONT: 5927421Sroot case SIGCHLD: 59312882Ssam case SIGURG: 59412951Ssam case SIGIO: 59517597Sbloom case SIGWINCH: 5967421Sroot /* 5977421Sroot * These signals are normally not 5987421Sroot * sent if the action is the default. 5997421Sroot */ 6007421Sroot continue; /* == ignore */ 6017421Sroot 6027421Sroot default: 6037421Sroot goto send; 6047421Sroot } 6057421Sroot /*NOTREACHED*/ 6067421Sroot 6077421Sroot case SIG_HOLD: 6087421Sroot case SIG_IGN: 6097421Sroot /* 6107421Sroot * Masking above should prevent us 6117421Sroot * ever trying to take action on a held 6127421Sroot * or ignored signal, unless process is traced. 6137421Sroot */ 6147421Sroot if ((p->p_flag&STRC) == 0) 6157421Sroot printf("issig\n"); 6167421Sroot continue; 6177421Sroot 6187421Sroot default: 6197421Sroot /* 6207421Sroot * This signal has an action, let 6217421Sroot * psig process it. 6227421Sroot */ 6237421Sroot goto send; 6247421Sroot } 6257421Sroot /*NOTREACHED*/ 6267421Sroot } 6277421Sroot /* 6287421Sroot * Didn't find a signal to send. 6297421Sroot */ 6307421Sroot p->p_cursig = 0; 6317421Sroot return (0); 6327421Sroot 6337421Sroot send: 6347421Sroot /* 6357421Sroot * Let psig process the signal. 6367421Sroot */ 6377421Sroot return (sig); 6387421Sroot } 6397421Sroot 6407421Sroot /* 6417421Sroot * Put the argument process into the stopped 6427421Sroot * state and notify the parent via wakeup and/or signal. 6437421Sroot */ 6447421Sroot stop(p) 6457421Sroot register struct proc *p; 6467421Sroot { 6477421Sroot 6487421Sroot p->p_stat = SSTOP; 6497421Sroot p->p_flag &= ~SWTED; 6507421Sroot wakeup((caddr_t)p->p_pptr); 6517421Sroot /* 6527421Sroot * Avoid sending signal to parent if process is traced 6537421Sroot */ 6547421Sroot if (p->p_flag&STRC) 6557421Sroot return; 6567421Sroot psignal(p->p_pptr, SIGCHLD); 6577421Sroot } 6587421Sroot 6597421Sroot /* 6607421Sroot * Perform the action specified by 6617421Sroot * the current signal. 6627421Sroot * The usual sequence is: 6637421Sroot * if (issig()) 6647421Sroot * psig(); 6657421Sroot * The signal bit has already been cleared by issig, 6667421Sroot * and the current signal number stored in p->p_cursig. 6677421Sroot */ 6687421Sroot psig() 6697421Sroot { 67012882Ssam register struct proc *p = u.u_procp; 67112882Ssam register int sig = p->p_cursig; 67217153Sbloom int mask = sigmask(sig), returnmask; 6737421Sroot register int (*action)(); 6747421Sroot 67512882Ssam if (sig == 0) 6767421Sroot panic("psig"); 67712882Ssam action = u.u_signal[sig]; 6787421Sroot if (action != SIG_DFL) { 67917153Sbloom if (action == SIG_IGN || (p->p_sigmask & mask)) 6807421Sroot panic("psig action"); 6817421Sroot u.u_error = 0; 6827421Sroot /* 68312882Ssam * Set the new mask value and also defer further 68412882Ssam * occurences of this signal (unless we're simulating 68512882Ssam * the old signal facilities). 68612882Ssam * 68712882Ssam * Special case: user has done a sigpause. Here the 68812882Ssam * current mask is not of interest, but rather the 68912882Ssam * mask from before the sigpause is what we want restored 69012882Ssam * after the signal processing is completed. 6917421Sroot */ 69217153Sbloom (void) splhigh(); 69312882Ssam if (p->p_flag & SOUSIG) { 69412882Ssam if (sig != SIGILL && sig != SIGTRAP) { 69512882Ssam u.u_signal[sig] = SIG_DFL; 69617153Sbloom p->p_sigcatch &= ~mask; 69712882Ssam } 69817153Sbloom mask = 0; 6997421Sroot } 70012882Ssam if (p->p_flag & SOMASK) { 70112882Ssam returnmask = u.u_oldmask; 70212882Ssam p->p_flag &= ~SOMASK; 70312882Ssam } else 70412882Ssam returnmask = p->p_sigmask; 70517153Sbloom p->p_sigmask |= u.u_sigmask[sig] | mask; 70612882Ssam (void) spl0(); 7078032Sroot u.u_ru.ru_nsignals++; 70812882Ssam sendsig(action, sig, returnmask); 70912882Ssam p->p_cursig = 0; 7107421Sroot return; 7117421Sroot } 7127421Sroot u.u_acflag |= AXSIG; 71312882Ssam switch (sig) { 7147421Sroot 7157421Sroot case SIGILL: 7167421Sroot case SIGIOT: 7177421Sroot case SIGBUS: 7187421Sroot case SIGQUIT: 7197421Sroot case SIGTRAP: 7207421Sroot case SIGEMT: 7217421Sroot case SIGFPE: 7227421Sroot case SIGSEGV: 7237421Sroot case SIGSYS: 72412882Ssam u.u_arg[0] = sig; 7257421Sroot if (core()) 72612882Ssam sig += 0200; 7277421Sroot } 72812882Ssam exit(sig); 7297421Sroot } 7307421Sroot 7317421Sroot /* 7327421Sroot * Create a core image on the file "core" 7337421Sroot * If you are looking for protection glitches, 7347421Sroot * there are probably a wealth of them here 7357421Sroot * when this occurs to a suid command. 7367421Sroot * 7377421Sroot * It writes UPAGES block of the 7387421Sroot * user.h area followed by the entire 7397421Sroot * data+stack segments. 7407421Sroot */ 7417421Sroot core() 7427421Sroot { 7437421Sroot register struct inode *ip; 74416692Smckusick register struct nameidata *ndp = &u.u_nd; 7457421Sroot 74612639Ssam if (u.u_uid != u.u_ruid || u.u_gid != u.u_rgid) 7477818Sroot return (0); 7488032Sroot if (ctob(UPAGES+u.u_dsize+u.u_ssize) >= 7498032Sroot u.u_rlimit[RLIMIT_CORE].rlim_cur) 7507421Sroot return (0); 7517421Sroot u.u_error = 0; 75216692Smckusick ndp->ni_nameiop = CREATE | FOLLOW; 75316692Smckusick ndp->ni_segflg = UIO_SYSSPACE; 75416692Smckusick ndp->ni_dirp = "core"; 75516692Smckusick ip = namei(ndp); 7567421Sroot if (ip == NULL) { 7577421Sroot if (u.u_error) 7587421Sroot return (0); 75916692Smckusick ip = maknode(0644, ndp); 7607421Sroot if (ip==NULL) 7617421Sroot return (0); 7627421Sroot } 7637818Sroot if (access(ip, IWRITE) || 7647818Sroot (ip->i_mode&IFMT) != IFREG || 7657818Sroot ip->i_nlink != 1) { 7667421Sroot u.u_error = EFAULT; 7677818Sroot goto out; 7687818Sroot } 7699160Ssam itrunc(ip, (u_long)0); 7707818Sroot u.u_acflag |= ACORE; 77112882Ssam u.u_error = rdwri(UIO_WRITE, ip, 77212882Ssam (caddr_t)&u, 77312882Ssam ctob(UPAGES), 77412882Ssam 0, 1, (int *)0); 7758101Sroot if (u.u_error == 0) 7768644Sroot u.u_error = rdwri(UIO_WRITE, ip, 7778967Sroot (caddr_t)ctob(dptov(u.u_procp, 0)), 7788967Sroot ctob(u.u_dsize), 7798644Sroot ctob(UPAGES), 0, (int *)0); 7808101Sroot if (u.u_error == 0) 7818644Sroot u.u_error = rdwri(UIO_WRITE, ip, 7828967Sroot (caddr_t)ctob(sptov(u.u_procp, u.u_ssize - 1)), 7838967Sroot ctob(u.u_ssize), 7848644Sroot ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0); 7857818Sroot out: 7867421Sroot iput(ip); 7877818Sroot return (u.u_error == 0); 7887421Sroot } 789