summaryrefslogtreecommitdiff
path: root/heartbeatclient.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2010-01-10 15:43:12 (GMT)
committerChristian Pointner <equinox@helsinki.at>2010-01-10 15:43:12 (GMT)
commit475ead22df9433e3a7f41fa88190984a10f86144 (patch)
treebb054ba546993db59d9f9293d8a5ab746ecc36e1 /heartbeatclient.c
parent51af8e19e9ad47539038f04012f4202f2dbb6b9a (diff)
heartbeatclient works now
Diffstat (limited to 'heartbeatclient.c')
-rw-r--r--heartbeatclient.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/heartbeatclient.c b/heartbeatclient.c
index 26e198e..f95c335 100644
--- a/heartbeatclient.c
+++ b/heartbeatclient.c
@@ -73,8 +73,6 @@ int process_serial(read_buffer_t* buffer, int serial_fd, u_int32_t* time)
if(strlen(buffer->buf)) {
log_printf(INFO, "heartbeat: '%s'", buffer->buf);
-
- // reset heartbeat cnt
*time = 0;
}
@@ -110,7 +108,7 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
max_fd = (max_fd < sig_fd) ? sig_fd : max_fd;
int return_value = 0;
- return_value = send_string(cmd_fd, "type heartbeat");
+ return_value = send_string(cmd_fd, "type heartbeat\n");
if(return_value <= 0) {
log_printf(ERROR, "error setting client type");
return_value = -1;
@@ -120,6 +118,7 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
return_value = 0;
}
+ int active = 1;
read_buffer_t serial_buffer;
serial_buffer.offset = 0;
struct timeval timeout;
@@ -138,10 +137,15 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
if(ret == -1)
continue;
if(!ret) {
+ if(active == 0)
+ continue;
+
time++;
if(time >= opt->timeout_) {
- log_printf(WARNING, "timeout reached");
- // call handler for timeout
+ log_printf(WARNING, "timeout reached, switching to standby");
+ send_string(cmd_fd, "mode standby\n");
+ active = 0;
+ log_printf(WARNING, "deactivated timeout");
time = 0;
}
continue;
@@ -151,6 +155,14 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
if(signal_handle())
return_value = 1;
+ if(reset_flag) {
+ active = 1;
+ time = 0;
+ reset_flag = 0;
+ log_printf(NOTICE, "reactivated timeout, switching to master");
+ send_string(cmd_fd, "mode master\n");
+ }
+
if(FD_ISSET(serial_fd, &tmpfds)) {
return_value = process_serial(&serial_buffer, serial_fd, &time);
if(return_value)