summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-01-23 11:56:55 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-01-23 11:56:55 +0100
commita8dcf5fcb160e94d0fcdb12ac71961c85e1e4599 (patch)
treec5fd482008ad67eb0a800e3e268fd7859549af63 /src
parent02d9f1e887da7253f933db392a808a509e30fd48 (diff)
downloaddabmux-a8dcf5fcb160e94d0fcdb12ac71961c85e1e4599.tar.gz
dabmux-a8dcf5fcb160e94d0fcdb12ac71961c85e1e4599.tar.bz2
dabmux-a8dcf5fcb160e94d0fcdb12ac71961c85e1e4599.zip
Replace signal() by sigaction()
Diffstat (limited to 'src')
-rw-r--r--src/DabMux.cpp26
1 files changed, 13 insertions, 13 deletions
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) {