]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fix crash on double pthread_cancel(3) on exit 1800/head
authorKlemens Nanni <kn@openbsd.org>
Wed, 31 Jan 2024 04:01:55 +0000 (05:01 +0100)
committerKlemens Nanni <kn@openbsd.org>
Thu, 1 Feb 2024 17:35:35 +0000 (18:35 +0100)
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

diff --git a/rtsp.c b/rtsp.c
index ee8f2971e9cc1fc57e2078b017d1c0f457f6c125..3d6c5f48b634f68c5545eb336b6a0326c1111af1 100644 (file)
--- 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);
   }