Subject: [PATCH] main/bacula: fix bacula-dir crash (pthread double detach)

From: leso-kn <[email-masked]>
Date: Fri, 1 Apr 2022 02:31:15 +0200

---
 main/bacula/APKBUILD                               |  2 ++
 .../bacula-11.0.6-pthread-double-detach-fix.patch  | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 main/bacula/bacula-11.0.6-pthread-double-detach-fix.patch

diff --git a/main/bacula/APKBUILD b/main/bacula/APKBUILD
index b164ac83fc..ad5bb75a57 100644
--- a/main/bacula/APKBUILD
+++ b/main/bacula/APKBUILD
@@ -21,6 +21,7 @@ source="https://downloads.sourceforge.net/project/$pkgname/$pkgname/$pkgver/$pkg
 	bacula-sd.initd
 	bacula-fd.initd
 	bacula-7.4.0-path-mounted.patch
+	bacula-11.0.6-pthread-double-detach-fix.patch
 	"
 options="!check" #no test suite provided
 
@@ -161,4 +162,5 @@ bb954bb94bffa68ba80872046782a73012487291f019fb8d7ff77fc7f4325e25bee88612b3279b4d
 0505b9a74520af6982d5df4390525976f8e009e641d0acfe8f24b2ec9f155166a65eecbabee9ff70ffe188d523effa64f958acd8f657410b1c002a6d736e8aee  bacula-sd.initd
 91a53cb566cfd91b42a319bd6ff9947047cae187c6ec198767853d1a0253667d6c2c58f0e72ed43a7b9f40b76e705cafde7a1d6ac86577fa0f64f44b031dec11  bacula-fd.initd
 2d3757236aacca421261a8866ff04b5b0151538e1462559bd1240119b1bece1d456acbba9fee86dbc6aaec7af2a52eb2c0b7490c5f371b7deb478731c74342ff  bacula-7.4.0-path-mounted.patch
+e5b6e98e60a3aac9939b5d9a43419961277a6d22b8153c6c73d7571cb2f3ee5601675c9de11e122ceca26c6f3c4c0648f2409689aa3fa11ee230ea0f5f5ba85a  bacula-11.0.6-pthread-double-detach-fix.patch
 "
diff --git a/main/bacula/bacula-11.0.6-pthread-double-detach-fix.patch b/main/bacula/bacula-11.0.6-pthread-double-detach-fix.patch
new file mode 100644
index 0000000000..8853c42f94
--- /dev/null
+++ b/main/bacula/bacula-11.0.6-pthread-double-detach-fix.patch
@@ -0,0 +1,14 @@
+diff --git a/src/dird/ua_server.c b/src/dird/ua_server.c
+index 75342a3bfa..d8d767e81f 100644
+--- a/src/dird/ua_server.c
++++ b/src/dird/ua_server.c
+@@ -126,7 +126,9 @@ static void *handle_UA_client_request(void *arg)
+    JCR *jcr;
+    BSOCK *user = (BSOCK *)arg;
+ 
+-   pthread_detach(pthread_self());
++   // Alpine: We know the thread is already detached (src/lib/workq.c:74).
++   // Detaching it again would crash on musl, so we disable this call
++   // pthread_detach(pthread_self());
+ 
+    jcr = new_control_jcr("-Console-", JT_CONSOLE);
-- 
2.27.0