]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/heartbeat.c
ebl fix RunScript bug (in some case, After script wasn't launched)
[bacula/bacula] / bacula / src / filed / heartbeat.c
index 93e2bc45431d2ad98ce76b7bed04acdf32cafcae..7a77621610d61c67b9b5b065f3aaff355b4e029f 100644 (file)
@@ -13,7 +13,7 @@
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
-   version 2 as ammended with additional clauses defined in the
+   version 2 as amended with additional clauses defined in the
    file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
@@ -26,7 +26,7 @@
 #include "bacula.h"
 #include "filed.h"
 
-#define WAIT_INTERVAL 10
+#define WAIT_INTERVAL 5
 
 extern "C" void *sd_heartbeat_thread(void *arg);
 extern "C" void *dir_heartbeat_thread(void *arg);
@@ -49,42 +49,37 @@ extern "C" void *sd_heartbeat_thread(void *arg)
 
    /* Get our own local copy */
    sd = dup_bsock(jcr->store_bsock);
-#ifndef WIN32
-   int oflags;
-   if ((oflags = fcntl(sd->fd, F_GETFL, 0)) != -1) {
-      fcntl(sd->fd, F_SETFL, oflags|O_NONBLOCK);
-   }
-#endif
    dir = dup_bsock(jcr->dir_bsock);
 
    jcr->hb_bsock = sd;
    jcr->hb_dir_bsock = dir;
 
    /* Hang reading the socket to the SD, and every time we get
-    *  a heartbeat or we get a wait timeout (1 minute), we
-    *  check to see if we need to send a heartbeat to the
-    *  Director.
+    *   a heartbeat or we get a wait timeout (1 minute), 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);
       if (me->heartbeat_interval) {
-        now = time(NULL);
-        if (now-last_heartbeat >= me->heartbeat_interval) {
-           bnet_sig(dir, BNET_HEARTBEAT);
-           last_heartbeat = now;
-        }
+         now = time(NULL);
+         if (now-last_heartbeat >= me->heartbeat_interval) {
+            bnet_sig(dir, BNET_HEARTBEAT);
+            last_heartbeat = now;
+         }
       }
-      if (is_bnet_stop(sd)) {
-        break;
+      if (n < 0 || is_bnet_stop(sd)) {
+         break;
       }
-      if (n == 1) {                  /* input waiting */
-        bnet_recv(sd);               /* read it -- probably heartbeat from sd */
-        if (sd->msglen <= 0) {
+      if (n == 1) {                   /* input waiting */
+         bnet_recv(sd);               /* read it -- probably heartbeat from sd */
+         if (sd->msglen <= 0) {
             Dmsg1(100, "Got BNET_SIG %d from SD\n", sd->msglen);
-        } else {
+         } else {
             Dmsg2(100, "Got %d bytes from SD. MSG=%s\n", sd->msglen, sd->msg);
-        }
+         }
       }
+      Dmsg2(100, "wait_intr=%d stop=%d\n", n, is_bnet_stop(sd));
    }
    bnet_close(sd);
    bnet_close(dir);
@@ -117,7 +112,7 @@ void stop_heartbeat_monitor(JCR *jcr)
    }
    /* Wait max 10 secs for heartbeat thread to start */
    while (jcr->hb_bsock == NULL && cnt++ < 200) {
-      bmicrosleep(0, 50000);        /* wait for start */
+      bmicrosleep(0, 50000);         /* wait for start */
    }
    if (!jcr->hb_bsock) {
    }
@@ -135,11 +130,9 @@ void stop_heartbeat_monitor(JCR *jcr)
    cnt = 0;
    /* Wait max 100 secs for heartbeat thread to stop */
    while (jcr->hb_bsock && cnt++ < 200) {
-      pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */
+      pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL);  /* make heartbeat thread go away */
       bmicrosleep(0, 500000);
    }
-   if (jcr->hb_bsock) {
-   }
 }
 
 /*
@@ -166,8 +159,8 @@ extern "C" void *dir_heartbeat_thread(void *arg)
       now = time(NULL);
       next = now - last_heartbeat;
       if (next >= me->heartbeat_interval) {
-        bnet_sig(dir, BNET_HEARTBEAT);
-        last_heartbeat = now;
+         bnet_sig(dir, BNET_HEARTBEAT);
+         last_heartbeat = now;
       }
       bmicrosleep(next, 0);
    }