1*9160Ssam /* kern_sig.c 5.12 82/11/13 */ 27421Sroot 37421Sroot #include "../h/param.h" 47421Sroot #include "../h/systm.h" 57421Sroot #include "../h/dir.h" 67421Sroot #include "../h/user.h" 77421Sroot #include "../h/reg.h" 87421Sroot #include "../h/inode.h" 97421Sroot #include "../h/proc.h" 107421Sroot #include "../h/timeb.h" 117421Sroot #include "../h/times.h" 127421Sroot #include "../h/conf.h" 137421Sroot #include "../h/buf.h" 147421Sroot #include "../h/mount.h" 157421Sroot #include "../h/text.h" 167421Sroot #include "../h/seg.h" 177421Sroot #include "../h/pte.h" 187421Sroot #include "../h/psl.h" 197421Sroot #include "../h/vm.h" 207421Sroot #include "../h/acct.h" 217818Sroot #include "../h/uio.h" 228117Sroot #include "../h/kernel.h" 23*9160Ssam #include "../h/nami.h" 247421Sroot 257499Sroot /* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */ 267499Sroot 277499Sroot sigvec() 287421Sroot { 297421Sroot 307421Sroot } 317421Sroot 327499Sroot sigblock() 337421Sroot { 347499Sroot 357499Sroot } 367499Sroot 377499Sroot sigsetmask() 387499Sroot { 397499Sroot 407499Sroot } 417499Sroot 427499Sroot sigpause() 437499Sroot { 447499Sroot 457499Sroot } 467499Sroot 477499Sroot sigstack() 487499Sroot { 497499Sroot 507499Sroot } 517499Sroot 528764Sroot #ifdef notdef 538032Sroot kill() 548032Sroot { 558032Sroot 568032Sroot } 578764Sroot #endif 588032Sroot 598032Sroot killpg() 608032Sroot { 618032Sroot 628032Sroot } 638032Sroot 647499Sroot /* BEGIN DEFUNCT */ 657499Sroot okill() 667499Sroot { 677421Sroot register struct proc *p; 687421Sroot register a, sig; 697421Sroot register struct a { 707421Sroot int pid; 717421Sroot int signo; 727421Sroot } *uap; 737421Sroot int f, priv; 747421Sroot 757421Sroot uap = (struct a *)u.u_ap; 767421Sroot f = 0; 777421Sroot a = uap->pid; 787421Sroot priv = 0; 797421Sroot sig = uap->signo; 807421Sroot if (sig < 0) 817421Sroot /* 827421Sroot * A negative signal means send to process group. 837421Sroot */ 847421Sroot uap->signo = -uap->signo; 857421Sroot if (uap->signo == 0 || uap->signo > NSIG) { 867421Sroot u.u_error = EINVAL; 877421Sroot return; 887421Sroot } 897421Sroot if (a > 0 && sig > 0) { 907421Sroot p = pfind(a); 917421Sroot if (p == 0 || u.u_uid && u.u_uid != p->p_uid) { 927421Sroot u.u_error = ESRCH; 937421Sroot return; 947421Sroot } 957421Sroot psignal(p, uap->signo); 967421Sroot return; 977421Sroot } 987421Sroot if (a==-1 && u.u_uid==0) { 997421Sroot priv++; 1007421Sroot a = 0; 1017421Sroot sig = -1; /* like sending to pgrp */ 1027421Sroot } else if (a==0) { 1037421Sroot /* 1047421Sroot * Zero process id means send to my process group. 1057421Sroot */ 1067421Sroot sig = -1; 1077421Sroot a = u.u_procp->p_pgrp; 1087421Sroot if (a == 0) { 1097421Sroot u.u_error = EINVAL; 1107421Sroot return; 1117421Sroot } 1127421Sroot } 1137421Sroot for(p = proc; p < procNPROC; p++) { 1147421Sroot if (p->p_stat == NULL) 1157421Sroot continue; 1167421Sroot if (sig > 0) { 1177421Sroot if (p->p_pid != a) 1187421Sroot continue; 1197421Sroot } else if (p->p_pgrp!=a && priv==0 || p->p_ppid==0 || 1207421Sroot (p->p_flag&SSYS) || (priv && p==u.u_procp)) 1217421Sroot continue; 1227421Sroot if (u.u_uid != 0 && u.u_uid != p->p_uid && 1237421Sroot (uap->signo != SIGCONT || !inferior(p))) 1247421Sroot continue; 1257421Sroot f++; 1267421Sroot psignal(p, uap->signo); 1277421Sroot } 1287421Sroot if (f == 0) 1297421Sroot u.u_error = ESRCH; 1307421Sroot } 1317421Sroot 1327499Sroot ossig() 1337499Sroot { 1347499Sroot register int (*f)(); 1357499Sroot struct a { 1367499Sroot int signo; 1377499Sroot int (*fun)(); 1387499Sroot } *uap; 1397499Sroot register struct proc *p = u.u_procp; 1407499Sroot register a; 1417499Sroot long sigmask; 1427421Sroot 1437499Sroot uap = (struct a *)u.u_ap; 1447499Sroot a = uap->signo & SIGNUMMASK; 1457499Sroot f = uap->fun; 1467499Sroot if (a<=0 || a>=NSIG || a==SIGKILL || a==SIGSTOP || 1477499Sroot a==SIGCONT && (f == SIG_IGN || f == SIG_HOLD)) { 1487499Sroot u.u_error = EINVAL; 1497499Sroot return; 1507499Sroot } 1517499Sroot if ((uap->signo &~ SIGNUMMASK) || (f != SIG_DFL && f != SIG_IGN && 1527499Sroot SIGISDEFER(f))) 1537499Sroot u.u_procp->p_flag |= SNUSIG; 1547499Sroot /* 1557499Sroot * Don't clobber registers if we are to simulate 1567499Sroot * a ret+rti. 1577499Sroot */ 1587499Sroot if ((uap->signo&SIGDORTI) == 0) 1597499Sroot u.u_r.r_val1 = (int)u.u_signal[a]; 1607499Sroot /* 1617499Sroot * Change setting atomically. 1627499Sroot */ 1637499Sroot (void) spl6(); 1647499Sroot sigmask = 1L << (a-1); 1657499Sroot if (u.u_signal[a] == SIG_IGN) 1667499Sroot p->p_sig &= ~sigmask; /* never to be seen again */ 1677499Sroot u.u_signal[a] = f; 1687499Sroot if (f != SIG_DFL && f != SIG_IGN && f != SIG_HOLD) 1697499Sroot f = SIG_CATCH; 1707499Sroot if ((int)f & 1) 1717499Sroot p->p_siga0 |= sigmask; 1727499Sroot else 1737499Sroot p->p_siga0 &= ~sigmask; 1747499Sroot if ((int)f & 2) 1757499Sroot p->p_siga1 |= sigmask; 1767499Sroot else 1777499Sroot p->p_siga1 &= ~sigmask; 1787499Sroot (void) spl0(); 1797499Sroot /* 1807499Sroot * Now handle options. 1817499Sroot */ 1827499Sroot if (uap->signo & SIGDOPAUSE) { 1837499Sroot /* 1847499Sroot * Simulate a PDP11 style wait instrution which 1857499Sroot * atomically lowers priority, enables interrupts 1867499Sroot * and hangs. 1877499Sroot */ 1887499Sroot opause(); 1897499Sroot /*NOTREACHED*/ 1907499Sroot } 1917499Sroot if (uap->signo & SIGDORTI) 1927499Sroot u.u_eosys = SIMULATERTI; 1937499Sroot } 1947421Sroot 1957421Sroot /* 1967421Sroot * Send the specified signal to 1977421Sroot * all processes with 'pgrp' as 1987421Sroot * process group. 1997421Sroot * Called by tty.c for quits and 2007421Sroot * interrupts. 2017421Sroot */ 2027421Sroot gsignal(pgrp, sig) 2037421Sroot register int pgrp; 2047421Sroot { 2057421Sroot register struct proc *p; 2067421Sroot 2077421Sroot if (pgrp == 0) 2087421Sroot return; 2097421Sroot for(p = proc; p < procNPROC; p++) 2107421Sroot if (p->p_pgrp == pgrp) 2117421Sroot psignal(p, sig); 2127421Sroot } 2137421Sroot 2147421Sroot /* 2157421Sroot * Send the specified signal to 2167421Sroot * the specified process. 2177421Sroot */ 2187421Sroot psignal(p, sig) 2197421Sroot register struct proc *p; 2207421Sroot register int sig; 2217421Sroot { 2227421Sroot register int s; 2237421Sroot register int (*action)(); 2247421Sroot long sigmask; 2257421Sroot 2267421Sroot if ((unsigned)sig >= NSIG) 2277421Sroot return; 2287421Sroot sigmask = (1L << (sig-1)); 2297421Sroot 2307421Sroot /* 2317421Sroot * If proc is traced, always give parent a chance. 2327421Sroot * Otherwise get the signal action from the bits in the proc table. 2337421Sroot */ 2347421Sroot if (p->p_flag & STRC) 2357421Sroot action = SIG_DFL; 2367421Sroot else { 2377421Sroot s = (p->p_siga1&sigmask) != 0; 2387421Sroot s <<= 1; 2397421Sroot s |= (p->p_siga0&sigmask) != 0; 2407421Sroot action = (int(*)())s; 2417421Sroot /* 2427421Sroot * If the signal is ignored, we forget about it immediately. 2437421Sroot */ 2447421Sroot if (action == SIG_IGN) 2457421Sroot return; 2467421Sroot } 2477421Sroot #define mask(sig) (1<<(sig-1)) 2487421Sroot #define stops (mask(SIGSTOP)|mask(SIGTSTP)|mask(SIGTTIN)|mask(SIGTTOU)) 2497421Sroot if (sig) { 2507421Sroot p->p_sig |= sigmask; 2517421Sroot switch (sig) { 2527421Sroot 2537421Sroot case SIGTERM: 2547421Sroot if ((p->p_flag&STRC) != 0 || action != SIG_DFL) 2557421Sroot break; 2567421Sroot /* fall into ... */ 2577421Sroot 2587421Sroot case SIGKILL: 2597421Sroot if (p->p_nice > NZERO) 2607421Sroot p->p_nice = NZERO; 2617421Sroot break; 2627421Sroot 2637421Sroot case SIGCONT: 2647421Sroot p->p_sig &= ~stops; 2657421Sroot break; 2667421Sroot 2677421Sroot case SIGSTOP: 2687421Sroot case SIGTSTP: 2697421Sroot case SIGTTIN: 2707421Sroot case SIGTTOU: 2717421Sroot p->p_sig &= ~mask(SIGCONT); 2727421Sroot break; 2737421Sroot } 2747421Sroot } 2757421Sroot #undef mask 2767421Sroot #undef stops 2777421Sroot /* 2787421Sroot * Defer further processing for signals which are held. 2797421Sroot */ 2807421Sroot if (action == SIG_HOLD) 2817421Sroot return; 2827421Sroot s = spl6(); 2837421Sroot switch (p->p_stat) { 2847421Sroot 2857421Sroot case SSLEEP: 2867421Sroot /* 2877421Sroot * If process is sleeping at negative priority 2887421Sroot * we can't interrupt the sleep... the signal will 2897421Sroot * be noticed when the process returns through 2907421Sroot * trap() or syscall(). 2917421Sroot */ 2927421Sroot if (p->p_pri <= PZERO) 2937421Sroot goto out; 2947421Sroot /* 2957421Sroot * Process is sleeping and traced... make it runnable 2967421Sroot * so it can discover the signal in issig() and stop 2977421Sroot * for the parent. 2987421Sroot */ 2997421Sroot if (p->p_flag&STRC) 3007421Sroot goto run; 3017421Sroot switch (sig) { 3027421Sroot 3037421Sroot case SIGSTOP: 3047421Sroot case SIGTSTP: 3057421Sroot case SIGTTIN: 3067421Sroot case SIGTTOU: 3077421Sroot /* 3087421Sroot * These are the signals which by default 3097421Sroot * stop a process. 3107421Sroot */ 3117421Sroot if (action != SIG_DFL) 3127421Sroot goto run; 3137421Sroot /* 3147421Sroot * Don't clog system with children of init 3157421Sroot * stopped from the keyboard. 3167421Sroot */ 3177421Sroot if (sig != SIGSTOP && p->p_pptr == &proc[1]) { 3187421Sroot psignal(p, SIGKILL); 3197421Sroot p->p_sig &= ~sigmask; 3207421Sroot splx(s); 3217421Sroot return; 3227421Sroot } 3237421Sroot /* 3247421Sroot * If a child in vfork(), stopping could 3257421Sroot * cause deadlock. 3267421Sroot */ 3277421Sroot if (p->p_flag&SVFORK) 3287421Sroot goto out; 3297421Sroot p->p_sig &= ~sigmask; 3307421Sroot p->p_cursig = sig; 3317421Sroot stop(p); 3327421Sroot goto out; 3337421Sroot 3347421Sroot case SIGIO: 3357421Sroot case SIGURG: 3367421Sroot case SIGCHLD: 3377421Sroot /* 3387421Sroot * These signals are special in that they 3397421Sroot * don't get propogated... if the process 3407421Sroot * isn't interested, forget it. 3417421Sroot */ 3427421Sroot if (action != SIG_DFL) 3437421Sroot goto run; 3447421Sroot p->p_sig &= ~sigmask; /* take it away */ 3457421Sroot goto out; 3467421Sroot 3477421Sroot default: 3487421Sroot /* 3497421Sroot * All other signals cause the process to run 3507421Sroot */ 3517421Sroot goto run; 3527421Sroot } 3537421Sroot /*NOTREACHED*/ 3547421Sroot 3557421Sroot case SSTOP: 3567421Sroot /* 3577421Sroot * If traced process is already stopped, 3587421Sroot * then no further action is necessary. 3597421Sroot */ 3607421Sroot if (p->p_flag&STRC) 3617421Sroot goto out; 3627421Sroot switch (sig) { 3637421Sroot 3647421Sroot case SIGKILL: 3657421Sroot /* 3667421Sroot * Kill signal always sets processes running. 3677421Sroot */ 3687421Sroot goto run; 3697421Sroot 3707421Sroot case SIGCONT: 3717421Sroot /* 3727421Sroot * If the process catches SIGCONT, let it handle 3737421Sroot * the signal itself. If it isn't waiting on 3747421Sroot * an event, then it goes back to run state. 3757421Sroot * Otherwise, process goes back to sleep state. 3767421Sroot */ 3777421Sroot if (action != SIG_DFL || p->p_wchan == 0) 3787421Sroot goto run; 3797421Sroot p->p_stat = SSLEEP; 3807421Sroot goto out; 3817421Sroot 3827421Sroot case SIGSTOP: 3837421Sroot case SIGTSTP: 3847421Sroot case SIGTTIN: 3857421Sroot case SIGTTOU: 3867421Sroot /* 3877421Sroot * Already stopped, don't need to stop again. 3887421Sroot * (If we did the shell could get confused.) 3897421Sroot */ 3907421Sroot p->p_sig &= ~sigmask; /* take it away */ 3917421Sroot goto out; 3927421Sroot 3937421Sroot default: 3947421Sroot /* 3957421Sroot * If process is sleeping interruptibly, then 3967421Sroot * unstick it so that when it is continued 3977421Sroot * it can look at the signal. 3987421Sroot * But don't setrun the process as its not to 3997421Sroot * be unstopped by the signal alone. 4007421Sroot */ 4017421Sroot if (p->p_wchan && p->p_pri > PZERO) 4027421Sroot unsleep(p); 4037421Sroot goto out; 4047421Sroot } 4057421Sroot /*NOTREACHED*/ 4067421Sroot 4077421Sroot default: 4087421Sroot /* 4097421Sroot * SRUN, SIDL, SZOMB do nothing with the signal, 4107421Sroot * other than kicking ourselves if we are running. 4117421Sroot * It will either never be noticed, or noticed very soon. 4127421Sroot */ 4137421Sroot if (p == u.u_procp && !noproc) 4148444Sroot #include "../vax/mtpr.h" 4157421Sroot aston(); 4167421Sroot goto out; 4177421Sroot } 4187421Sroot /*NOTREACHED*/ 4197421Sroot run: 4207421Sroot /* 4217421Sroot * Raise priority to at least PUSER. 4227421Sroot */ 4237421Sroot if (p->p_pri > PUSER) 4247421Sroot if ((p != u.u_procp || noproc) && p->p_stat == SRUN && 4257421Sroot (p->p_flag & SLOAD)) { 4267421Sroot remrq(p); 4277421Sroot p->p_pri = PUSER; 4287421Sroot setrq(p); 4297421Sroot } else 4307421Sroot p->p_pri = PUSER; 4317421Sroot setrun(p); 4327421Sroot out: 4337421Sroot splx(s); 4347421Sroot } 4357421Sroot 4367421Sroot /* 4377421Sroot * Returns true if the current 4387421Sroot * process has a signal to process. 4397421Sroot * The signal to process is put in p_cursig. 4407421Sroot * This is asked at least once each time a process enters the 4417421Sroot * system (though this can usually be done without actually 4427421Sroot * calling issig by checking the pending signal masks.) 4437421Sroot * A signal does not do anything 4447421Sroot * directly to a process; it sets 4457421Sroot * a flag that asks the process to 4467421Sroot * do something to itself. 4477421Sroot */ 4487421Sroot issig() 4497421Sroot { 4507421Sroot register struct proc *p; 4517421Sroot register int sig; 4527421Sroot long sigbits; 4537421Sroot long sigmask; 4547421Sroot 4557421Sroot p = u.u_procp; 4567421Sroot for (;;) { 4577421Sroot sigbits = p->p_sig; 4587421Sroot if ((p->p_flag&STRC) == 0) 4597421Sroot sigbits &= ~p->p_ignsig; 4607421Sroot if (p->p_flag&SVFORK) 4617421Sroot #define bit(a) (1<<(a-1)) 4627421Sroot sigbits &= ~(bit(SIGSTOP)|bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU)); 4637421Sroot if (sigbits == 0) 4647421Sroot break; 4657421Sroot sig = ffs((int)sigbits); 4667421Sroot sigmask = 1L << (sig-1); 4677421Sroot p->p_sig &= ~sigmask; /* take the signal! */ 4687421Sroot p->p_cursig = sig; 4697421Sroot if (p->p_flag&STRC && (p->p_flag&SVFORK)==0) { 4707421Sroot /* 4717421Sroot * If traced, always stop, and stay 4727421Sroot * stopped until released by the parent. 4737421Sroot */ 4747421Sroot do { 4757421Sroot stop(p); 4767421Sroot swtch(); 4777421Sroot } while (!procxmt() && p->p_flag&STRC); 4787421Sroot 4797421Sroot /* 4807421Sroot * If the traced bit got turned off, 4817421Sroot * then put the signal taken above back into p_sig 4827421Sroot * and go back up to the top to rescan signals. 4837421Sroot * This ensures that siga0 and u_signal are consistent. 4847421Sroot */ 4857421Sroot if ((p->p_flag&STRC) == 0) { 4867421Sroot p->p_sig |= sigmask; 4877421Sroot continue; 4887421Sroot } 4897421Sroot 4907421Sroot /* 4917421Sroot * If parent wants us to take the signal, 4927421Sroot * then it will leave it in p->p_cursig; 4937421Sroot * otherwise we just look for signals again. 4947421Sroot */ 4957421Sroot sig = p->p_cursig; 4967421Sroot if (sig == 0) 4977421Sroot continue; 4987421Sroot } 4997421Sroot switch (u.u_signal[sig]) { 5007421Sroot 5017421Sroot case SIG_DFL: 5027421Sroot /* 5037421Sroot * Don't take default actions on system processes. 5047421Sroot */ 5057421Sroot if (p->p_ppid == 0) 5067421Sroot break; 5077421Sroot switch (sig) { 5087421Sroot 5097421Sroot case SIGTSTP: 5107421Sroot case SIGTTIN: 5117421Sroot case SIGTTOU: 5127421Sroot /* 5137421Sroot * Children of init aren't allowed to stop 5147421Sroot * on signals from the keyboard. 5157421Sroot */ 5167421Sroot if (p->p_pptr == &proc[1]) { 5177421Sroot psignal(p, SIGKILL); 5187421Sroot continue; 5197421Sroot } 5207421Sroot /* fall into ... */ 5217421Sroot 5227421Sroot case SIGSTOP: 5237421Sroot if (p->p_flag&STRC) 5247421Sroot continue; 5257421Sroot stop(p); 5267421Sroot swtch(); 5277421Sroot continue; 5287421Sroot 5297421Sroot case SIGCONT: 5307421Sroot case SIGCHLD: 5317421Sroot /* 5327421Sroot * These signals are normally not 5337421Sroot * sent if the action is the default. 5347421Sroot */ 5357421Sroot continue; /* == ignore */ 5367421Sroot 5377421Sroot default: 5387421Sroot goto send; 5397421Sroot } 5407421Sroot /*NOTREACHED*/ 5417421Sroot 5427421Sroot case SIG_HOLD: 5437421Sroot case SIG_IGN: 5447421Sroot /* 5457421Sroot * Masking above should prevent us 5467421Sroot * ever trying to take action on a held 5477421Sroot * or ignored signal, unless process is traced. 5487421Sroot */ 5497421Sroot if ((p->p_flag&STRC) == 0) 5507421Sroot printf("issig\n"); 5517421Sroot continue; 5527421Sroot 5537421Sroot default: 5547421Sroot /* 5557421Sroot * This signal has an action, let 5567421Sroot * psig process it. 5577421Sroot */ 5587421Sroot goto send; 5597421Sroot } 5607421Sroot /*NOTREACHED*/ 5617421Sroot } 5627421Sroot /* 5637421Sroot * Didn't find a signal to send. 5647421Sroot */ 5657421Sroot p->p_cursig = 0; 5667421Sroot return (0); 5677421Sroot 5687421Sroot send: 5697421Sroot /* 5707421Sroot * Let psig process the signal. 5717421Sroot */ 5727421Sroot return (sig); 5737421Sroot } 5747421Sroot 5757421Sroot /* 5767421Sroot * Put the argument process into the stopped 5777421Sroot * state and notify the parent via wakeup and/or signal. 5787421Sroot */ 5797421Sroot stop(p) 5807421Sroot register struct proc *p; 5817421Sroot { 5827421Sroot 5837421Sroot p->p_stat = SSTOP; 5847421Sroot p->p_flag &= ~SWTED; 5857421Sroot wakeup((caddr_t)p->p_pptr); 5867421Sroot /* 5877421Sroot * Avoid sending signal to parent if process is traced 5887421Sroot */ 5897421Sroot if (p->p_flag&STRC) 5907421Sroot return; 5917421Sroot psignal(p->p_pptr, SIGCHLD); 5927421Sroot } 5937421Sroot 5947421Sroot /* 5957421Sroot * Perform the action specified by 5967421Sroot * the current signal. 5977421Sroot * The usual sequence is: 5987421Sroot * if (issig()) 5997421Sroot * psig(); 6007421Sroot * The signal bit has already been cleared by issig, 6017421Sroot * and the current signal number stored in p->p_cursig. 6027421Sroot */ 6037421Sroot psig() 6047421Sroot { 6057421Sroot register struct proc *rp = u.u_procp; 6067421Sroot register int n = rp->p_cursig; 6077421Sroot long sigmask = 1L << (n-1); 6087421Sroot register int (*action)(); 6097421Sroot 6107421Sroot if (rp->p_cursig == 0) 6117421Sroot panic("psig"); 6127421Sroot action = u.u_signal[n]; 6137421Sroot if (action != SIG_DFL) { 6147421Sroot if (action == SIG_IGN || action == SIG_HOLD) 6157421Sroot panic("psig action"); 6167421Sroot u.u_error = 0; 6177421Sroot if (n != SIGILL && n != SIGTRAP) 6187421Sroot u.u_signal[n] = 0; 6197421Sroot /* 6207421Sroot * If this catch value indicates automatic holding of 6217421Sroot * subsequent signals, set the hold value. 6227421Sroot */ 6237421Sroot if (SIGISDEFER(action)) { 6247421Sroot (void) spl6(); 6257421Sroot if ((int)SIG_HOLD & 1) 6267421Sroot rp->p_siga0 |= sigmask; 6277421Sroot else 6287421Sroot rp->p_siga0 &= ~sigmask; 6297421Sroot if ((int)SIG_HOLD & 2) 6307421Sroot rp->p_siga1 |= sigmask; 6317421Sroot else 6327421Sroot rp->p_siga1 &= ~sigmask; 6337421Sroot u.u_signal[n] = SIG_HOLD; 6347421Sroot (void) spl0(); 6357421Sroot action = SIGUNDEFER(action); 6367421Sroot } 6378032Sroot u.u_ru.ru_nsignals++; 6387421Sroot sendsig(action, n); 6397421Sroot rp->p_cursig = 0; 6407421Sroot return; 6417421Sroot } 6427421Sroot u.u_acflag |= AXSIG; 6437421Sroot switch (n) { 6447421Sroot 6457421Sroot case SIGILL: 6467421Sroot case SIGIOT: 6477421Sroot case SIGBUS: 6487421Sroot case SIGQUIT: 6497421Sroot case SIGTRAP: 6507421Sroot case SIGEMT: 6517421Sroot case SIGFPE: 6527421Sroot case SIGSEGV: 6537421Sroot case SIGSYS: 6547421Sroot u.u_arg[0] = n; 6557421Sroot if (core()) 6567421Sroot n += 0200; 6577421Sroot } 6587421Sroot exit(n); 6597421Sroot } 6607421Sroot 6617421Sroot #ifdef unneeded 6627421Sroot int corestop = 0; 6637421Sroot #endif 6647421Sroot /* 6657421Sroot * Create a core image on the file "core" 6667421Sroot * If you are looking for protection glitches, 6677421Sroot * there are probably a wealth of them here 6687421Sroot * when this occurs to a suid command. 6697421Sroot * 6707421Sroot * It writes UPAGES block of the 6717421Sroot * user.h area followed by the entire 6727421Sroot * data+stack segments. 6737421Sroot */ 6747421Sroot core() 6757421Sroot { 6767421Sroot register struct inode *ip; 6777421Sroot extern schar(); 6787421Sroot 6797421Sroot #ifdef unneeded 6807421Sroot if (corestop) { 6817421Sroot int i; 6827421Sroot for (i = 0; i < 10; i++) 6837421Sroot if (u.u_comm[i]) 6847421Sroot putchar(u.u_comm[i], 0); 6857421Sroot printf(", uid %d\n", u.u_uid); 6867421Sroot if (corestop&2) 6877421Sroot asm("halt"); 6887421Sroot } 6897421Sroot #endif 6907421Sroot if (u.u_uid != u.u_ruid) 6917818Sroot return (0); 6928032Sroot if (ctob(UPAGES+u.u_dsize+u.u_ssize) >= 6938032Sroot u.u_rlimit[RLIMIT_CORE].rlim_cur) 6947421Sroot return (0); 6957421Sroot u.u_error = 0; 6967421Sroot u.u_dirp = "core"; 697*9160Ssam ip = namei(schar, CREATE, 1); 6987421Sroot if (ip == NULL) { 6997421Sroot if (u.u_error) 7007421Sroot return (0); 7017421Sroot ip = maknode(0666); 7027421Sroot if (ip==NULL) 7037421Sroot return (0); 7047421Sroot } 7057818Sroot if (access(ip, IWRITE) || 7067818Sroot (ip->i_mode&IFMT) != IFREG || 7077818Sroot ip->i_nlink != 1) { 7087421Sroot u.u_error = EFAULT; 7097818Sroot goto out; 7107818Sroot } 711*9160Ssam itrunc(ip, (u_long)0); 7127818Sroot u.u_acflag |= ACORE; 7138967Sroot /* if (u.u_error == 0) */ 7148967Sroot u.u_error = rdwri(UIO_WRITE, ip, 7158967Sroot (caddr_t)&u, 7168967Sroot ctob(UPAGES), 7178967Sroot 0, 1, (int *)0); 7188101Sroot if (u.u_error == 0) 7198644Sroot u.u_error = rdwri(UIO_WRITE, ip, 7208967Sroot (caddr_t)ctob(dptov(u.u_procp, 0)), 7218967Sroot ctob(u.u_dsize), 7228644Sroot ctob(UPAGES), 0, (int *)0); 7238101Sroot if (u.u_error == 0) 7248644Sroot u.u_error = rdwri(UIO_WRITE, ip, 7258967Sroot (caddr_t)ctob(sptov(u.u_procp, u.u_ssize - 1)), 7268967Sroot ctob(u.u_ssize), 7278644Sroot ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0); 7287818Sroot out: 7297421Sroot iput(ip); 7307818Sroot return (u.u_error == 0); 7317421Sroot } 732