Cherry-pick the following to fix crashes when pausing playback. This makes the shairport_sync rc.d daemon survive.
OK? From 57af5f3c10c54947cf160fe46a580cf40669d412 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist <an...@basename.se> Date: Fri, 3 Dec 2021 20:45:51 +0100 Subject: [PATCH] avoid recursive mutex acquisition in sndio backend Ending a RTSP session while running on OpenBSD using sndio backend causes the following crash: #0 thrkill () #1 0x000005208224403e in _libc_abort #2 0x00000520821b77be in _rthread_mutex_trylock #3 _rthread_mutex_timedlock #4 0x0000051e0d54e2c0 in stop () #5 0x0000051e0d544e85 in player_thread_cleanup_handler #6 0x0000052082243126 in _libc_pthread_exit #7 0x000005209a158700 in sigthr_handler #8 <signal handler called> #9 _thread_sys_poll () #10 0x000005208223533e in _libc_poll_cancel #11 0x00000520df54c9a0 in sio_psleep #12 0x00000520df54cc1f in sio_write #13 0x0000051e0d54e27a in play #14 0x0000051e0d547fc0 in player_thread_func #15 0x000005209a158cc1 in _rthread_start #16 0x000005208223565a in __tfork_thread The player thread is blocking inside sio_write() -> poll(2) while the thread is being terminated. The stop routine tied to the same backend is invoked through player_thread_cleanup_handler() which tries to acquire the mutex which it already acquired before invoking sio_write(). Avoiding blocking writes would require switching to async I/O which is quite an undertaking. The fact that there's only one `struct sio_hdl *' instance in the compilation unit sort of implies there can only be one player thread at a time. Therefore fix the crash by only trying to acquire the mutex and continue as usual if it's already acquired. --- audio_sndio.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) Index: Makefile =================================================================== RCS file: /cvs/ports/audio/shairport-sync/Makefile,v diff -u -p -r1.3 Makefile --- Makefile 5 Oct 2022 14:54:23 -0000 1.3 +++ Makefile 21 Jan 2024 16:06:02 -0000 @@ -3,7 +3,12 @@ COMMENT = AirPlay audio player GH_ACCOUNT = mikebrady GH_PROJECT = shairport-sync GH_TAGNAME = 3.3.9 -REVISION = 1 +REVISION = 2 + +SITES.fix = https://github.com/mikebrady/shairport-sync/commit/ +# "avoid recursive mutex acquisition in sndio backend" to fix crash on pause +PATCHFILES.fix = 57af5f3c10c54947cf160fe46a580cf40669d412.patch +PATCH_DIST_STRIP = -p1 CATEGORIES = audio Index: distinfo =================================================================== RCS file: /cvs/ports/audio/shairport-sync/distinfo,v diff -u -p -r1.1.1.1 distinfo --- distinfo 27 Apr 2022 02:19:25 -0000 1.1.1.1 +++ distinfo 21 Jan 2024 16:06:07 -0000 @@ -1,2 +1,4 @@ +SHA256 (57af5f3c10c54947cf160fe46a580cf40669d412.patch) = oXgaUppVX6sT9ZLReDyLZ9pRxB/s43puBLDsvSlmsWQ= SHA256 (shairport-sync-3.3.9.tar.gz) = F5kMsmIFUcqgehw7NxiJ5VgDBx6q2gTpWMNWVHp+F5U= +SIZE (57af5f3c10c54947cf160fe46a580cf40669d412.patch) = 2421 SIZE (shairport-sync-3.3.9.tar.gz) = 426827