From: Eric Bollengier Date: Thu, 22 Apr 2021 18:23:53 +0000 (+0200) Subject: Try to avoid segfault with heartbeat X-Git-Tag: Release-11.3.2~567 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3b173f4b89008462bfba1e288f70666a0535814;p=thirdparty%2Fbacula.git Try to avoid segfault with heartbeat 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 --- diff --git a/bacula/src/filed/heartbeat.c b/bacula/src/filed/heartbeat.c index e002797dd..0a2267510 100644 --- a/bacula/src/filed/heartbeat.c +++ b/bacula/src/filed/heartbeat.c @@ -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; }