From 4e36181a109b6fe18fa7f248fca4d6b62b497072 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 9 Jun 2014 17:39:26 +0200 Subject: [PATCH] Fix Bacula to work with newer Windows pthreads library --- bacula/src/dird/backup.c | 4 ++-- bacula/src/dird/job.c | 2 +- bacula/src/dird/mac.c | 8 ++++---- bacula/src/dird/msgchan.c | 9 +++++---- bacula/src/dird/restore.c | 4 ++-- bacula/src/dird/vbackup.c | 4 ++-- bacula/src/jcr.h | 1 + 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 6492e1e34e..25728b2c98 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -783,7 +783,7 @@ void backup_cleanup(JCR *jcr, int TermCode) msg_type = M_ERROR; /* Generate error message */ if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } @@ -792,7 +792,7 @@ void backup_cleanup(JCR *jcr, int TermCode) term_msg = _("Backup Canceled"); if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 96f4ead6e2..fa667d40db 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -358,7 +358,7 @@ void sd_msg_thread_send_signal(JCR *jcr, int sig) { jcr->lock(); if ( !jcr->sd_msg_thread_done - && jcr->SD_msg_chan + && jcr->SD_msg_chan_started && !pthread_equal(jcr->SD_msg_chan, pthread_self())) { Dmsg1(800, "Send kill to SD msg chan jid=%d\n", jcr->JobId); diff --git a/bacula/src/dird/mac.c b/bacula/src/dird/mac.c index 49de6df01e..6483011839 100644 --- a/bacula/src/dird/mac.c +++ b/bacula/src/dird/mac.c @@ -739,13 +739,13 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode) msg_type = M_ERROR; /* Generate error message */ if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } if (wjcr->store_bsock) { wjcr->store_bsock->signal(BNET_TERMINATE); - if (wjcr->SD_msg_chan) { + if (wjcr->SD_msg_chan_started) { pthread_cancel(wjcr->SD_msg_chan); } } @@ -754,13 +754,13 @@ void mac_cleanup(JCR *jcr, int TermCode, int writeTermCode) term_msg = _("%s Canceled"); if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } if (wjcr->store_bsock) { wjcr->store_bsock->signal(BNET_TERMINATE); - if (wjcr->SD_msg_chan) { + if (wjcr->SD_msg_chan_started) { pthread_cancel(wjcr->SD_msg_chan); } } diff --git a/bacula/src/dird/msgchan.c b/bacula/src/dird/msgchan.c index c012e2cee5..7ea6359152 100644 --- a/bacula/src/dird/msgchan.c +++ b/bacula/src/dird/msgchan.c @@ -368,14 +368,14 @@ bool start_storage_daemon_message_thread(JCR *jcr) jcr->inc_use_count(); /* mark in use by msg thread */ jcr->sd_msg_thread_done = false; - jcr->SD_msg_chan = 0; + jcr->SD_msg_chan_started = false; Dmsg0(150, "Start SD msg_thread.\n"); if ((status=pthread_create(&thid, NULL, msg_thread, (void *)jcr)) != 0) { berrno be; Jmsg1(jcr, M_ABORT, 0, _("Cannot create message thread: %s\n"), be.bstrerror(status)); } /* Wait for thread to start */ - while (jcr->SD_msg_chan == 0) { + while (!jcr->SD_msg_chan_started) { bmicrosleep(0, 50); if (job_canceled(jcr) || jcr->sd_msg_thread_done) { return false; @@ -391,7 +391,7 @@ extern "C" void msg_thread_cleanup(void *arg) db_end_transaction(jcr, jcr->db); /* terminate any open transaction */ jcr->lock(); jcr->sd_msg_thread_done = true; - jcr->SD_msg_chan = 0; + jcr->SD_msg_chan_started = false; jcr->unlock(); pthread_cond_broadcast(&jcr->term_wait); /* wakeup any waiting threads */ Dmsg2(100, "=== End msg_thread. JobId=%d usecnt=%d\n", jcr->JobId, jcr->use_count()); @@ -417,6 +417,7 @@ extern "C" void *msg_thread(void *arg) pthread_detach(pthread_self()); set_jcr_in_tsd(jcr); jcr->SD_msg_chan = pthread_self(); + jcr->SD_msg_chan_started = true; pthread_cleanup_push(msg_thread_cleanup, arg); sd = jcr->store_bsock; @@ -472,7 +473,7 @@ void wait_for_storage_daemon_termination(JCR *jcr) pthread_cond_timedwait(&jcr->term_wait, &mutex, &timeout); V(mutex); if (jcr->is_canceled()) { - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { jcr->store_bsock->set_timed_out(); jcr->store_bsock->set_terminated(); sd_msg_thread_send_signal(jcr, TIMEOUT_SIGNAL); diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index 3c11120e73..99bffc6706 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -595,7 +595,7 @@ void restore_cleanup(JCR *jcr, int TermCode) msg_type = M_ERROR; /* Generate error message */ if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } @@ -604,7 +604,7 @@ void restore_cleanup(JCR *jcr, int TermCode) term_msg = _("Restore Canceled"); if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index 8430c74dfd..64d69bb66f 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -392,7 +392,7 @@ void vbackup_cleanup(JCR *jcr, int TermCode) msg_type = M_ERROR; /* Generate error message */ if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } @@ -401,7 +401,7 @@ void vbackup_cleanup(JCR *jcr, int TermCode) term_msg = _("Backup Canceled"); if (jcr->store_bsock) { jcr->store_bsock->signal(BNET_TERMINATE); - if (jcr->SD_msg_chan) { + if (jcr->SD_msg_chan_started) { pthread_cancel(jcr->SD_msg_chan); } } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 5ffc1421a0..ef56593014 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -349,6 +349,7 @@ public: int32_t SDVersion; /* Storage daemon version number */ int64_t spool_size; /* Spool size for this job */ volatile bool sd_msg_thread_done; /* Set when Storage message thread done */ + bool SD_msg_chan_started; /* Set if message thread started */ bool wasVirtualFull; /* set if job was VirtualFull */ bool IgnoreDuplicateJobChecking; /* set in migration jobs */ bool spool_data; /* Spool data in SD */ -- 2.39.5