trap.c 878 B

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