xref: /csrg-svn/sys/kern/kern_sig.c (revision 7499)
1*7499Sroot /*	kern_sig.c	5.2	82/07/24	*/
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/clock.h"
117421Sroot #include "../h/mtpr.h"
127421Sroot #include "../h/timeb.h"
137421Sroot #include "../h/times.h"
147421Sroot #include "../h/conf.h"
157421Sroot #include "../h/buf.h"
167421Sroot #include "../h/mount.h"
177421Sroot #include "../h/text.h"
187421Sroot #include "../h/seg.h"
197421Sroot #include "../h/pte.h"
207421Sroot #include "../h/psl.h"
217421Sroot #include "../h/vm.h"
227421Sroot #include "../h/vlimit.h"
237421Sroot #include "../h/acct.h"
247421Sroot 
25*7499Sroot /* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */
26*7499Sroot 
27*7499Sroot sigvec()
287421Sroot {
297421Sroot 
307421Sroot }
317421Sroot 
32*7499Sroot sigblock()
337421Sroot {
34*7499Sroot 
35*7499Sroot }
36*7499Sroot 
37*7499Sroot sigsetmask()
38*7499Sroot {
39*7499Sroot 
40*7499Sroot }
41*7499Sroot 
42*7499Sroot sigpause()
43*7499Sroot {
44*7499Sroot 
45*7499Sroot }
46*7499Sroot 
47*7499Sroot sigstack()
48*7499Sroot {
49*7499Sroot 
50*7499Sroot }
51*7499Sroot 
52*7499Sroot /* BEGIN DEFUNCT */
53*7499Sroot okill()
54*7499Sroot {
557421Sroot 	register struct proc *p;
567421Sroot 	register a, sig;
577421Sroot 	register struct a {
587421Sroot 		int	pid;
597421Sroot 		int	signo;
607421Sroot 	} *uap;
617421Sroot 	int f, priv;
627421Sroot 
637421Sroot 	uap = (struct a *)u.u_ap;
647421Sroot 	f = 0;
657421Sroot 	a = uap->pid;
667421Sroot 	priv = 0;
677421Sroot 	sig = uap->signo;
687421Sroot 	if (sig < 0)
697421Sroot 		/*
707421Sroot 		 * A negative signal means send to process group.
717421Sroot 		 */
727421Sroot 		uap->signo = -uap->signo;
737421Sroot 	if (uap->signo == 0 || uap->signo > NSIG) {
747421Sroot 		u.u_error = EINVAL;
757421Sroot 		return;
767421Sroot 	}
777421Sroot 	if (a > 0 && sig > 0) {
787421Sroot 		p = pfind(a);
797421Sroot 		if (p == 0 || u.u_uid && u.u_uid != p->p_uid) {
807421Sroot 			u.u_error = ESRCH;
817421Sroot 			return;
827421Sroot 		}
837421Sroot 		psignal(p, uap->signo);
847421Sroot 		return;
857421Sroot 	}
867421Sroot 	if (a==-1 && u.u_uid==0) {
877421Sroot 		priv++;
887421Sroot 		a = 0;
897421Sroot 		sig = -1;		/* like sending to pgrp */
907421Sroot 	} else if (a==0) {
917421Sroot 		/*
927421Sroot 		 * Zero process id means send to my process group.
937421Sroot 		 */
947421Sroot 		sig = -1;
957421Sroot 		a = u.u_procp->p_pgrp;
967421Sroot 		if (a == 0) {
977421Sroot 			u.u_error = EINVAL;
987421Sroot 			return;
997421Sroot 		}
1007421Sroot 	}
1017421Sroot 	for(p = proc; p < procNPROC; p++) {
1027421Sroot 		if (p->p_stat == NULL)
1037421Sroot 			continue;
1047421Sroot 		if (sig > 0) {
1057421Sroot 			if (p->p_pid != a)
1067421Sroot 				continue;
1077421Sroot 		} else if (p->p_pgrp!=a && priv==0 || p->p_ppid==0 ||
1087421Sroot 		    (p->p_flag&SSYS) || (priv && p==u.u_procp))
1097421Sroot 			continue;
1107421Sroot 		if (u.u_uid != 0 && u.u_uid != p->p_uid &&
1117421Sroot 		    (uap->signo != SIGCONT || !inferior(p)))
1127421Sroot 			continue;
1137421Sroot 		f++;
1147421Sroot 		psignal(p, uap->signo);
1157421Sroot 	}
1167421Sroot 	if (f == 0)
1177421Sroot 		u.u_error = ESRCH;
1187421Sroot }
1197421Sroot 
120*7499Sroot ossig()
121*7499Sroot {
122*7499Sroot 	register int (*f)();
123*7499Sroot 	struct a {
124*7499Sroot 		int	signo;
125*7499Sroot 		int	(*fun)();
126*7499Sroot 	} *uap;
127*7499Sroot 	register struct proc *p = u.u_procp;
128*7499Sroot 	register a;
129*7499Sroot 	long sigmask;
1307421Sroot 
131*7499Sroot 	uap = (struct a *)u.u_ap;
132*7499Sroot 	a = uap->signo & SIGNUMMASK;
133*7499Sroot 	f = uap->fun;
134*7499Sroot 	if (a<=0 || a>=NSIG || a==SIGKILL || a==SIGSTOP ||
135*7499Sroot 	    a==SIGCONT && (f == SIG_IGN || f == SIG_HOLD)) {
136*7499Sroot 		u.u_error = EINVAL;
137*7499Sroot 		return;
138*7499Sroot 	}
139*7499Sroot 	if ((uap->signo &~ SIGNUMMASK) || (f != SIG_DFL && f != SIG_IGN &&
140*7499Sroot 	    SIGISDEFER(f)))
141*7499Sroot 		u.u_procp->p_flag |= SNUSIG;
142*7499Sroot 	/*
143*7499Sroot 	 * Don't clobber registers if we are to simulate
144*7499Sroot 	 * a ret+rti.
145*7499Sroot 	 */
146*7499Sroot 	if ((uap->signo&SIGDORTI) == 0)
147*7499Sroot 		u.u_r.r_val1 = (int)u.u_signal[a];
148*7499Sroot 	/*
149*7499Sroot 	 * Change setting atomically.
150*7499Sroot 	 */
151*7499Sroot 	(void) spl6();
152*7499Sroot 	sigmask = 1L << (a-1);
153*7499Sroot 	if (u.u_signal[a] == SIG_IGN)
154*7499Sroot 		p->p_sig &= ~sigmask;		/* never to be seen again */
155*7499Sroot 	u.u_signal[a] = f;
156*7499Sroot 	if (f != SIG_DFL && f != SIG_IGN && f != SIG_HOLD)
157*7499Sroot 		f = SIG_CATCH;
158*7499Sroot 	if ((int)f & 1)
159*7499Sroot 		p->p_siga0 |= sigmask;
160*7499Sroot 	else
161*7499Sroot 		p->p_siga0 &= ~sigmask;
162*7499Sroot 	if ((int)f & 2)
163*7499Sroot 		p->p_siga1 |= sigmask;
164*7499Sroot 	else
165*7499Sroot 		p->p_siga1 &= ~sigmask;
166*7499Sroot 	(void) spl0();
167*7499Sroot 	/*
168*7499Sroot 	 * Now handle options.
169*7499Sroot 	 */
170*7499Sroot 	if (uap->signo & SIGDOPAUSE) {
171*7499Sroot 		/*
172*7499Sroot 		 * Simulate a PDP11 style wait instrution which
173*7499Sroot 		 * atomically lowers priority, enables interrupts
174*7499Sroot 		 * and hangs.
175*7499Sroot 		 */
176*7499Sroot 		opause();
177*7499Sroot 		/*NOTREACHED*/
178*7499Sroot 	}
179*7499Sroot 	if (uap->signo & SIGDORTI)
180*7499Sroot 		u.u_eosys = SIMULATERTI;
181*7499Sroot }
1827421Sroot 
1837421Sroot /*
1847421Sroot  * Send the specified signal to
1857421Sroot  * all processes with 'pgrp' as
1867421Sroot  * process group.
1877421Sroot  * Called by tty.c for quits and
1887421Sroot  * interrupts.
1897421Sroot  */
1907421Sroot gsignal(pgrp, sig)
1917421Sroot 	register int pgrp;
1927421Sroot {
1937421Sroot 	register struct proc *p;
1947421Sroot 
1957421Sroot 	if (pgrp == 0)
1967421Sroot 		return;
1977421Sroot 	for(p = proc; p < procNPROC; p++)
1987421Sroot 		if (p->p_pgrp == pgrp)
1997421Sroot 			psignal(p, sig);
2007421Sroot }
2017421Sroot 
2027421Sroot /*
2037421Sroot  * Send the specified signal to
2047421Sroot  * the specified process.
2057421Sroot  */
2067421Sroot psignal(p, sig)
2077421Sroot 	register struct proc *p;
2087421Sroot 	register int sig;
2097421Sroot {
2107421Sroot 	register int s;
2117421Sroot 	register int (*action)();
2127421Sroot 	long sigmask;
2137421Sroot 
2147421Sroot 	if ((unsigned)sig >= NSIG)
2157421Sroot 		return;
2167421Sroot 	sigmask = (1L << (sig-1));
2177421Sroot 
2187421Sroot 	/*
2197421Sroot 	 * If proc is traced, always give parent a chance.
2207421Sroot 	 * Otherwise get the signal action from the bits in the proc table.
2217421Sroot 	 */
2227421Sroot 	if (p->p_flag & STRC)
2237421Sroot 		action = SIG_DFL;
2247421Sroot 	else {
2257421Sroot 		s = (p->p_siga1&sigmask) != 0;
2267421Sroot 		s <<= 1;
2277421Sroot 		s |= (p->p_siga0&sigmask) != 0;
2287421Sroot 		action = (int(*)())s;
2297421Sroot 		/*
2307421Sroot 		 * If the signal is ignored, we forget about it immediately.
2317421Sroot 		 */
2327421Sroot 		if (action == SIG_IGN)
2337421Sroot 			return;
2347421Sroot 	}
2357421Sroot #define mask(sig)	(1<<(sig-1))
2367421Sroot #define	stops	(mask(SIGSTOP)|mask(SIGTSTP)|mask(SIGTTIN)|mask(SIGTTOU))
2377421Sroot 	if (sig) {
2387421Sroot 		p->p_sig |= sigmask;
2397421Sroot 		switch (sig) {
2407421Sroot 
2417421Sroot 		case SIGTERM:
2427421Sroot 			if ((p->p_flag&STRC) != 0 || action != SIG_DFL)
2437421Sroot 				break;
2447421Sroot 			/* fall into ... */
2457421Sroot 
2467421Sroot 		case SIGKILL:
2477421Sroot 			if (p->p_nice > NZERO)
2487421Sroot 				p->p_nice = NZERO;
2497421Sroot 			break;
2507421Sroot 
2517421Sroot 		case SIGCONT:
2527421Sroot 			p->p_sig &= ~stops;
2537421Sroot 			break;
2547421Sroot 
2557421Sroot 		case SIGSTOP:
2567421Sroot 		case SIGTSTP:
2577421Sroot 		case SIGTTIN:
2587421Sroot 		case SIGTTOU:
2597421Sroot 			p->p_sig &= ~mask(SIGCONT);
2607421Sroot 			break;
2617421Sroot 		}
2627421Sroot 	}
2637421Sroot #undef mask
2647421Sroot #undef stops
2657421Sroot 	/*
2667421Sroot 	 * Defer further processing for signals which are held.
2677421Sroot 	 */
2687421Sroot 	if (action == SIG_HOLD)
2697421Sroot 		return;
2707421Sroot 	s = spl6();
2717421Sroot 	switch (p->p_stat) {
2727421Sroot 
2737421Sroot 	case SSLEEP:
2747421Sroot 		/*
2757421Sroot 		 * If process is sleeping at negative priority
2767421Sroot 		 * we can't interrupt the sleep... the signal will
2777421Sroot 		 * be noticed when the process returns through
2787421Sroot 		 * trap() or syscall().
2797421Sroot 		 */
2807421Sroot 		if (p->p_pri <= PZERO)
2817421Sroot 			goto out;
2827421Sroot 		/*
2837421Sroot 		 * Process is sleeping and traced... make it runnable
2847421Sroot 		 * so it can discover the signal in issig() and stop
2857421Sroot 		 * for the parent.
2867421Sroot 		 */
2877421Sroot 		if (p->p_flag&STRC)
2887421Sroot 			goto run;
2897421Sroot 		switch (sig) {
2907421Sroot 
2917421Sroot 		case SIGSTOP:
2927421Sroot 		case SIGTSTP:
2937421Sroot 		case SIGTTIN:
2947421Sroot 		case SIGTTOU:
2957421Sroot 			/*
2967421Sroot 			 * These are the signals which by default
2977421Sroot 			 * stop a process.
2987421Sroot 			 */
2997421Sroot 			if (action != SIG_DFL)
3007421Sroot 				goto run;
3017421Sroot 			/*
3027421Sroot 			 * Don't clog system with children of init
3037421Sroot 			 * stopped from the keyboard.
3047421Sroot 			 */
3057421Sroot 			if (sig != SIGSTOP && p->p_pptr == &proc[1]) {
3067421Sroot 				psignal(p, SIGKILL);
3077421Sroot 				p->p_sig &= ~sigmask;
3087421Sroot 				splx(s);
3097421Sroot 				return;
3107421Sroot 			}
3117421Sroot 			/*
3127421Sroot 			 * If a child in vfork(), stopping could
3137421Sroot 			 * cause deadlock.
3147421Sroot 			 */
3157421Sroot 			if (p->p_flag&SVFORK)
3167421Sroot 				goto out;
3177421Sroot 			p->p_sig &= ~sigmask;
3187421Sroot 			p->p_cursig = sig;
3197421Sroot 			stop(p);
3207421Sroot 			goto out;
3217421Sroot 
3227421Sroot 		case SIGIO:
3237421Sroot 		case SIGURG:
3247421Sroot 		case SIGCHLD:
3257421Sroot 			/*
3267421Sroot 			 * These signals are special in that they
3277421Sroot 			 * don't get propogated... if the process
3287421Sroot 			 * isn't interested, forget it.
3297421Sroot 			 */
3307421Sroot 			if (action != SIG_DFL)
3317421Sroot 				goto run;
3327421Sroot 			p->p_sig &= ~sigmask;		/* take it away */
3337421Sroot 			goto out;
3347421Sroot 
3357421Sroot 		default:
3367421Sroot 			/*
3377421Sroot 			 * All other signals cause the process to run
3387421Sroot 			 */
3397421Sroot 			goto run;
3407421Sroot 		}
3417421Sroot 		/*NOTREACHED*/
3427421Sroot 
3437421Sroot 	case SSTOP:
3447421Sroot 		/*
3457421Sroot 		 * If traced process is already stopped,
3467421Sroot 		 * then no further action is necessary.
3477421Sroot 		 */
3487421Sroot 		if (p->p_flag&STRC)
3497421Sroot 			goto out;
3507421Sroot 		switch (sig) {
3517421Sroot 
3527421Sroot 		case SIGKILL:
3537421Sroot 			/*
3547421Sroot 			 * Kill signal always sets processes running.
3557421Sroot 			 */
3567421Sroot 			goto run;
3577421Sroot 
3587421Sroot 		case SIGCONT:
3597421Sroot 			/*
3607421Sroot 			 * If the process catches SIGCONT, let it handle
3617421Sroot 			 * the signal itself.  If it isn't waiting on
3627421Sroot 			 * an event, then it goes back to run state.
3637421Sroot 			 * Otherwise, process goes back to sleep state.
3647421Sroot 			 */
3657421Sroot 			if (action != SIG_DFL || p->p_wchan == 0)
3667421Sroot 				goto run;
3677421Sroot 			p->p_stat = SSLEEP;
3687421Sroot 			goto out;
3697421Sroot 
3707421Sroot 		case SIGSTOP:
3717421Sroot 		case SIGTSTP:
3727421Sroot 		case SIGTTIN:
3737421Sroot 		case SIGTTOU:
3747421Sroot 			/*
3757421Sroot 			 * Already stopped, don't need to stop again.
3767421Sroot 			 * (If we did the shell could get confused.)
3777421Sroot 			 */
3787421Sroot 			p->p_sig &= ~sigmask;		/* take it away */
3797421Sroot 			goto out;
3807421Sroot 
3817421Sroot 		default:
3827421Sroot 			/*
3837421Sroot 			 * If process is sleeping interruptibly, then
3847421Sroot 			 * unstick it so that when it is continued
3857421Sroot 			 * it can look at the signal.
3867421Sroot 			 * But don't setrun the process as its not to
3877421Sroot 			 * be unstopped by the signal alone.
3887421Sroot 			 */
3897421Sroot 			if (p->p_wchan && p->p_pri > PZERO)
3907421Sroot 				unsleep(p);
3917421Sroot 			goto out;
3927421Sroot 		}
3937421Sroot 		/*NOTREACHED*/
3947421Sroot 
3957421Sroot 	default:
3967421Sroot 		/*
3977421Sroot 		 * SRUN, SIDL, SZOMB do nothing with the signal,
3987421Sroot 		 * other than kicking ourselves if we are running.
3997421Sroot 		 * It will either never be noticed, or noticed very soon.
4007421Sroot 		 */
4017421Sroot 		if (p == u.u_procp && !noproc)
4027421Sroot 			aston();
4037421Sroot 		goto out;
4047421Sroot 	}
4057421Sroot 	/*NOTREACHED*/
4067421Sroot run:
4077421Sroot 	/*
4087421Sroot 	 * Raise priority to at least PUSER.
4097421Sroot 	 */
4107421Sroot 	if (p->p_pri > PUSER)
4117421Sroot 		if ((p != u.u_procp || noproc) && p->p_stat == SRUN &&
4127421Sroot 		    (p->p_flag & SLOAD)) {
4137421Sroot 			remrq(p);
4147421Sroot 			p->p_pri = PUSER;
4157421Sroot 			setrq(p);
4167421Sroot 		} else
4177421Sroot 			p->p_pri = PUSER;
4187421Sroot 	setrun(p);
4197421Sroot out:
4207421Sroot 	splx(s);
4217421Sroot }
4227421Sroot 
4237421Sroot /*
4247421Sroot  * Returns true if the current
4257421Sroot  * process has a signal to process.
4267421Sroot  * The signal to process is put in p_cursig.
4277421Sroot  * This is asked at least once each time a process enters the
4287421Sroot  * system (though this can usually be done without actually
4297421Sroot  * calling issig by checking the pending signal masks.)
4307421Sroot  * A signal does not do anything
4317421Sroot  * directly to a process; it sets
4327421Sroot  * a flag that asks the process to
4337421Sroot  * do something to itself.
4347421Sroot  */
4357421Sroot issig()
4367421Sroot {
4377421Sroot 	register struct proc *p;
4387421Sroot 	register int sig;
4397421Sroot 	long sigbits;
4407421Sroot 	long sigmask;
4417421Sroot 
4427421Sroot 	p = u.u_procp;
4437421Sroot 	for (;;) {
4447421Sroot 		sigbits = p->p_sig;
4457421Sroot 		if ((p->p_flag&STRC) == 0)
4467421Sroot 			sigbits &= ~p->p_ignsig;
4477421Sroot 		if (p->p_flag&SVFORK)
4487421Sroot #define bit(a) (1<<(a-1))
4497421Sroot 			sigbits &= ~(bit(SIGSTOP)|bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU));
4507421Sroot 		if (sigbits == 0)
4517421Sroot 			break;
4527421Sroot 		sig = ffs((int)sigbits);
4537421Sroot 		sigmask = 1L << (sig-1);
4547421Sroot 		p->p_sig &= ~sigmask;		/* take the signal! */
4557421Sroot 		p->p_cursig = sig;
4567421Sroot 		if (p->p_flag&STRC && (p->p_flag&SVFORK)==0) {
4577421Sroot 			/*
4587421Sroot 			 * If traced, always stop, and stay
4597421Sroot 			 * stopped until released by the parent.
4607421Sroot 			 */
4617421Sroot 			do {
4627421Sroot 				stop(p);
4637421Sroot 				swtch();
4647421Sroot 			} while (!procxmt() && p->p_flag&STRC);
4657421Sroot 
4667421Sroot 			/*
4677421Sroot 			 * If the traced bit got turned off,
4687421Sroot 			 * then put the signal taken above back into p_sig
4697421Sroot 			 * and go back up to the top to rescan signals.
4707421Sroot 			 * This ensures that siga0 and u_signal are consistent.
4717421Sroot 			 */
4727421Sroot 			if ((p->p_flag&STRC) == 0) {
4737421Sroot 				p->p_sig |= sigmask;
4747421Sroot 				continue;
4757421Sroot 			}
4767421Sroot 
4777421Sroot 			/*
4787421Sroot 			 * If parent wants us to take the signal,
4797421Sroot 			 * then it will leave it in p->p_cursig;
4807421Sroot 			 * otherwise we just look for signals again.
4817421Sroot 			 */
4827421Sroot 			sig = p->p_cursig;
4837421Sroot 			if (sig == 0)
4847421Sroot 				continue;
4857421Sroot 		}
4867421Sroot 		switch (u.u_signal[sig]) {
4877421Sroot 
4887421Sroot 		case SIG_DFL:
4897421Sroot 			/*
4907421Sroot 			 * Don't take default actions on system processes.
4917421Sroot 			 */
4927421Sroot 			if (p->p_ppid == 0)
4937421Sroot 				break;
4947421Sroot 			switch (sig) {
4957421Sroot 
4967421Sroot 			case SIGTSTP:
4977421Sroot 			case SIGTTIN:
4987421Sroot 			case SIGTTOU:
4997421Sroot 				/*
5007421Sroot 				 * Children of init aren't allowed to stop
5017421Sroot 				 * on signals from the keyboard.
5027421Sroot 				 */
5037421Sroot 				if (p->p_pptr == &proc[1]) {
5047421Sroot 					psignal(p, SIGKILL);
5057421Sroot 					continue;
5067421Sroot 				}
5077421Sroot 				/* fall into ... */
5087421Sroot 
5097421Sroot 			case SIGSTOP:
5107421Sroot 				if (p->p_flag&STRC)
5117421Sroot 					continue;
5127421Sroot 				stop(p);
5137421Sroot 				swtch();
5147421Sroot 				continue;
5157421Sroot 
5167421Sroot 			case SIGCONT:
5177421Sroot 			case SIGCHLD:
5187421Sroot 				/*
5197421Sroot 				 * These signals are normally not
5207421Sroot 				 * sent if the action is the default.
5217421Sroot 				 */
5227421Sroot 				continue;		/* == ignore */
5237421Sroot 
5247421Sroot 			default:
5257421Sroot 				goto send;
5267421Sroot 			}
5277421Sroot 			/*NOTREACHED*/
5287421Sroot 
5297421Sroot 		case SIG_HOLD:
5307421Sroot 		case SIG_IGN:
5317421Sroot 			/*
5327421Sroot 			 * Masking above should prevent us
5337421Sroot 			 * ever trying to take action on a held
5347421Sroot 			 * or ignored signal, unless process is traced.
5357421Sroot 			 */
5367421Sroot 			if ((p->p_flag&STRC) == 0)
5377421Sroot 				printf("issig\n");
5387421Sroot 			continue;
5397421Sroot 
5407421Sroot 		default:
5417421Sroot 			/*
5427421Sroot 			 * This signal has an action, let
5437421Sroot 			 * psig process it.
5447421Sroot 			 */
5457421Sroot 			goto send;
5467421Sroot 		}
5477421Sroot 		/*NOTREACHED*/
5487421Sroot 	}
5497421Sroot 	/*
5507421Sroot 	 * Didn't find a signal to send.
5517421Sroot 	 */
5527421Sroot 	p->p_cursig = 0;
5537421Sroot 	return (0);
5547421Sroot 
5557421Sroot send:
5567421Sroot 	/*
5577421Sroot 	 * Let psig process the signal.
5587421Sroot 	 */
5597421Sroot 	return (sig);
5607421Sroot }
5617421Sroot 
5627421Sroot /*
5637421Sroot  * Put the argument process into the stopped
5647421Sroot  * state and notify the parent via wakeup and/or signal.
5657421Sroot  */
5667421Sroot stop(p)
5677421Sroot 	register struct proc *p;
5687421Sroot {
5697421Sroot 
5707421Sroot 	p->p_stat = SSTOP;
5717421Sroot 	p->p_flag &= ~SWTED;
5727421Sroot 	wakeup((caddr_t)p->p_pptr);
5737421Sroot 	/*
5747421Sroot 	 * Avoid sending signal to parent if process is traced
5757421Sroot 	 */
5767421Sroot 	if (p->p_flag&STRC)
5777421Sroot 		return;
5787421Sroot 	psignal(p->p_pptr, SIGCHLD);
5797421Sroot }
5807421Sroot 
5817421Sroot /*
5827421Sroot  * Perform the action specified by
5837421Sroot  * the current signal.
5847421Sroot  * The usual sequence is:
5857421Sroot  *	if (issig())
5867421Sroot  *		psig();
5877421Sroot  * The signal bit has already been cleared by issig,
5887421Sroot  * and the current signal number stored in p->p_cursig.
5897421Sroot  */
5907421Sroot psig()
5917421Sroot {
5927421Sroot 	register struct proc *rp = u.u_procp;
5937421Sroot 	register int n = rp->p_cursig;
5947421Sroot 	long sigmask = 1L << (n-1);
5957421Sroot 	register int (*action)();
5967421Sroot 
5977421Sroot 	if (rp->p_cursig == 0)
5987421Sroot 		panic("psig");
5997421Sroot 	action = u.u_signal[n];
6007421Sroot 	if (action != SIG_DFL) {
6017421Sroot 		if (action == SIG_IGN || action == SIG_HOLD)
6027421Sroot 			panic("psig action");
6037421Sroot 		u.u_error = 0;
6047421Sroot 		if (n != SIGILL && n != SIGTRAP)
6057421Sroot 			u.u_signal[n] = 0;
6067421Sroot 		/*
6077421Sroot 		 * If this catch value indicates automatic holding of
6087421Sroot 		 * subsequent signals, set the hold value.
6097421Sroot 		 */
6107421Sroot 		if (SIGISDEFER(action)) {
6117421Sroot 			(void) spl6();
6127421Sroot 			if ((int)SIG_HOLD & 1)
6137421Sroot 				rp->p_siga0 |= sigmask;
6147421Sroot 			else
6157421Sroot 				rp->p_siga0 &= ~sigmask;
6167421Sroot 			if ((int)SIG_HOLD & 2)
6177421Sroot 				rp->p_siga1 |= sigmask;
6187421Sroot 			else
6197421Sroot 				rp->p_siga1 &= ~sigmask;
6207421Sroot 			u.u_signal[n] = SIG_HOLD;
6217421Sroot 			(void) spl0();
6227421Sroot 			action = SIGUNDEFER(action);
6237421Sroot 		}
6247421Sroot 		sendsig(action, n);
6257421Sroot 		rp->p_cursig = 0;
6267421Sroot 		return;
6277421Sroot 	}
6287421Sroot 	u.u_acflag |= AXSIG;
6297421Sroot 	switch (n) {
6307421Sroot 
6317421Sroot 	case SIGILL:
6327421Sroot 	case SIGIOT:
6337421Sroot 	case SIGBUS:
6347421Sroot 	case SIGQUIT:
6357421Sroot 	case SIGTRAP:
6367421Sroot 	case SIGEMT:
6377421Sroot 	case SIGFPE:
6387421Sroot 	case SIGSEGV:
6397421Sroot 	case SIGSYS:
6407421Sroot 		u.u_arg[0] = n;
6417421Sroot 		if (core())
6427421Sroot 			n += 0200;
6437421Sroot 	}
6447421Sroot 	exit(n);
6457421Sroot }
6467421Sroot 
6477421Sroot #ifdef unneeded
6487421Sroot int	corestop = 0;
6497421Sroot #endif
6507421Sroot /*
6517421Sroot  * Create a core image on the file "core"
6527421Sroot  * If you are looking for protection glitches,
6537421Sroot  * there are probably a wealth of them here
6547421Sroot  * when this occurs to a suid command.
6557421Sroot  *
6567421Sroot  * It writes UPAGES block of the
6577421Sroot  * user.h area followed by the entire
6587421Sroot  * data+stack segments.
6597421Sroot  */
6607421Sroot core()
6617421Sroot {
6627421Sroot 	register struct inode *ip;
6637421Sroot 	extern schar();
6647421Sroot 
6657421Sroot #ifdef unneeded
6667421Sroot 	if (corestop) {
6677421Sroot 		int i;
6687421Sroot 		for (i = 0; i < 10; i++)
6697421Sroot 			if (u.u_comm[i])
6707421Sroot 				putchar(u.u_comm[i], 0);
6717421Sroot 		printf(", uid %d\n", u.u_uid);
6727421Sroot 		if (corestop&2)
6737421Sroot 			asm("halt");
6747421Sroot 	}
6757421Sroot #endif
6767421Sroot 	if (u.u_uid != u.u_ruid)
6777421Sroot 		return;
6787421Sroot 	if (ctob(UPAGES+u.u_dsize+u.u_ssize) >= u.u_limit[LIM_CORE])
6797421Sroot 		return (0);
6807421Sroot 	u.u_error = 0;
6817421Sroot 	u.u_dirp = "core";
6827421Sroot 	ip = namei(schar, 1, 1);
6837421Sroot 	if (ip == NULL) {
6847421Sroot 		if (u.u_error)
6857421Sroot 			return (0);
6867421Sroot 		ip = maknode(0666);
6877421Sroot 		if (ip==NULL)
6887421Sroot 			return (0);
6897421Sroot 	}
6907421Sroot 	if (!access(ip, IWRITE) &&
6917421Sroot 	   (ip->i_mode&IFMT) == IFREG &&
6927421Sroot 	   ip->i_nlink == 1) {
6937421Sroot 		itrunc(ip);
6947421Sroot 		u.u_acflag |= ACORE;
6957421Sroot 		u.u_offset = 0;
6967421Sroot 		u.u_base = (caddr_t)&u;
6977421Sroot 		u.u_count = ctob(UPAGES);
6987421Sroot 		u.u_segflg = 1;
6997421Sroot 		writei(ip);
7007421Sroot 		u.u_base = (char *)ctob(u.u_tsize);
7017421Sroot 		u.u_count = ctob(u.u_dsize);
7027421Sroot 		u.u_segflg = 0;
7037421Sroot 		writei(ip);
7047421Sroot 		u.u_base = (char *)(USRSTACK - ctob(u.u_ssize));
7057421Sroot 		u.u_count = ctob(u.u_ssize);
7067421Sroot 		writei(ip);
7077421Sroot 	} else
7087421Sroot 		u.u_error = EFAULT;
7097421Sroot 	iput(ip);
7107421Sroot 	return (u.u_error==0);
7117421Sroot }
7127421Sroot /*
713*7499Sroot  * alarm clock signal
7147421Sroot  */
715*7499Sroot oalarm()
7167421Sroot {
7177421Sroot 	register struct proc *p;
718*7499Sroot 	register c;
7197421Sroot 	register struct a {
720*7499Sroot 		int	deltat;
7217421Sroot 	} *uap;
7227421Sroot 
7237421Sroot 	uap = (struct a *)u.u_ap;
724*7499Sroot 	p = u.u_procp;
725*7499Sroot 	c = p->p_clktim;
726*7499Sroot 	p->p_clktim = uap->deltat;
727*7499Sroot 	u.u_r.r_val1 = c;
7287421Sroot }
7297421Sroot 
7307421Sroot /*
731*7499Sroot  * indefinite wait.
732*7499Sroot  * no one should wakeup(&u)
7337421Sroot  */
734*7499Sroot opause()
7357421Sroot {
7367421Sroot 
737*7499Sroot 	for (;;)
738*7499Sroot 		sleep((caddr_t)&u, PSLEP);
739*7499Sroot }
7407421Sroot 
741