summaryrefslogtreecommitdiff
path: root/sys/src/cmd/rc/trap.c
blob: 59f06d25b1dc00e3cc713af7def99fd250c5cfef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "rc.h"
#include "exec.h"
#include "fns.h"
#include "io.h"
extern char *Signame[];

void
dotrap(void)
{
	int i;
	var *trapreq;
	word *starval;
	starval = vlook("*")->val;
	while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
		--trap[i];
		--ntrap;
		if(getpid()!=mypid) Exit(getstatus());
		trapreq = vlook(Signame[i]);
		if(trapreq->fn)
			startfunc(trapreq, copywords(starval, (word*)0), (var*)0, (redir*)0);
		else if(i==SIGINT || i==SIGQUIT){
			/*
			 * run the stack down until we uncover the
			 * command reading loop.  Xreturn will exit
			 * if there is none (i.e. if this is not
			 * an interactive rc.)
			 */
			while(!runq->iflag) Xreturn();
		}
		else Exit(getstatus());
	}
}