diff options
-rw-r--r-- | src/sig_handler.c | 12 | ||||
-rw-r--r-- | src/tcpproxy.c | 15 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/sig_handler.c b/src/sig_handler.c index cc7276d..fb50000 100644 --- a/src/sig_handler.c +++ b/src/sig_handler.c @@ -116,12 +116,12 @@ int signal_handle() for(sig=1; sig < NSIG; ++sig) { if(sigismember(&set, sig)) { switch(sig) { - case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); return_value = 1; break; - case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); return_value = 1; break; - case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); return_value = 1; break; - case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); return_value = 2; break; - case SIGUSR1: log_printf(NOTICE, "SIG-Usr1 caught"); return_value = 3; break; - case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); return_value = 4; break; + case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); return_value = SIGINT; break; + case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); return_value = SIGQUIT; break; + case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); return_value = SIGTERM; break; + case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); return_value = SIGHUP; break; + case SIGUSR1: log_printf(NOTICE, "SIG-Usr1 caught"); return_value = SIGUSR1; break; + case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); return_value = SIGUSR2; break; default: log_printf(WARNING, "unknown signal %d caught, ignoring", sig); break; } sigdelset(&set, sig); diff --git a/src/tcpproxy.c b/src/tcpproxy.c index baa5214..a22744a 100644 --- a/src/tcpproxy.c +++ b/src/tcpproxy.c @@ -30,6 +30,9 @@ #include <errno.h> #include <string.h> #include <sys/select.h> +#include <sys/types.h> +#include <unistd.h> +#include <signal.h> #include "datatypes.h" #include "options.h" @@ -73,8 +76,8 @@ int main_loop(options_t* opt, listeners_t* listeners) if(FD_ISSET(sig_fd, &readfds)) { return_value = signal_handle(); - if(return_value == 1) break; - if(return_value == 2) { + if(return_value == SIGINT || return_value == SIGQUIT || return_value == SIGTERM) break; + if(return_value == SIGHUP) { if(opt->config_file_) { log_printf(NOTICE, "re-reading config file: %s", opt->config_file_); read_configfile(opt->config_file_, listeners); @@ -82,9 +85,9 @@ int main_loop(options_t* opt, listeners_t* listeners) log_printf(NOTICE, "ignoring SIGHUP: no config file specified"); return_value = 0; - } else if(return_value == 3) { + } else if(return_value == SIGUSR1) { listeners_print(listeners); - } else if(return_value == 4) { + } else if(return_value == SIGUSR2) { clients_print(&clients); } } @@ -233,8 +236,10 @@ int main(int argc, char* argv[]) log_printf(NOTICE, "normal shutdown"); else if(ret < 0) log_printf(NOTICE, "shutdown after error"); - else + else { log_printf(NOTICE, "shutdown after signal"); + kill(getpid(), ret); + } log_close(); |