summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--heartbeatclient.c22
-rw-r--r--openwrt/rhctl/Makefile2
-rwxr-xr-xopenwrt/rhctl/files/heartbeatclient.init14
-rw-r--r--openwrt/rhctl/files/rhctl.config2
-rw-r--r--sig_handler.c4
-rw-r--r--sig_handler.h2
6 files changed, 37 insertions, 9 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)
diff --git a/openwrt/rhctl/Makefile b/openwrt/rhctl/Makefile
index 7071bb1..5a88216 100644
--- a/openwrt/rhctl/Makefile
+++ b/openwrt/rhctl/Makefile
@@ -18,7 +18,7 @@ PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://localhost/
-PKG_MD5SUM:=eb7c44c6c95da63480440799d3f72041
+PKG_MD5SUM:=a09815ee33dd76f43c277ca80a770073
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
diff --git a/openwrt/rhctl/files/heartbeatclient.init b/openwrt/rhctl/files/heartbeatclient.init
index 97f59ce..b201c5e 100755
--- a/openwrt/rhctl/files/heartbeatclient.init
+++ b/openwrt/rhctl/files/heartbeatclient.init
@@ -54,3 +54,17 @@ stop() {
fi
echo "."
}
+
+reset() {
+ echo -n "$DESC: Restarting timeout"
+ if [ -f $PIDFILE ]; then
+ kill -HUP `cat $PIDFILE` > /dev/null 2>&1
+ echo -n " (Ok)"
+ else
+ echo -n " (not running)"
+ fi
+ echo "."
+}
+
+EXTRA_COMMANDS=reset
+EXTRA_HELP=" reset Restart timeout and switch back to master"
diff --git a/openwrt/rhctl/files/rhctl.config b/openwrt/rhctl/files/rhctl.config
index 7d14e51..3245618 100644
--- a/openwrt/rhctl/files/rhctl.config
+++ b/openwrt/rhctl/files/rhctl.config
@@ -30,4 +30,4 @@ config 'heartbeatclient'
option command_sock '/var/run/rhctl/switchctl.sock'
option baudrate '38400'
option device '/dev/ttyHeartbeat'
-
+ option timeout '50'
diff --git a/sig_handler.c b/sig_handler.c
index ca2e18f..1a88ddb 100644
--- a/sig_handler.c
+++ b/sig_handler.c
@@ -48,7 +48,7 @@
static int sig_pipe_fds[2];
-
+int reset_flag;
static void sig_handler(int sig)
{
@@ -127,7 +127,7 @@ int signal_handle()
case SIGINT: log_printf(NOTICE, "SIG-Int caught, exitting"); return_value = 1; break;
case SIGQUIT: log_printf(NOTICE, "SIG-Quit caught, exitting"); return_value = 1; break;
case SIGTERM: log_printf(NOTICE, "SIG-Term caught, exitting"); return_value = 1; break;
- case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); break;
+ case SIGHUP: log_printf(NOTICE, "SIG-Hup caught"); reset_flag = 1; break;
case SIGUSR1: log_printf(NOTICE, "SIG-Usr1 caught"); break;
case SIGUSR2: log_printf(NOTICE, "SIG-Usr2 caught"); break;
default: log_printf(WARNING, "unknown signal %d caught, ignoring", sig); break;
diff --git a/sig_handler.h b/sig_handler.h
index 1995e1a..ddaf131 100644
--- a/sig_handler.h
+++ b/sig_handler.h
@@ -36,6 +36,8 @@
#ifndef UANYTUN_sig_handler_h_INCLUDED
#define UANYTUN_sig_handler_h_INCLUDED
+extern int reset_flag;
+
int signal_init();
int signal_handle();
void signal_stop();