]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/heartbeat.c
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / filed / heartbeat.c
index b27e8998b94105d3e20c61343af37e2fbf3ba5b5..783bfb24be492f7e823dd29f539a9c24e09a2177 100644 (file)
@@ -1,29 +1,21 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2003-2008 Free Software Foundation Europe e.V.
-
-   The main author of Bacula is Kern Sibbald, with contributions from
-   many others, a complete list can be found in the file AUTHORS.
-   This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version three of the GNU Affero General Public
-   License as published by the Free Software Foundation and included
-   in the file LICENSE.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU Affero General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-   Bacula® is a registered trademark of Kern Sibbald.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2015 Kern Sibbald
+   Copyright (C) 2003-2014 Free Software Foundation Europe e.V.
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
  *  Bacula File Daemon heartbeat routines
@@ -32,8 +24,6 @@
  *
  *    Kern Sibbald, May MMIII
  *
- *   Version $Id$
- *
  */
 
 #include "bacula.h"
@@ -67,36 +57,48 @@ extern "C" void *sd_heartbeat_thread(void *arg)
    jcr->hb_bsock = sd;
    jcr->hb_started = true;
    jcr->hb_dir_bsock = dir;
+   dir->suppress_error_messages(true);
+   sd->suppress_error_messages(true);
 
    /* Hang reading the socket to the SD, and every time we get
-    *   a heartbeat or we get a wait timeout (1 minute), we
+    *   a heartbeat or we get a wait timeout (5 seconds), we
     *   check to see if we need to send a heartbeat to the
     *   Director.
     */
-   for ( ; !is_bnet_stop(sd); ) {
-      n = bnet_wait_data_intr(sd, WAIT_INTERVAL);
+   while (!sd->is_stop()) {
+      n = sd->wait_data_intr(WAIT_INTERVAL);
+      if (n < 0 || sd->is_stop()) {
+         break;
+      }
       if (me->heartbeat_interval) {
          now = time(NULL);
          if (now-last_heartbeat >= me->heartbeat_interval) {
-            bnet_sig(dir, BNET_HEARTBEAT);
+            dir->signal(BNET_HEARTBEAT);
+            if (dir->is_stop()) {
+               break;
+            }
             last_heartbeat = now;
          }
       }
-      if (n < 0 || is_bnet_stop(sd)) {
-         break;
-      }
-      if (n == 1) {                   /* input waiting */
-         sd->recv();                  /* read it -- probably heartbeat from sd */
+      if (n == 1) {               /* input waiting */
+         sd->recv();              /* read it -- probably heartbeat from sd */
+         if (sd->is_stop()) {
+            break;
+         }
          if (sd->msglen <= 0) {
             Dmsg1(100, "Got BNET_SIG %d from SD\n", sd->msglen);
          } else {
             Dmsg2(100, "Got %d bytes from SD. MSG=%s\n", sd->msglen, sd->msg);
          }
       }
-      Dmsg2(200, "wait_intr=%d stop=%d\n", n, is_bnet_stop(sd));
+      Dmsg2(200, "wait_intr=%d stop=%d\n", n, sd->is_stop());
    }
-   sd->close();
-   dir->close();
+   /*
+    * Note, since sd and dir are local dupped sockets, this
+    *  is one place where we can call destroy().
+    */
+   sd->destroy();
+   dir->destroy();
    jcr->hb_bsock = NULL;
    jcr->hb_started = false;
    jcr->hb_dir_bsock = NULL;
@@ -111,7 +113,7 @@ void start_heartbeat_monitor(JCR *jcr)
     * it gives a constant stream of TIMEOUT_SIGNAL signals that
     * make debugging impossible.
     */
-   if (!no_signals) {
+   if (!no_signals && (me->heartbeat_interval > 0)) {
       jcr->hb_bsock = NULL;
       jcr->hb_started = false;
       jcr->hb_dir_bsock = NULL;
@@ -170,19 +172,27 @@ extern "C" void *dir_heartbeat_thread(void *arg)
 
    jcr->hb_bsock = dir;
    jcr->hb_started = true;
+   dir->suppress_error_messages(true);
 
-   for ( ; !is_bnet_stop(dir); ) {
+   while (!dir->is_stop()) {
       time_t now, next;
 
       now = time(NULL);
       next = now - last_heartbeat;
       if (next >= me->heartbeat_interval) {
          dir->signal(BNET_HEARTBEAT);
+         if (dir->is_stop()) {
+            break;
+         }
          last_heartbeat = now;
       }
+      /* This should never happen, but it might ... */
+      if (next <= 0) {
+         next = 1;
+      }
       bmicrosleep(next, 0);
    }
-   dir->close();
+   dir->destroy();
    jcr->hb_bsock = NULL;
    jcr->hb_started = false;
    return NULL;
@@ -193,7 +203,7 @@ extern "C" void *dir_heartbeat_thread(void *arg)
  */
 void start_dir_heartbeat(JCR *jcr)
 {
-   if (me->heartbeat_interval) {
+   if (!no_signals && (me->heartbeat_interval > 0)) {
       jcr->dir_bsock->set_locking();
       pthread_create(&jcr->heartbeat_id, NULL, dir_heartbeat_thread, (void *)jcr);
    }
@@ -201,7 +211,7 @@ void start_dir_heartbeat(JCR *jcr)
 
 void stop_dir_heartbeat(JCR *jcr)
 {
-   if (me->heartbeat_interval) {
+   if (me->heartbeat_interval > 0) {
       stop_heartbeat_monitor(jcr);
    }
 }