From c5b1f979e4e4b9bc24e3bcea742d979f0351c6fd Mon Sep 17 00:00:00 2001 From: James Laird Date: Mon, 3 Jun 2013 22:51:53 +1000 Subject: [PATCH] mdns: die iff the MDNS advertising process dies and not if any other child does! --- mdns.c | 2 +- mdns.h | 2 ++ rtsp.c | 9 ++++++++- shairport.c | 13 +++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mdns.c b/mdns.c index 5583581d6..936e33385 100644 --- a/mdns.c +++ b/mdns.c @@ -31,7 +31,7 @@ #include #include "common.h" -static int mdns_pid = 0; +int mdns_pid = 0; void mdns_unregister(void) { if (mdns_pid) diff --git a/mdns.h b/mdns.h index fe83bfe11..9827c0c3e 100644 --- a/mdns.h +++ b/mdns.h @@ -1,6 +1,8 @@ #ifndef _MDNS_H #define _MDNS_H +extern int mdns_pid; + void mdns_unregister(void); void mdns_register(void); diff --git a/rtsp.c b/rtsp.c index d25bba9e3..9e048fc56 100644 --- a/rtsp.c +++ b/rtsp.c @@ -791,7 +791,14 @@ void rtsp_listen_loop(void) { printf("Listening for connections.\n"); int acceptfd; - while (select(maxfd+1, &fds, 0, 0, 0) >= 0) { + while (1) { + ret = select(maxfd+1, &fds, 0, 0, 0); + if (ret<0) { + if (errno==EINTR) + continue; + break; + } + for (i=0; i #include #include +#include #include "common.h" #include "rtsp.h" #include "mdns.h" @@ -50,6 +51,15 @@ static void sig_shutdown(int foo, siginfo_t *bar, void *baz) { shairport_shutdown(); } +static void sig_child(int foo, siginfo_t *bar, void *baz) { + pid_t pid; + while ((pid = waitpid((pid_t)-1, 0, WNOHANG)) > 0) { + if (pid == mdns_pid && !shutting_down) { + die("MDNS child process died unexpectedly!"); + } + } +} + void usage(char *progname) { printf("Usage: %s [options...] [-- [output options...]]\n\n", progname); printf("Available options:\n" @@ -128,6 +138,9 @@ void signal_setup(void) { sa.sa_sigaction = &sig_shutdown; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); + + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = &sig_child; sigaction(SIGCHLD, &sa, NULL); }