Skip to content

Commit

Permalink
restore '-d' (daemonise) flag
Browse files Browse the repository at this point in the history
  • Loading branch information
abrasive committed Apr 14, 2013
1 parent a9c4087 commit 9894b52
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef struct {
char *output_name;
audio_output *output;
int buffer_start_fill;
int daemonise;
} shairport_cfg;

extern int debuglev;
Expand Down
8 changes: 8 additions & 0 deletions rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion shairport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <output> -h to find the available options for a specific output\n"
"\n", config.buffer_start_fill, progname);

Expand All @@ -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;
Expand Down

0 comments on commit 9894b52

Please sign in to comment.