9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

trap.c (878B)


      1 #include "rc.h"
      2 #include "exec.h"
      3 #include "fns.h"
      4 #include "io.h"
      5 extern char *Signame[];
      6 
      7 void
      8 dotrap(void)
      9 {
     10 	int i;
     11 	struct var *trapreq;
     12 	struct word *starval;
     13 	starval = vlook("*")->val;
     14 	while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
     15 		--trap[i];
     16 		--ntrap;
     17 		if(getpid()!=mypid) Exit(getstatus());
     18 		trapreq = vlook(Signame[i]);
     19 		if(trapreq->fn){
     20 			start(trapreq->fn, trapreq->pc, (struct var *)0);
     21 			runq->local = newvar(strdup("*"), runq->local);
     22 			runq->local->val = copywords(starval, (struct word *)0);
     23 			runq->local->changed = 1;
     24 			runq->redir = runq->startredir = 0;
     25 		}
     26 		else if(i==SIGINT || i==SIGQUIT){
     27 			/*
     28 			 * run the stack down until we uncover the
     29 			 * command reading loop.  Xreturn will exit
     30 			 * if there is none (i.e. if this is not
     31 			 * an interactive rc.)
     32 			 */
     33 			while(!runq->iflag) Xreturn();
     34 		}
     35 		else Exit(getstatus());
     36 	}
     37 }