summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qarsh.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/qarsh.c b/qarsh.c
index b593a70..ba32243 100644
--- a/qarsh.c
+++ b/qarsh.c
@@ -87,7 +87,7 @@ sig_handler(int sig)
void
sig_alrm_handler(int sig)
{
- fprintf(stderr, "No heartbeat from remote host\n");
+ fprintf(stderr, "Could not connect to remote host\n");
exit(1);
}
@@ -230,6 +230,7 @@ run_remote_cmd(char *cmdline)
buf = malloc(1024);
memset(buf, 0, 1024);
+ hbeat(qarsh_hb);
cmd_finished = 0;
for (;;) {
if (cmd_finished) {
@@ -247,7 +248,6 @@ run_remote_cmd(char *cmdline)
if (nset == 0) {
if (!hbeat(qarsh_hb)) {
- fprintf(stderr, "No heartbeat from remote host\n");
/* Set our return packet as NULL so we exit
* with unknown error. */
qp = NULL;
@@ -328,9 +328,17 @@ run_remote_cmd(char *cmdline)
}
if (c_out) close(c_out);
if (c_err) close(c_err);
+ free(buf);
+ if (hbeat_getstate(qarsh_hb) == HOST_TIMEOUT) {
+ fprintf(stderr, "Didn't receive heartbeat for %d seconds\n",
+ hbeat_getmaxtimeout(qarsh_hb));
+ return 127;
+ } else if (hbeat_getstate(qarsh_hb) == HOST_REBOOT) {
+ fprintf(stderr, "Remote host rebooted\n");
+ return 127;
+ }
if (qp == NULL) {
fprintf(stderr, "Remote command exited with unknown state\n");
- free(buf);
return 127;
}
if (WIFSIGNALED(qp->qp_cmdexit.qp_status)) {
@@ -339,7 +347,6 @@ run_remote_cmd(char *cmdline)
rc = WEXITSTATUS(qp->qp_cmdexit.qp_status);
}
qpfree(qp);
- free(buf);
return rc;
}