aboutsummaryrefslogtreecommitdiffstats
path: root/community/bareos/pthread-double-detach.patch
blob: e43f806bee1a0574669e26331888b5a6b38edaa1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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");