]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Try to avoid segfault with heartbeat
authorEric Bollengier <eric@baculasystems.com>
Thu, 22 Apr 2021 18:23:53 +0000 (20:23 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:01 +0000 (09:03 +0100)
Strange segfault on Redhat 7

[Thread debugging using libthread_db enabled]
$3 = 0x2521158 "bacula-fd"
$7 = 0x7f41dbe8b369 "12.7.6 (22 April 2021)"
$8 = 0x7f41dbe8bb30 "x86_64-redhat-linux-gnu-bacula-enterprise"
$9 = 0x7f41dbe8b354 "redhat"
$10 = 0x7f41dbe8b362 "(Core)"
TestName = regexwhere-test

Thread 4 (Thread 0x7f41d6ed2700 (LWP 4146)):

Thread 3 (Thread 0x7f41d76d3700 (LWP 4163)):

Thread 2 (Thread 0x7f41d64be700 (LWP 4166)):

Attempt to dump locks
Attempt to dump current JCRs. njcrs=1
threadid=0x7f41d76d3700 JobId=6 JobStatus=T jcr=0x7f41cc00f918 name=JobE.2021-04-22_13.07.30_09
        use_count=1 killable=1
        JobType=R JobLevel=
        sched_time=22-Apr-2021 13:07 start_time=22-Apr-2021 13:07
        end_time=31-Dec-1969 19:00 wait_time=31-Dec-1969 19:00
        db=(nil) db_batch=(nil) batch_started=0

bacula/src/filed/heartbeat.c

index e002797dd0029476ed4b88210ded93e3635d019d..0a2267510452de0b0f75763589839cf6e4fc1e40 100644 (file)
@@ -30,8 +30,6 @@
 
 #define WAIT_INTERVAL 5
 
-extern "C" void *sd_heartbeat_thread(void *arg);
-extern "C" void *dir_heartbeat_thread(void *arg);
 extern bool no_signals;
 
 int handle_command(JCR *jcr, BSOCK *sd);
@@ -41,7 +39,7 @@ int handle_command(JCR *jcr, BSOCK *sd);
  * Send heartbeats to the Director every HB_TIME
  *   seconds.
  */
-extern "C" void *sd_heartbeat_thread(void *arg)
+static void *sd_heartbeat_thread(void *arg)
 {
    int32_t n;
    int32_t m;
@@ -158,8 +156,10 @@ void stop_heartbeat_monitor(JCR *jcr)
    }
 
    if (jcr->hb_status == 1) {               /* Mark as started */
-      jcr->hb_bsock->set_timed_out();       /* set timed_out to terminate read */
-      jcr->hb_bsock->set_terminated();      /* set to terminate read */
+      if (jcr->hb_bsock) {
+         jcr->hb_bsock->set_timed_out();       /* set timed_out to terminate read */
+         jcr->hb_bsock->set_terminated();      /* set to terminate read */
+      }
 
       if (jcr->hb_dir_bsock) {
          jcr->hb_dir_bsock->set_timed_out();     /* set timed_out to terminate read */
@@ -183,7 +183,7 @@ void stop_heartbeat_monitor(JCR *jcr)
  *   is no SD monitoring needed -- e.g. restore and verify Vol
  *   both do their own read() on the SD socket.
  */
-extern "C" void *dir_heartbeat_thread(void *arg)
+static void *dir_heartbeat_thread(void *arg)
 {
    JCR *jcr = (JCR *)arg;
    BSOCK *dir;
@@ -194,7 +194,7 @@ extern "C" void *dir_heartbeat_thread(void *arg)
    /* Get our own local copy */
    dir = dup_bsock(jcr->dir_bsock);
 
-   jcr->hb_bsock = dir;
+   jcr->hb_dir_bsock = dir;
    jcr->hb_status = 1;          // Mark as started
    dir->suppress_error_messages(true);
 
@@ -212,7 +212,6 @@ extern "C" void *dir_heartbeat_thread(void *arg)
       bmicrosleep(30, 0);
    }
    dir->close();
-   jcr->hb_bsock = NULL;
    jcr->hb_status = -1;         // Mark as stopped
    return NULL;
 }