home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3998 / signal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-09  |  4.7 KB  |  217 lines

  1. /*
  2.  * @(#)signal.c    1.5 91/09/05
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <sys/types.h>
  8. #include <sys/ptrace.h>
  9. #include <sys/signal.h>
  10.  
  11. #include "defs.h"
  12.  
  13. char *signals[] = {
  14.      "SIGNULL",
  15.      "SIGHUP",   /*    1    hangup */
  16.      "SIGINT",   /*    2    interrupt */
  17.      "SIGQUIT",  /*    3*   quit */
  18.      "SIGILL",   /*    4*   illegal instruction */
  19.      "SIGTRAP",  /*    5*   trace trap */
  20.      "SIGIOT",   /*    6*   IOT trap (not generated on Suns) */
  21.      "SIGEMT",   /*    7*   EMT trap (A-line or F-line op code) */
  22.      "SIGFPE",   /*    8*   arithmetic exception */
  23.      "SIGKILL",  /*    9    kill (cannot be caught, blocked, or ignored) */
  24.      "SIGBUS",   /*    10*  bus error */
  25.      "SIGSEGV",  /*    11*  segmentation violation */
  26.      "SIGSYS",   /*    12*  bad argument to system call */
  27.      "SIGPIPE",  /*    13   write on a pipe with no one to read it */
  28.      "SIGALRM",  /*    14   alarm clock */
  29.      "SIGTERM",  /*    15   software termination signal */
  30.      "SIGURG",   /*    16@  urgent condition present on socket */
  31.      "SIGSTOP",  /*    17+  stop (cannot be caught, blocked, or ignored) */
  32.      "SIGTSTP",  /*    18+  stop signal generated from keyboard */
  33.      "SIGCONT",  /*    19@  continue after stop (cannot be blocked) */
  34.      "SIGCHLD",  /*    20@  child status has changed */
  35.      "SIGTTIN",  /*    21+  background read attempted from control terminal */
  36.      "SIGTTOU",  /*    22+  background write attempted to control terminal */
  37.      "SIGIO",    /*    23@  I/O is possible on a descriptor (see fcntl(2)) */
  38.      "SIGXCPU",  /*    24   cpu time limit exceeded (see setrlimit(2)) */
  39.      "SIGXFSZ",  /*    25   file size limit exceeded (see setrlimit(2)) */
  40.      "SIGVTALRM", /*   26   virtual time alarm (see setitimer(2)) */
  41.      "SIGPROF",  /*    27   profiling timer alarm (see setitimer(2)) */
  42.      "SIGWINCH", /*    28@  window changed (see win(4S)) */
  43.      "SIGLOST",  /*    29*  resource lost (see lockd(8C)) */
  44.      "SIGUSR1",  /*    30   user-defined signal 1 */
  45.      "SIGUSR2"   /*    31   user-defined signal 2 */
  46. };
  47.  
  48. static Xlat sigvec_flags[] = {
  49.     SV_ONSTACK,    "ONSTACK",
  50.     SV_INTERRUPT,    "INTERRUPT",
  51.     SV_RESETHAND,    "RESETHAND",
  52.     SA_NOCLDSTOP,    "NOCLDSTOP",
  53.     0,        NULL,
  54. };
  55.  
  56. static void
  57. printsigmask(mask)
  58. sigset_t mask;
  59. {
  60.     int i;
  61.     char *format;
  62.  
  63.     format = "%s";
  64.     fprintf(outf, "[", mask);
  65.     for (i = 0; i < NSIG; i++) {
  66.         if (mask & sigmask(i)) {
  67.             fprintf(outf, format, signals[i]);
  68.             format = " %s";
  69.         }
  70.     }
  71.     fprintf(outf, "]", mask);
  72. }
  73.  
  74. int
  75. sys_sigvec(tcp)
  76. struct tcb *tcp;
  77. {
  78.     struct sigvec sv;
  79.     int addr;
  80.  
  81.     if (entering(tcp)) {
  82.         fprintf(outf, "%s, ", signals[tcp->u_args[0]]);
  83.         addr = tcp->u_args[1];
  84.     } else {
  85.         addr = tcp->u_args[2];
  86.     }
  87.     if (addr == 0 || umove(tcp->pid, addr, sizeof sv, (char *)&sv) < 0) {
  88.         fprintf(outf, "(struct sigvec *)0");
  89.     } else {
  90.         switch (sv.sv_handler) {
  91.         case SIG_ERR:
  92.             fprintf(outf, "SIG_ERR");
  93.             break;
  94.         case SIG_DFL:
  95.             fprintf(outf, "SIG_DFL");
  96.             break;
  97.         case SIG_IGN:
  98.             fprintf(outf, "SIG_IGN");
  99.             break;
  100.         default:
  101.             fprintf(outf, "{%#x, ", sv.sv_handler);
  102.             printsigmask(sv.sv_mask);
  103.             fprintf(outf, ", ");
  104.             if (!printflags(sigvec_flags, sv.sv_flags))
  105.                 putc('0', outf);
  106.             putc('}', outf);
  107.         }
  108.     }
  109.     if (entering(tcp))
  110.         fprintf(outf, ", ");
  111.     return 0;
  112. }
  113.  
  114. int
  115. sys_sigblock(tcp)
  116. struct tcb *tcp;
  117. {
  118.     if (entering(tcp)) {
  119.         printsigmask(tcp->u_args[0]);
  120.         if ((tcp->u_args[0] & sigmask(SIGTRAP)) && brutal) {
  121.             pokearg(tcp->pid, 0, tcp->u_args[0] & ~sigmask(SIGTRAP));
  122.         }
  123.     }
  124.     return 0;
  125. }
  126.  
  127. int
  128. sys_sigsetmask(tcp)
  129. struct tcb *tcp;
  130. {
  131.     if (entering(tcp)) {
  132.         if (tcp->u_args[0])
  133.             printsigmask(tcp->u_args[0]);
  134.         else
  135.             fprintf(outf, "0");
  136.     }
  137.     return 0;
  138. }
  139.  
  140. int
  141. sys_sigpause(tcp)
  142. struct tcb *tcp;
  143. {
  144.     if (entering(tcp)) {
  145.         if (tcp->u_args[0])
  146.             printsigmask(tcp->u_args[0]);
  147.         else
  148.             fprintf(outf, "0");
  149.     }
  150.     return 0;
  151. }
  152.  
  153. int
  154. sys_sigstack(tcp)
  155. struct tcb *tcp;
  156. {
  157.     struct sigstack ss;
  158.     int addr;
  159.  
  160.     if (entering(tcp)) {
  161.         addr = tcp->u_args[0];
  162.     } else {
  163.         addr = tcp->u_args[1];
  164.     }
  165.     if (addr == 0 || umove(tcp->pid, addr, sizeof ss, (char *)&ss)) {
  166.         fprintf(outf, "(struct sigstack *)0");
  167.     } else {
  168.         fprintf(outf, "{sp: %#x,", ss.ss_sp);
  169.         fprintf(outf, "%s}", ss.ss_onstack?"ON":"OFF");
  170.     }
  171.     if (entering(tcp))
  172.         fprintf(outf, ", ");
  173.     return 0;
  174. }
  175.  
  176. int
  177. sys_sigcleanup(tcp)
  178. struct tcb *tcp;
  179. {
  180.     return 0;
  181. }
  182.  
  183. int
  184. sys_kill(tcp)
  185. struct tcb *tcp;
  186. {
  187.     if (entering(tcp)) {
  188.         fprintf(outf, "%d, %s",
  189.                 tcp->u_args[0], signals[tcp->u_args[1]]);
  190.     }
  191.     return 0;
  192. }
  193.  
  194. int
  195. sys_killpg(tcp)
  196. struct tcb *tcp;
  197. {
  198.     return sys_kill(tcp);
  199. }
  200.  
  201. int
  202. sys_sigpending(tcp)
  203. struct tcb *tcp;
  204. {
  205.     sigset_t sigset;
  206.  
  207.     if (exiting(tcp)) {
  208.         if (syserror(tcp) ||
  209.             umove(tcp->pid, tcp->u_args[0],
  210.                 sizeof sigset, (char *)&sigset) < 0)
  211.             fprintf(outf, "%#x", tcp->u_args[0]);
  212.         else
  213.             printsigmask(sigset);
  214.     }
  215.     return 0;
  216. }
  217.