From a8dcf5fcb160e94d0fcdb12ac71961c85e1e4599 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 23 Jan 2015 11:56:55 +0100 Subject: Replace signal() by sigaction() --- src/DabMux.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/DabMux.cpp b/src/DabMux.cpp index 8ccebef..376e33c 100644 --- a/src/DabMux.cpp +++ b/src/DabMux.cpp @@ -177,7 +177,7 @@ const unsigned short BitRateTable[64] = { }; -bool running = true; +volatile sig_atomic_t running = 1; void signalHandler(int signum) { @@ -214,25 +214,25 @@ void signalHandler(int signum) #ifndef _WIN32 killpg(0, SIGPIPE); #endif - running = false; + running = 0; } int main(int argc, char *argv[]) { - header_message(); - /* for (int signum = 1; signum < 16; ++signum) { - signal(signum, signalHandler); - }*/ -#ifndef _WIN32 - signal(SIGHUP, signalHandler); - signal(SIGQUIT, signalHandler); -#endif - signal(SIGINT, signalHandler); - signal(SIGTERM, signalHandler); - //signal(SIGPIPE, signalHandler); + struct sigaction sa; + memset(&sa, 0, sizeof(struct sigaction)); + sa.sa_handler = &signalHandler; + + const int sigs[] = {SIGHUP, SIGQUIT, SIGINT, SIGTERM}; + for (int i = 0; i < 4; i++) { + if (sigaction(sigs[i], &sa, NULL) == -1) { + perror("sigaction"); + return EXIT_FAILURE; + } + } #ifdef _WIN32 if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST) == 0) { -- cgit v1.2.3