mdns: die iff the MDNS advertising process dies
and not if any other child does!
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
|
||||
static int mdns_pid = 0;
|
||||
int mdns_pid = 0;
|
||||
|
||||
void mdns_unregister(void) {
|
||||
if (mdns_pid)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef _MDNS_H
|
||||
#define _MDNS_H
|
||||
|
||||
extern int mdns_pid;
|
||||
|
||||
void mdns_unregister(void);
|
||||
void mdns_register(void);
|
||||
|
||||
|
||||
@@ -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<nsock; i++) {
|
||||
if (FD_ISSET(sockfd[i], &fds)) {
|
||||
acceptfd = sockfd[i];
|
||||
|
||||
+13
@@ -28,6 +28,7 @@
|
||||
#include <unistd.h>
|
||||
#include <memory.h>
|
||||
#include <openssl/md5.h>
|
||||
#include <sys/wait.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user