From e12d7ad23ee3c40b61c31543737dd1b929e08a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krause?= Date: Thu, 28 May 2015 09:10:59 +0200 Subject: [PATCH 1/2] Fix segfault with musl libc shairport-sync crashes on musl libc when accessing the `statistics` array in `player_thread_func()`. This array is quite large (60128 bytes) and the data for this thread exceed the the default stack size on musl libc of 80k [1]. Safe and portable programs should not depend upon the default stack limit, but instead, explicitly allocate enough stack for each thread by using the pthread_attr_setstacksize routine [2]. So, lets set the stack size for the `player_thread` to 128k. A follow-up patch may set the stack sizes for the other threads, too. The difficulty here is to decide how much memory to allocate for the stack. [1] http://wiki.musl-libc.org/wiki/Functional_differences_from_glibc#Thread_stack_size [2] https://computing.llnl.gov/tutorials/pthreads/#Stack --- player.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/player.c b/player.c index fcca3487..561c3f22 100644 --- a/player.c +++ b/player.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "config.h" @@ -1104,7 +1105,15 @@ int player_play(stream_cfg *stream) { if (rc) debug(1,"Error initialising condition variable."); config.output->start(sampling_rate); - pthread_create(&player_thread, NULL, player_thread_func, NULL); + + size_t size = (PTHREAD_STACK_MIN + 128 * 1024); + pthread_attr_t tattr; + pthread_attr_init(&tattr); + rc = pthread_attr_setstacksize(&tattr, size); + if (rc) + debug(1, "Error setting stack size for player_thread: %s", strerror(errno)); + pthread_create(&player_thread, &tattr, player_thread_func, NULL); + pthread_attr_destroy(&tattr); return 0; } From 8a122426c654ce87568b6be78af7e66df4a1b4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krause?= Date: Thu, 28 May 2015 09:54:46 +0200 Subject: [PATCH 2/2] Fix redirection of incorrect system headers The POSIX correct header include is `` [1] and `` The glibc silently redirects these incorrect includes, musl libc prints a warning: #warning redirecting incorrect #include to #warning redirecting incorrect #include to [1] http://pubs.opengroup.org/onlinepubs/7908799/xsh/poll.h.html [2] http://pubs.opengroup.org/onlinepubs/7908799/xsh/signal.h.html --- player.c | 2 +- rtsp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/player.c b/player.c index 561c3f22..3b28eee2 100644 --- a/player.c +++ b/player.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/rtsp.c b/rtsp.c index 91e0728e..379662a2 100644 --- a/rtsp.c +++ b/rtsp.c @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include "config.h"