crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs

interrupt.c (2321B)


      1 /*************************************************************************
      2  * This file is part of Crosroads 1.23, a load balancer and fail over
      3  * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL.
      4  * Visit http://crossroads.e-tunity.com for information.
      5  *************************************************************************/
      6 #include "crossroads.h"
      7 
      8 /* Signal handler */
      9 void interrupt (int sig) {
     10     msg ("Caught signal %d", sig);
     11     
     12     /* SIGHUP (1) is handled differently, it will reload the allow- and
     13      * deny files when in waiting mode. In other modes it will be ignored. */
     14     if (sig == SIGHUP) {
     15 	if (program_stage == stage_waiting) {
     16 	    if (ipf_loadfile (activeservice->allowfile,
     17 			      &(activeservice->allowchain),
     18 			      &(activeservice->nallowchain)))
     19 		warning ("Bad syntax in allow file");
     20 	    if (ipf_loadfile (activeservice->denyfile,
     21 			      &(activeservice->denychain),
     22 			      &(activeservice->ndenychain)))
     23 		warning ("Bad syntax in deny file");
     24 	}
     25 
     26 	msg ("Service %s: allow chain has %d entries, "
     27 	     "deny chain has %d entries", activeservice->name,
     28 	     activeservice->nallowchain, activeservice->ndenychain);
     29 	return;
     30     }
     31 
     32     /* For all other signals: flag that we're signalled, and depending on
     33      * the stage, exit right away or wait 'till the servicer stops. */
     34     
     35     interrupted++;
     36     
     37     switch (program_stage) {
     38     case stage_waiting:
     39 	warning ("Service %s: listener caught signal %d, "
     40 		 "closing socket %d and exiting",
     41 		 activeservice->name, sig, listen_sock);
     42 	if (shutdown (listen_sock, SHUT_RDWR))
     43 	    error ("Service %s: can't shut down server-side socket %d: %s",
     44 		     activeservice->name, listen_sock, strerror(errno));
     45 	if (close (listen_sock))
     46 	    error ("Service %s: can't close socket %d: %s",
     47 		   activeservice->name, listen_sock, strerror(errno));
     48 	exit (0);
     49     case stage_serving:
     50 	warning ("Service %s: servicer caught signal %d, "
     51 		 "will exit after servicing my connection",
     52 		 activeservice->name, sig);
     53 	break;
     54     case stage_retrying:
     55 	warning ("Service %s: wakeup handler caught signal %d, "
     56 		 "stopping wake ups and exiting",
     57 		 activeservice->name, sig);
     58 	exit (0);
     59     default:
     60 	msg ("Caught signal %d in program stage %s, exiting", sig,
     61 	     stage_to_string (program_stage));
     62 	exit (0);
     63     }
     64 }