2 * Bacula File Daemon heartbeat routines
3 * Listens for heartbeats coming from the SD
4 * If configured, sends heartbeats to Dir
6 * Kern Sibbald, May MMIII
12 Copyright (C) 2000-2003 Kern Sibbald and John Walker
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of
17 the License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public
25 License along with this program; if not, write to the Free
26 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 * Listen on the SD socket for heartbeat signals.
36 * Send heartbeats to the Director every HB_TIME
39 static void *heartbeat_thread(void *arg)
42 JCR *jcr = (JCR *)arg;
44 time_t last_heartbeat = time(NULL);
47 pthread_detach(pthread_self());
49 /* Get our own local copy */
50 sd = dup_bsock(jcr->store_bsock);
51 dir = dup_bsock(jcr->dir_bsock);
55 /* Hang reading the socket to the SD, and every time we get
56 * a heartbeat, we simply send it on to the Director to
59 for ( ; !is_bnet_stop(sd); ) {
60 n = bnet_wait_data_intr(sd, 60);
61 if (me->heartbeat_interval) {
63 if (now-last_heartbeat >= me->heartbeat_interval) {
64 bnet_sig(dir, BNET_HEARTBEAT);
68 if (n == 1) { /* input waiting */
69 bnet_recv(sd); /* read it -- probably heartbeat from sd */
70 /* Dmsg1(000, "Got %d from SD\n", sd->msglen); */
79 /* Startup the heartbeat thread -- see above */
80 void start_heartbeat_monitor(JCR *jcr)
83 pthread_create(&jcr->heartbeat_id, NULL, heartbeat_thread, (void *)jcr);
86 /* Terminate the heartbeat thread */
87 void stop_heartbeat_monitor(JCR *jcr)
89 /* Wait for heartbeat thread to start */
90 while (jcr->duped_sd == NULL) {
91 bmicrosleep(0, 50); /* avoid race */
93 jcr->duped_sd->timed_out = 1; /* set timed_out to terminate read */
94 jcr->duped_sd->terminated = 1; /* set to terminate read */
96 /* Wait for heartbeat thread to stop */
97 while (jcr->duped_sd) {
98 pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */
104 * Same as above but we don't listen to the SD
106 void start_dir_heartbeat(JCR *jcr)
108 /* ***FIXME*** implement */
111 void stop_dir_heartbeat(JCR *jcr)
113 /* ***FIXME*** implement */