From 9355015b3c20cf251e8bf6efd141338ca2e660fb Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 20 Sep 2016 22:17:04 +0200 Subject: [PATCH 1/4] [main] Use waitpid instead of obsolete wait3 --- src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 4d24f96c..3c0f07dd 100644 --- a/src/main.c +++ b/src/main.c @@ -346,9 +346,9 @@ signal_signalfd_cb(int fd, short event, void *arg) switch (info.ssi_signo) { case SIGCHLD: - DPRINTF(E_LOG, L_MAIN, "Got SIGCHLD, reaping children\n"); + DPRINTF(E_LOG, L_MAIN, "Got SIGCHLD\n"); - while (wait3(&status, WNOHANG, NULL) > 0) + while (waitpid(-1, &status, WNOHANG) > 0) /* Nothing. */ ; break; @@ -391,9 +391,9 @@ signal_kqueue_cb(int fd, short event, void *arg) switch (ke.ident) { case SIGCHLD: - DPRINTF(E_LOG, L_MAIN, "Got SIGCHLD, reaping children\n"); + DPRINTF(E_LOG, L_MAIN, "Got SIGCHLD\n"); - while (wait3(&status, WNOHANG, NULL) > 0) + while (waitpid(-1, &status, WNOHANG) > 0) /* Nothing. */ ; break; From f202b5d2e9157aaed1457d7932020ec4710a4189 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 20 Sep 2016 22:17:29 +0200 Subject: [PATCH 2/4] [pulseaudio] Try to spawn Pulseaudio if it doesn't by itself Requiring the user to set up Pulseaudio in system mode is not optimal. This would, however, be required especially on headless systems. This is the sledgehammer alternative to starting Pulseaudio. --- src/outputs/pulse.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/outputs/pulse.c b/src/outputs/pulse.c index 9e3d0182..acee452a 100644 --- a/src/outputs/pulse.c +++ b/src/outputs/pulse.c @@ -806,7 +806,26 @@ pulse_init(void) if (pa_context_connect(p->context, NULL, 0, NULL) < 0) { ret = pa_context_errno(p->context); - goto fail; + if (ret == PA_ERR_CONNECTIONREFUSED) + { + DPRINTF(E_LOG, L_LAUDIO, "Connection to Pulseaudio refused, trying to start daemon for our user\n"); + + ret = system("pulseaudio --start"); + if (ret < 0) + { + DPRINTF(E_LOG, L_LAUDIO, "Could not start Pulseaudio\n"); + return -1; + } + } + + // Try connecting again + if (pa_context_connect(p->context, NULL, 0, NULL) < 0) + { + ret = pa_context_errno(p->context); + goto fail; + } + + DPRINTF(E_LOG, L_LAUDIO, "Connection to Pulseaudio established\n"); } pa_threaded_mainloop_lock(p->mainloop); From 1af24044decea94a68de3e20df4ab774532f31f6 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Tue, 20 Sep 2016 22:23:36 +0200 Subject: [PATCH 3/4] [docs] Update README with simplified Pulseaudio instructions --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d9eb7e25..96becaa8 100644 --- a/README.md +++ b/README.md @@ -229,11 +229,8 @@ If you select Pulseaudio, the "card" setting in the config file has no effect. Instead all soundcards detected by Pulseaudio will be listed as speakers by forked-daapd. -There is some one-time setup required to use Pulseaudio: - - Add the forked-daapd user (probably "daapd") to the "pulse-access" group. - - On non-desktop/headless systems, you will need to run Pulseaudio in system - mode. For this, you will probably want to install a SystemD .service file - (Google will help you), so Pulseaudio automatically starts at boot. +There is some one-time setup required to use Pulseaudio: Add the forked-daapd +user (probably "daapd") to the "pulse-access" group. ## MP3 network streaming (streaming to iOS) From ac9900ff1a91717afd2cd55228c1eb903bf27a27 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Mon, 26 Sep 2016 20:48:00 +0200 Subject: [PATCH 4/4] [pulseaudio] Modification of f202b5d: Now always try to start Pulseaudio --- src/outputs/pulse.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/outputs/pulse.c b/src/outputs/pulse.c index acee452a..3c5dbad9 100644 --- a/src/outputs/pulse.c +++ b/src/outputs/pulse.c @@ -786,6 +786,16 @@ pulse_init(void) if (type && (strcasecmp(type, "pulseaudio") != 0)) return -1; + // In some situations Pulseaudio won't autospawn, and we don't want to trouble + // the user with setting up system mode (which isn't recommended anyway), so + // we use this sledgehammer approach + ret = system("pulseaudio --start"); + if (ret < 0) + { + DPRINTF(E_LOG, L_LAUDIO, "Could not start Pulseaudio\n"); + return -1; + } + ret = 0; if (!(p->mainloop = pa_threaded_mainloop_new())) @@ -806,26 +816,7 @@ pulse_init(void) if (pa_context_connect(p->context, NULL, 0, NULL) < 0) { ret = pa_context_errno(p->context); - if (ret == PA_ERR_CONNECTIONREFUSED) - { - DPRINTF(E_LOG, L_LAUDIO, "Connection to Pulseaudio refused, trying to start daemon for our user\n"); - - ret = system("pulseaudio --start"); - if (ret < 0) - { - DPRINTF(E_LOG, L_LAUDIO, "Could not start Pulseaudio\n"); - return -1; - } - } - - // Try connecting again - if (pa_context_connect(p->context, NULL, 0, NULL) < 0) - { - ret = pa_context_errno(p->context); - goto fail; - } - - DPRINTF(E_LOG, L_LAUDIO, "Connection to Pulseaudio established\n"); + goto fail; } pa_threaded_mainloop_lock(p->mainloop);