From 9894b52b7b49ff6884c202d86e37b2d366ec9c9c Mon Sep 17 00:00:00 2001 From: James Laird Date: Sun, 14 Apr 2013 20:17:40 +1000 Subject: [PATCH] restore '-d' (daemonise) flag --- common.h | 1 + rtsp.c | 8 ++++++++ shairport.c | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common.h b/common.h index f4ec5fbf0..31f8c5ca8 100644 --- a/common.h +++ b/common.h @@ -24,6 +24,7 @@ typedef struct { char *output_name; audio_output *output; int buffer_start_fill; + int daemonise; } shairport_cfg; extern int debuglev; diff --git a/rtsp.c b/rtsp.c index 0169e347f..3625ba656 100644 --- a/rtsp.c +++ b/rtsp.c @@ -758,6 +758,14 @@ void rtsp_listen_loop(void) { mdns_register(); + if (config.daemonise) { + pid_t pid = fork(); + if (pid) { + printf("%d\n", pid); + exit(0); + } + } + printf("Listening for connections.\n"); int acceptfd; diff --git a/shairport.c b/shairport.c index 1138405b2..4ad37b4e0 100644 --- a/shairport.c +++ b/shairport.c @@ -59,6 +59,8 @@ void usage(char *progname) { " -o output set audio output\n" " -b fill set how full the buffer must be before audio output starts\n" " This value is in frames; default %d\n" + " -d fork (daemonise)\n" + " The PID of the child process is written to stdout\n" "Run %s -o -h to find the available options for a specific output\n" "\n", config.buffer_start_fill, progname); @@ -74,13 +76,16 @@ void usage(char *progname) { int parse_options(int argc, char **argv) { int opt; - while ((opt = getopt(argc, argv, "+hvp:a:o:b:")) > 0) { + while ((opt = getopt(argc, argv, "+hdvp:a:o:b:")) > 0) { switch (opt) { default: printf("Unknown argument -%c\n", optopt); case 'h': usage(argv[0]); exit(1); + case 'd': + config.daemonise = 1; + break; case 'v': debuglev++; break;