]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/heartbeat.c
FreeBSD fixes; manual updates
[bacula/bacula] / bacula / src / filed / heartbeat.c
index 2cc907f7abb0923789f01927e8f29a6adeb0a42e..bda617ee11b7466b13f381bb2ff8b07b96edb53a 100644 (file)
 #include "bacula.h"
 #include "filed.h"
 
+#ifdef HAVE_CYGWIN
+/* pthread_kill() dies on Cygwin, so disable it */
+#define pthread_kill(x, y)
+/* Use shorter wait interval on Cygwin because no kill */
+#define WAIT_INTERVAL 10
+#else  /* Unix systems */
+#define WAIT_INTERVAL 60
+#endif
+
 /* 
  * Listen on the SD socket for heartbeat signals.
  * Send heartbeats to the Director every HB_TIME
@@ -53,11 +63,12 @@ static void *sd_heartbeat_thread(void *arg)
    jcr->hb_bsock = sd;
 
    /* Hang reading the socket to the SD, and every time we get
-    *  a heartbeat, we simply send it on to the Director to
-    *  keep him alive.
+    *  a heartbeat or we get a wait timeout (1 minute), we
+    *  check to see if we need to send a heartbeat to the
+    *  Directory.
     */
    for ( ; !is_bnet_stop(sd); ) {
-      n = bnet_wait_data_intr(sd, 60);
+      n = bnet_wait_data_intr(sd, WAIT_INTERVAL);
       if (me->heartbeat_interval) {
         now = time(NULL);
         if (now-last_heartbeat >= me->heartbeat_interval) {
@@ -86,19 +97,21 @@ void start_heartbeat_monitor(JCR *jcr)
 /* Terminate the heartbeat thread. Used for both SD and DIR */
 void stop_heartbeat_monitor(JCR *jcr) 
 {
-   /* Wait for heartbeat thread to start */
-   while (jcr->hb_bsock == NULL) {
+   int cnt = 0;
+   /* Wait max 10 secs for heartbeat thread to start */
+   while (jcr->hb_bsock == NULL && cnt++ < 200) {
       bmicrosleep(0, 50);            /* avoid race */
    }
-   jcr->hb_bsock->timed_out = 1;      /* set timed_out to terminate read */
-   jcr->hb_bsock->terminated = 1;     /* set to terminate read */
 
-   /* Wait for heartbeat thread to stop */
-   while (jcr->hb_bsock) {
-#ifndef HAVE_CYGWIN
+   if (jcr->hb_bsock) {
+      jcr->hb_bsock->timed_out = 1;   /* set timed_out to terminate read */
+      jcr->hb_bsock->terminated = 1;  /* set to terminate read */
+   }
+   cnt = 0;
+   /* Wait max 100 secs for heartbeat thread to stop */
+   while (jcr->hb_bsock && cnt++ < 200) {
       /* Naturally, Cygwin 1.3.20 craps out on the following */
       pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */
-#endif
       bmicrosleep(0, 500);
    }
 }