From 783d600a100fe2be707adc3b2d74f63456f1ee4d Mon Sep 17 00:00:00 2001 From: Klemens Nanni Date: Wed, 31 Jan 2024 05:01:55 +0100 Subject: [PATCH] Fix crash on double pthread_cancel(3) on exit On OpenBSD 7.4-current, failure to listen on the RTSP socket(s) results the `rtsp_listener_thread` being pthread_cancel(3)'ed twice, once through `rtsp_listen_loop()` and again via atexit(3) handler `exit_rtsp_listener()`: ``` $ nc -4l 5000 & $ nc -6l 5000 & $ shairport-sync -c/dev/null warning: could not establish a service on port 5000 -- program terminating. Is another instance of Shairport Sync running on this device? Segmentation fault (core dumped) ``` ``` Program terminated with signal SIGSEGV, Segmentation fault. 433 if (tib->tib_canceled == 0 && tid != 0 && [Current thread is 1 (process 290061)] ``` `die()` -> `exit(EXIT_FAILURE)` normally in this case, thus forgoing the first cancel and relying on the atexit handler alone. With Mike Brady. --- rtsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtsp.c b/rtsp.c index ee8f2971e..3d6c5f48b 100644 --- a/rtsp.c +++ b/rtsp.c @@ -5694,7 +5694,7 @@ void *rtsp_listen_loop(__attribute((unused)) void *arg) { } while (1); pthread_cleanup_pop(1); // should never happen } else { - warn("could not establish a service on port %d -- program terminating. Is another instance of " + die("could not establish a service on port %d -- program terminating. Is another instance of " "Shairport Sync running on this device?", config.port); }