From: Juho Vähä-Herttua Date: Tue, 9 Apr 2013 09:40:26 +0000 (+0300) Subject: Add signal handlers to shairplay to make it shut down gracefully X-Git-Tag: upstream/0.9.0~4^2~30 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2c4250f147fa35b9adf48ea33067249f8d9cea25;p=deb_shairplay.git Add signal handlers to shairplay to make it shut down gracefully --- diff --git a/src/shairplay.c b/src/shairplay.c index 9cccf03..09210bf 100644 --- a/src/shairplay.c +++ b/src/shairplay.c @@ -6,7 +6,7 @@ #include #ifdef WIN32 -#include +# include #endif #include @@ -39,6 +39,33 @@ typedef struct { static int running; +#ifndef WIN32 + +#include +static void +signal_handler(int sig) +{ + switch (sig) { + case SIGINT: + case SIGTERM: + running = 0; + break; + } +} +static void +init_signals(void) +{ + struct sigaction sigact; + + sigact.sa_handler = signal_handler; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + sigaction(SIGINT, &sigact, NULL); + sigaction(SIGTERM, &sigact, NULL); +} + +#endif + static ao_device * audio_open_device(shairplay_options_t *opt, int bits, int channels, int samplerate) @@ -238,6 +265,10 @@ main(int argc, char *argv[]) int error; +#ifndef WIN32 + init_signals(); +#endif + memset(&options, 0, sizeof(options)); if (parse_options(&options, argc, argv)) { return 0;