trap.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "rc.h"
  10. #include "exec.h"
  11. #include "fns.h"
  12. #include "io.h"
  13. extern char *Signame[];
  14. void
  15. dotrap(void)
  16. {
  17. int i;
  18. struct var *trapreq;
  19. struct word *starval;
  20. starval = vlook("*")->val;
  21. while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){
  22. --trap[i];
  23. --ntrap;
  24. if(getpid()!=mypid) Exit(getstatus());
  25. trapreq = vlook(Signame[i]);
  26. if(trapreq->fn){
  27. start(trapreq->fn, trapreq->pc, (struct var *)0);
  28. runq->local = newvar(strdup("*"), runq->local);
  29. runq->local->val = copywords(starval, (struct word *)0);
  30. runq->local->changed = 1;
  31. runq->redir = runq->startredir = 0;
  32. }
  33. else if(i==SIGINT || i==SIGQUIT){
  34. /*
  35. * run the stack down until we uncover the
  36. * command reading loop. Xreturn will exit
  37. * if there is none (i.e. if this is not
  38. * an interactive rc.)
  39. */
  40. while(!runq->iflag) Xreturn();
  41. }
  42. else Exit(getstatus());
  43. }
  44. }