home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / SRS / client / src / sighandlers.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-12  |  4.9 KB  |  239 lines

  1. /* functions for signal handling */
  2. /* ----------------------------- */
  3.  
  4. #include "headers.h" /* all important stuff */ 
  5.  
  6. /* handle various signals */
  7. RETSIGTYPE sighandler(int sig)
  8. {
  9.    int oerrno = errno; /* save old errno */
  10.  
  11.    (void)signal(SIGPIPE, SIG_IGN);
  12.  
  13.    /* need local scope variables here.. */
  14.    if (debugging == 1)
  15.    {
  16.       char *line = "-------------------------------------------------";
  17.       char *error = "\nsignal handler called.. ";     
  18.  
  19.       (void)write(STDOUT, line, strlen(line));
  20.       (void)write(STDOUT, error, strlen(error));
  21.  
  22.       (void)printf("signal number %2d received\n", sig);
  23.       (void)fflush(stdout);
  24.    }
  25.  
  26.    if ((sig == SIGILL) || (sig == SIGBUS) || (sig == SIGSEGV))
  27.    {
  28.       error("got a fatal signal to abort.. signal = %d\n\n", sig);
  29.  
  30.       if (done == 1) return;
  31.       else longjmp(doquit, ERROR);
  32.    }
  33.  
  34.    else if ((sig == SIGINT) || (sig == SIGTERM) || (sig == SIGQUIT))
  35.    {
  36.       if (done == 1) return;
  37.       else longjmp(doquit, ABORT);
  38.    }
  39.  
  40.    else if (sig == SIGPIPE)
  41.    {
  42.       connected = 0;
  43.  
  44.       error("the server dropped the connection..\n\n");
  45.  
  46.       if (done == 1) return;
  47.       else longjmp(sigdropconn, 1);
  48.    }
  49.  
  50.    else if (sig == SIGUSR1) running = 1;
  51.  
  52.    else if (sig == SIGHUP)
  53.    {
  54.       config(); /* re-read config file */
  55.       (void)signal(SIGHUP, sighandler);
  56.    }
  57.  
  58.    else 
  59.    {
  60.       char *error = "Error: that signal is not being handled\n";
  61.       (void)write(STDERR, error, strlen(error));
  62.    }
  63.  
  64.    errno = oerrno; /* restore old errno */
  65. }
  66.  
  67.  
  68. /* --------------------- */
  69.  
  70.  
  71. /* called when we've timed out after restarting at top of server list */
  72. RETSIGTYPE restart(int sig)
  73. {
  74.     error("unable to reconnect to a streaming server..\n"
  75.           "getting a new server list\n\n");
  76.  
  77.    if (done == 1) return;
  78.    else longjmp(infoconn, 1);
  79. }
  80. /* --------------------- */
  81.       
  82.  
  83. /* timed out checking for an error */
  84. RETSIGTYPE errTimeout(int sig)
  85. {
  86.    gotAlrm = 1;
  87.    return;
  88. }
  89.  
  90.  
  91. /* --------------------- */
  92.  
  93.  
  94. /* called when we timeout waiting for Sub-ID */
  95. void subIDTimeout(int sig) 
  96. {
  97.    error("timed out while waiting for Sub-ID.. aborting\n\n");
  98.  
  99.    if (done == 1) return;
  100.    else longjmp(doquit, ERROR);
  101. }
  102.  
  103.  
  104. /* --------------------- */
  105.  
  106.  
  107. /* timeouit waiting for server list */
  108. RETSIGTYPE listTimeout(int sig)
  109. {
  110.    error("timed out while waiting for server list.. aborting\n\n");
  111.  
  112.    if (done == 1) return;
  113.    else longjmp(doquit, ERROR);
  114. }
  115.  
  116.  
  117. /* --------------------- */
  118.  
  119.  
  120. /* called when we time out waiting for server to send us */
  121. /* the current client and server versions                */
  122.  
  123. RETSIGTYPE verTimeout(int sig)
  124. {
  125.    error("timed out waiting for server/client version.. aborting\n\n");
  126.  
  127.    if (done == 1) return;
  128.    else longjmp(doquit, ERROR);
  129. }
  130.  
  131.  
  132. /* --------------------- */
  133.  
  134.  
  135. /* called when we timeout sending or receiving "OKAY" */
  136. RETSIGTYPE okayTimeout(int sig)
  137. {
  138.    error("timed out waiting for or sending OKAY\n\n");
  139.    gotAlrm = 1;
  140. }
  141.  
  142.  
  143. /* -------------------------- */
  144.  
  145.  
  146. /* called when child OK's us to run */
  147. RETSIGTYPE startUp(int sig)
  148. {
  149.    if (debugging == 1)
  150.    {
  151.       char *error = "(in parent) got SIGUSR2 from child (free to continue)\n";
  152.       (void)write(STDOUT, error, strlen(error));
  153.    }
  154.  
  155.    /* FIX - make reentrant by using sigaction() instead */
  156.    /*     - or sigaddset, sigemptyset, etc.             */
  157.  
  158.    (void)signal(SIGUSR2, startUp);
  159.  
  160.    running = 1;
  161.    return;
  162. }
  163.  
  164.  
  165. /* --------------------- */
  166.  
  167.  
  168. /* called when we get new data.. according to parent */
  169. RETSIGTYPE gotNewData(int sig)
  170. {
  171.    if (debugging == 1)
  172.    {
  173.       char *error= "(in child) got SIGUSR1 from parent (new data available)\n";
  174.       (void)write(STDOUT, error, strlen(error));
  175.    }
  176.  
  177.    /* FIX - make reentrant by using sigaction() instead */
  178.    /*     - or sigaddset, sigemptyset, etc.             */
  179.  
  180.    (void)signal(SIGUSR1, gotNewData);
  181.    newData = 1;
  182.  
  183.    return;
  184. }
  185.  
  186.  
  187. /* --------------------- */
  188.  
  189.  
  190. /* signal handler when sigpipe from info server is received */
  191. RETSIGTYPE dropinfoconn(int sig)
  192. {
  193.    /* FIX - make reentrant by using sigaction() instead */
  194.    /*     - or sigaddset, sigemptyset, etc.             */
  195.  
  196.    error("connection with info server dropped..\n"
  197.          "reconnecting to new one\n\n");
  198.  
  199. #  ifdef BEEP   
  200.    if (debugging == 1) (void)putchar('\a');
  201. #  endif
  202.  
  203.    connected = 0;
  204.  
  205.    if (done == 1) return;
  206.    else longjmp(infoconn, 1);
  207. }
  208.  
  209.  
  210. /* ---------------------- */
  211.  
  212.  
  213. /* called when SIGPIPE (connection dropped) is received */
  214. RETSIGTYPE dropstreamconn(int stat)
  215. {
  216.    int res; /* used for checking some results */
  217.  
  218.    res = setjmp(sigdropconn);
  219.    if (res == ERROR)
  220.    {
  221.       error("error with setjmp(): %s\n\n", strerror(errno));
  222.       quit(ERROR);
  223.    }
  224.  
  225.    if (stat == INIT) return; /* they just came to init it */
  226.  
  227.    connected = 0;
  228.  
  229. #  ifdef BEEP   
  230.    if (debugging == 1) (void)putchar('\a');
  231. #  endif
  232.  
  233.    error("server #%d (%s, port %d) dropped connection...\n\n",
  234.          curServ, servList[curServ].name, servList[curServ].port);
  235.  
  236.    if (done == 1) return;
  237.    else longjmp(dropconn, 1);
  238. }
  239.