From 3a07ad842fcae0f59c449082a0aa6fdf06a9ed35 Mon Sep 17 00:00:00 2001 From: Nate Straz Date: Fri, 5 Jan 2007 23:09:14 +0000 Subject: Push processing of the remote command status to main() so it can be reproduced properly by qarsh. Return 127 as an exit code on internal error cases. --- qarsh.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/qarsh.c b/qarsh.c index 28a1429..bcbd68c 100644 --- a/qarsh.c +++ b/qarsh.c @@ -349,20 +349,16 @@ run_remote_cmd(char *cmdline) if (hbeat_getstate(qarsh_hb) == HOST_TIMEOUT) { fprintf(stderr, "Didn't receive heartbeat for %d seconds\n", hbeat_getmaxtimeout(qarsh_hb)); - return 127; + return W_EXITCODE(127, 0); } else if (hbeat_getstate(qarsh_hb) == HOST_REBOOT) { fprintf(stderr, "Remote host rebooted\n"); - return 127; + return W_EXITCODE(127, 0); } if (qp == NULL) { fprintf(stderr, "Remote command exited with unknown state\n"); - return 127; - } - if (WIFSIGNALED(qp->qp_cmdexit.qp_status)) { - rc = 128 + WTERMSIG(qp->qp_cmdexit.qp_status); - } else { - rc = WEXITSTATUS(qp->qp_cmdexit.qp_status); + return W_EXITCODE(127, 0); } + rc = qp->qp_cmdexit.qp_status; qpfree(qp); return rc; } @@ -492,5 +488,10 @@ again: ret = run_remote_cmd(args); close(qarsh_fd); free(args); - return ret; + /* If the remote cmd was killed, we need to be killed too */ + if (WIFSIGNALED(ret)) { + raise(WTERMSIG(ret)); + } + /* Otherwise we need to exit with the same exit status */ + return WEXITSTATUS(ret); } -- cgit