aboutsummaryrefslogtreecommitdiffstats
path: root/community/bareos/pthread-double-detach.patch
blob: b0fca51e8dae78567847a2365dfb7cfe2a7a9322 (plain)
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
--- old/core/src/dird/job.cc
+++ new/core/src/dird/job.cc
@@ -455,7 +455,16 @@
 {
    JobControlRecord *jcr = (JobControlRecord *)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");
--- old/core/src/dird/ua_server.cc
+++ new/core/src/dird/ua_server.cc
@@ -77,7 +77,15 @@
  */
 void *HandleUserAgentClientRequest(BareosSocket *user_agent_socket)
 {
-   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());
+   }
 
    JobControlRecord *jcr = new_control_jcr("-Console-", JT_CONSOLE);