From b454a2fd6087252d6f6d625e6521deb37b0eb653 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 17 Mar 2016 22:20:16 +0100 Subject: [PATCH] [general] Put back support for platforms without pipe2(), see issue #239 --- configure.ac | 1 + src/cache.c | 10 +++++++++- src/filescanner.c | 8 ++++++++ src/httpd.c | 4 ++++ src/httpd_dacp.c | 4 ++++ src/httpd_streaming.c | 9 +++++++++ src/mpd.c | 8 ++++++++ src/player.c | 8 ++++++++ src/remote_pairing.c | 9 +++++++++ src/spotify.c | 12 ++++++++++++ src/worker.c | 8 ++++++++ 11 files changed, 80 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 5f44d1e1..6b802f2f 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ AC_CHECK_FUNCS(strptime) AC_CHECK_FUNCS(strtok_r) AC_CHECK_FUNCS(timegm) AC_CHECK_FUNCS(euidaccess) +AC_CHECK_FUNCS(pipe2) dnl Large File Support (LFS) AC_SYS_LARGEFILE diff --git a/src/cache.c b/src/cache.c index 895c734b..df0e9ce8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1796,14 +1796,22 @@ cache_init(void) return 0; } +#ifdef HAVE_PIPE2 ret = pipe2(g_exit_pipe, O_CLOEXEC); +#else + ret = pipe(g_exit_pipe); +#endif if (ret < 0) { - DPRINTF(E_LOG, L_CACHE, "Could not create pipe: %s\n", strerror(errno)); + DPRINTF(E_LOG, L_CACHE, "Could not create exit pipe: %s\n", strerror(errno)); goto exit_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(g_cmd_pipe, O_CLOEXEC); +#else + ret = pipe(g_cmd_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_CACHE, "Could not create command pipe: %s\n", strerror(errno)); diff --git a/src/filescanner.c b/src/filescanner.c index 45c961c9..f9e4e035 100644 --- a/src/filescanner.c +++ b/src/filescanner.c @@ -2271,7 +2271,11 @@ filescanner_init(void) return -1; } +#ifdef HAVE_PIPE2 ret = pipe2(exit_pipe, O_CLOEXEC); +#else + ret = pipe(exit_pipe); +#endif if (ret < 0) { DPRINTF(E_FATAL, L_SCAN, "Could not create pipe: %s\n", strerror(errno)); @@ -2292,7 +2296,11 @@ filescanner_init(void) goto ino_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(cmd_pipe, O_CLOEXEC); +#else + ret = pipe(cmd_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_SCAN, "Could not create command pipe: %s\n", strerror(errno)); diff --git a/src/httpd.c b/src/httpd.c index 5d8773c7..3ab6fe61 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -1338,7 +1338,11 @@ httpd_init(void) exitev = event_new(evbase_httpd, exit_efd, EV_READ, exit_cb, NULL); #else +# ifdef HAVE_PIPE2 ret = pipe2(exit_pipe, O_CLOEXEC); +# else + ret = pipe(exit_pipe); +# endif if (ret < 0) { DPRINTF(E_FATAL, L_HTTPD, "Could not create pipe: %s\n", strerror(errno)); diff --git a/src/httpd_dacp.c b/src/httpd_dacp.c index 2edce3f6..adbb30a8 100644 --- a/src/httpd_dacp.c +++ b/src/httpd_dacp.c @@ -2663,7 +2663,11 @@ dacp_init(void) return -1; } #else +# ifdef HAVE_PIPE2 ret = pipe2(update_pipe, O_CLOEXEC); +# else + ret = pipe(update_pipe); +# endif if (ret < 0) { DPRINTF(E_LOG, L_DACP, "Could not create update pipe: %s\n", strerror(errno)); diff --git a/src/httpd_streaming.c b/src/httpd_streaming.c index e3bebedd..5cb83277 100644 --- a/src/httpd_streaming.c +++ b/src/httpd_streaming.c @@ -298,7 +298,16 @@ streaming_init(void) } // Non-blocking because otherwise httpd and player thread may deadlock +#ifdef HAVE_PIPE2 ret = pipe2(streaming_pipe, O_CLOEXEC | O_NONBLOCK); +#else + if ( pipe(streaming_pipe) < 0 || + fcntl(streaming_pipe[0], F_SETFL, O_CLOEXEC | O_NONBLOCK) < 0 || + fcntl(streaming_pipe[1], F_SETFL, O_CLOEXEC | O_NONBLOCK) < 0 ) + ret = -1; + else + ret = 0; +#endif if (ret < 0) { DPRINTF(E_FATAL, L_STREAMING, "Could not create pipe: %s\n", strerror(errno)); diff --git a/src/mpd.c b/src/mpd.c index b8d09ae4..3377cdde 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -4791,14 +4791,22 @@ int mpd_init(void) v6enabled = cfg_getbool(cfg_getsec(cfg, "general"), "ipv6"); +#ifdef HAVE_PIPE2 ret = pipe2(g_exit_pipe, O_CLOEXEC); +#else + ret = pipe(g_exit_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_MPD, "Could not create pipe: %s\n", strerror(errno)); goto exit_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(g_cmd_pipe, O_CLOEXEC); +#else + ret = pipe(g_cmd_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_MPD, "Could not create command pipe: %s\n", strerror(errno)); diff --git a/src/player.c b/src/player.c index a1a50d0a..17bb5e20 100644 --- a/src/player.c +++ b/src/player.c @@ -4655,7 +4655,11 @@ player_init(void) goto audio_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(exit_pipe, O_CLOEXEC); +#else + ret = pipe(exit_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_PLAYER, "Could not create pipe: %s\n", strerror(errno)); @@ -4663,7 +4667,11 @@ player_init(void) goto exit_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(cmd_pipe, O_CLOEXEC); +#else + ret = pipe(cmd_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_PLAYER, "Could not create command pipe: %s\n", strerror(errno)); diff --git a/src/remote_pairing.c b/src/remote_pairing.c index 11ce27b8..f3f935ec 100644 --- a/src/remote_pairing.c +++ b/src/remote_pairing.c @@ -917,7 +917,16 @@ remote_pairing_init(void) return -1; } #else +# ifdef HAVE_PIPE2 ret = pipe2(pairing_pipe, O_CLOEXEC | O_NONBLOCK); +# else + if ( pipe(pairing_pipe) < 0 || + fcntl(pairing_pipe[0], F_SETFL, O_CLOEXEC | O_NONBLOCK) < 0 || + fcntl(pairing_pipe[1], F_SETFL, O_CLOEXEC | O_NONBLOCK) < 0 ) + ret = -1; + else + ret = 0; +# endif if (ret < 0) { DPRINTF(E_FATAL, L_REMOTE, "Could not create pairing pipe: %s\n", strerror(errno)); diff --git a/src/spotify.c b/src/spotify.c index f412a1ef..370ce234 100644 --- a/src/spotify.c +++ b/src/spotify.c @@ -2193,21 +2193,33 @@ spotify_init(void) if (ret < 0) goto assign_fail; +#ifdef HAVE_PIPE2 ret = pipe2(g_exit_pipe, O_CLOEXEC); +#else + ret = pipe(g_exit_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_SPOTIFY, "Could not create pipe: %s\n", strerror(errno)); goto exit_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(g_cmd_pipe, O_CLOEXEC); +#else + ret = pipe(g_cmd_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_SPOTIFY, "Could not create command pipe: %s\n", strerror(errno)); goto cmd_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(g_notify_pipe, O_CLOEXEC); +#else + ret = pipe(g_notify_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_SPOTIFY, "Could not notify command pipe: %s\n", strerror(errno)); diff --git a/src/worker.c b/src/worker.c index 69b4d1aa..502a28d8 100644 --- a/src/worker.c +++ b/src/worker.c @@ -289,14 +289,22 @@ worker_init(void) { int ret; +#ifdef HAVE_PIPE2 ret = pipe2(g_exit_pipe, O_CLOEXEC); +#else + ret = pipe(g_exit_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_MAIN, "Could not create pipe: %s\n", strerror(errno)); goto exit_fail; } +#ifdef HAVE_PIPE2 ret = pipe2(g_cmd_pipe, O_CLOEXEC); +#else + ret = pipe(g_cmd_pipe); +#endif if (ret < 0) { DPRINTF(E_LOG, L_MAIN, "Could not create command pipe: %s\n", strerror(errno));