summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2006-01-06 16:42:28 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:45 -0400
commit65794221d4d9890a2536c6bb95301466e9707592 (patch)
treea294437da307cf4b843ed9cbe27393018af2b33b
parentf73014e353921cf45c124383991a59b436145836 (diff)
downloadqarsh-65794221d4d9890a2536c6bb95301466e9707592.zip
qarsh-65794221d4d9890a2536c6bb95301466e9707592.tar.gz
qarsh-65794221d4d9890a2536c6bb95301466e9707592.tar.xz
Reorganized heartbeat state machine to be move explicit.
Don't set last_rhost_btime until after we've checked for a reboot.
-rw-r--r--hbeat.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/hbeat.c b/hbeat.c
index 6242d38..08ec9d1 100644
--- a/hbeat.c
+++ b/hbeat.c
@@ -96,8 +96,33 @@ hbeat(hbeat_t hbh)
hbeat = btime(hbeatp->host);
current_time = time(NULL);
- if (!hbeat) {
- switch (hbeatp->rhost_state) {
+ if (hbeat) { switch(hbeatp->rhost_state) {
+ /* Remote Host is Responding */
+ case HOST_REBOOT:
+ case HOST_TIMEOUT:
+ retval = 0;
+ break;
+ case HOST_QUIET:
+ hbeatp->rhost_state = HOST_ALIVE;
+ hbeatp->start_quiet_time = 0;
+ case HOST_ALIVE:
+ if (hbeatp->last_rhost_btime == 0) {
+ hbeatp->last_rhost_btime = hbeat;
+ retval = 1;
+ } else if (abs(hbeat - hbeatp->last_rhost_btime) > 5) {
+ hbeatp->rhost_state = HOST_REBOOT;
+ retval = 0;
+ } else {
+ hbeatp->last_rhost_btime = hbeat;
+ retval = 1;
+ }
+ break;
+
+ case HOST_HBEAT_DISABLED:
+ retval = 1;
+ break;
+ }} else { switch (hbeatp->rhost_state) {
+ /* Remote Host is NOT Responding */
case HOST_ALIVE:
hbeatp->rhost_state = HOST_QUIET;
hbeatp->start_quiet_time = time(NULL);
@@ -122,24 +147,7 @@ hbeat(hbeat_t hbh)
case HOST_HBEAT_DISABLED:
retval = 1;
break;
- }
- }
-
- if (hbeat) {
- if (hbeatp->rhost_state == HOST_REBOOT) {
- retval = 0;
- } else {
- hbeatp->last_rhost_btime = hbeat;
- hbeatp->rhost_state = HOST_ALIVE;
- hbeatp->start_quiet_time = 0;
- retval = 1;
-
- if (abs(hbeat - hbeatp->last_rhost_btime) > 5) {
- hbeatp->rhost_state = HOST_REBOOT;
- retval = 0;
- }
- }
- }
+ }}
return retval;
}