X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprocess.c;h=44a4c7663e7ffad318ea51e942378e35bc911e93;hb=760dd966efe7dbff316a8c638e40dee162848256;hp=11e8b4fc7b98920fadb981e4fe1c7cc74eced74d;hpb=de78d79db84c486afcc353884ec1770866beb653;p=tinc diff --git a/src/process.c b/src/process.c index 11e8b4fc..44a4c766 100644 --- a/src/process.c +++ b/src/process.c @@ -36,14 +36,12 @@ /* If zero, don't detach from the terminal. */ bool do_detach = true; -bool sighup = false; bool sigalrm = false; extern char *identname; extern char *pidfilename; extern char **g_argv; extern bool use_logfile; -extern volatile bool running; sigset_t emptysigset; @@ -165,19 +163,11 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) { return ERROR_CALL_NOT_IMPLEMENTED; } - if(running) { - running = false; - status.dwWaitHint = 30000; - status.dwCurrentState = SERVICE_STOP_PENDING; - SetServiceStatus(statushandle, &status); - return NO_ERROR; - } else { - status.dwWaitHint = 0; - status.dwCurrentState = SERVICE_STOPPED; - SetServiceStatus(statushandle, &status); - exit(1); - } - + event_loopexit(NULL); + status.dwWaitHint = 30000; + status.dwCurrentState = SERVICE_STOP_PENDING; + SetServiceStatus(statushandle, &status); + return NO_ERROR; } VOID WINAPI run_service(DWORD argc, LPTSTR* argv) @@ -379,8 +369,10 @@ bool execute_script(const char *name, char **envp) /* First check if there is a script */ - if(stat(scriptname + 1, &s)) + if(stat(scriptname + 1, &s)) { + free(scriptname); return true; + } ifdebug(STATUS) logger(LOG_INFO, _("Executing script %s"), name); @@ -439,24 +431,6 @@ bool execute_script(const char *name, char **envp) */ #ifndef HAVE_MINGW -static RETSIGTYPE sigterm_handler(int a) -{ - logger(LOG_NOTICE, _("Got %s signal"), "TERM"); - if(running) - running = false; - else - exit(1); -} - -static RETSIGTYPE sigquit_handler(int a) -{ - logger(LOG_NOTICE, _("Got %s signal"), "QUIT"); - if(running) - running = false; - else - exit(1); -} - static RETSIGTYPE fatal_signal_square(int a) { logger(LOG_ERR, _("Got another fatal signal %d (%s): not restarting."), a, @@ -489,54 +463,6 @@ static RETSIGTYPE fatal_signal_handler(int a) } } -static RETSIGTYPE sighup_handler(int a) -{ - logger(LOG_NOTICE, _("Got %s signal"), "HUP"); - sighup = true; -} - -static RETSIGTYPE sigint_handler(int a) -{ - logger(LOG_NOTICE, _("Got %s signal"), "INT"); - - if(saved_debug_level != -1) { - logger(LOG_NOTICE, _("Reverting to old debug level (%d)"), - saved_debug_level); - debug_level = saved_debug_level; - saved_debug_level = -1; - } else { - logger(LOG_NOTICE, - _("Temporarily setting debug level to 5. Kill me with SIGINT again to go back to level %d."), - debug_level); - saved_debug_level = debug_level; - debug_level = 5; - } -} - -static RETSIGTYPE sigalrm_handler(int a) -{ - logger(LOG_NOTICE, _("Got %s signal"), "ALRM"); - sigalrm = true; -} - -static RETSIGTYPE sigusr1_handler(int a) -{ - dump_connections(); -} - -static RETSIGTYPE sigusr2_handler(int a) -{ - dump_device_stats(); - dump_nodes(); - dump_edges(); - dump_subnets(); -} - -static RETSIGTYPE sigwinch_handler(int a) -{ - do_purge = true; -} - static RETSIGTYPE unexpected_signal_handler(int a) { logger(LOG_WARNING, _("Got unexpected signal %d (%s)"), a, strsignal(a)); @@ -552,19 +478,11 @@ static struct { int signal; void (*handler)(int); } sighandlers[] = { - {SIGHUP, sighup_handler}, - {SIGTERM, sigterm_handler}, - {SIGQUIT, sigquit_handler}, {SIGSEGV, fatal_signal_handler}, {SIGBUS, fatal_signal_handler}, {SIGILL, fatal_signal_handler}, {SIGPIPE, ignore_signal_handler}, - {SIGINT, sigint_handler}, - {SIGUSR1, sigusr1_handler}, - {SIGUSR2, sigusr2_handler}, {SIGCHLD, ignore_signal_handler}, - {SIGALRM, sigalrm_handler}, - {SIGWINCH, sigwinch_handler}, {0, NULL} }; #endif @@ -592,7 +510,7 @@ void setup_signals(void) /* If we didn't detach, allow coredumps */ if(!do_detach) - sighandlers[3].handler = SIG_DFL; + sighandlers[0].handler = SIG_DFL; /* Then, for each known signal that we want to catch, assign a handler to the signal, with error checking this time. */