aboutsummaryrefslogtreecommitdiffstats
path: root/community/bareos/pthread-double-detach.patch
diff options
context:
space:
mode:
Diffstat (limited to 'community/bareos/pthread-double-detach.patch')
-rw-r--r--community/bareos/pthread-double-detach.patch43
1 files changed, 43 insertions, 0 deletions
diff --git a/community/bareos/pthread-double-detach.patch b/community/bareos/pthread-double-detach.patch
new file mode 100644
index 0000000000..e43f806bee
--- /dev/null
+++ b/community/bareos/pthread-double-detach.patch
@@ -0,0 +1,43 @@
+This patch fixes a double pthread_detach(), which is undefined behaviour
+and leads to a segfault when running with musl libc.
+Until this issue is fixed upstream this patch is needed.
+
+--- a/src/dird/ua_server.c
++++ b/src/dird/ua_server.c
+@@ -73,7 +73,15 @@
+ UAContext *ua;
+ JCR *jcr;
+
+- pthread_detach(pthread_self());
++ /* only detach if not yet detached */
++ int _detachstate;
++ pthread_attr_t _gattr;
++ pthread_getattr_np(pthread_self(), &_gattr);
++ pthread_attr_getdetachstate(&_gattr, &_detachstate);
++ pthread_attr_destroy(&_gattr);
++ if(_detachstate != PTHREAD_CREATE_DETACHED) {
++ pthread_detach(pthread_self());
++ }
+
+ jcr = new_control_jcr("-Console-", JT_CONSOLE);
+
+--- a/src/dird/job.c
++++ b/src/dird/job.c
+@@ -420,7 +420,16 @@
+ {
+ JCR *jcr = (JCR *)arg;
+
+- pthread_detach(pthread_self());
++ /* only detach if not yet detached */
++ int _detachstate;
++ pthread_attr_t _gattr;
++ pthread_getattr_np(pthread_self(), &_gattr);
++ pthread_attr_getdetachstate(&_gattr, &_detachstate);
++ pthread_attr_destroy(&_gattr);
++ if(_detachstate != PTHREAD_CREATE_DETACHED) {
++ pthread_detach(pthread_self());
++ }
++
+ Dsm_check(100);
+
+ Dmsg0(200, "=====Start Job=========\n");