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