summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sig_handler.c8
-rw-r--r--src/uanytun.c14
2 files changed, 14 insertions, 8 deletions
diff --git a/src/sig_handler.c b/src/sig_handler.c
index 5de168e..f23d070 100644
--- a/src/sig_handler.c
+++ b/src/sig_handler.c
@@ -139,10 +139,10 @@ 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 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"); break;
case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); break;
default: log_printf(WARNING, "unknown signal %d caught, ignoring", sig); break;
diff --git a/src/uanytun.c b/src/uanytun.c
index 159f773..da90eda 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -52,6 +52,10 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <sys/select.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
#include "log.h"
#include "sig_handler.h"
@@ -258,9 +262,8 @@ int main_loop(tun_device_t* dev, udp_t* sock, options_t* opt)
if(FD_ISSET(sig_fd, &readyfds)) {
return_value = signal_handle();
- if(return_value == 1)
- break;
- else if(return_value == 2) {
+ if(return_value == SIGINT || return_value == SIGQUIT || return_value == SIGTERM) break;
+ else if(return_value == SIGHUP) {
seq_win_clear(&seq_win);
seq_nr = 0;
log_printf(NOTICE, "sequence window cleared");
@@ -447,8 +450,11 @@ 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");
+ log_close();
+ kill(getpid(), ret);
+ }
log_close();