File bug-962309_pacemaker-fencing-remap-agent-error-codes.patch of Package pacemaker.3577
commit 25326b1a3819adc0cf963f70c256ee775fa7ec5f
Author: Ken Gaillot <kgaillot@redhat.com>
Date: Tue Jan 5 11:56:22 2016 -0600
Fix: fencing, libfencing: remap fence agent error codes before async callback
Previously, stonithd's st_child_done() remapped fence agent exit codes
based on error output. However, since 3dd3d01, stderr is not provided
to callbacks, so this was no longer effective. Now, the remapping is done
in libfencing before calling the callback.
diff --git a/fencing/commands.c b/fencing/commands.c
index a81a251..e933404 100644
--- a/fencing/commands.c
+++ b/fencing/commands.c
@@ -1975,22 +1975,6 @@ st_child_done(GPid pid, int rc, const char *output, gpointer user_data)
goto done;
}
- if (rc > 0) {
- /* Try to provide _something_ useful */
- if(output == NULL) {
- rc = -ENODATA;
-
- } else if(strstr(output, "imed out")) {
- rc = -ETIMEDOUT;
-
- } else if(strstr(output, "Unrecognised action")) {
- rc = -EOPNOTSUPP;
-
- } else {
- rc = -pcmk_err_generic;
- }
- }
-
stonith_send_async_reply(cmd, output, rc, pid);
if (rc != 0) {
diff --git a/lib/fencing/st_client.c b/lib/fencing/st_client.c
index a150e92..33c58b7 100644
--- a/lib/fencing/st_client.c
+++ b/lib/fencing/st_client.c
@@ -783,6 +783,9 @@ stonith_action_async_done(mainloop_child_t * p, pid_t pid, int core, int signo,
action->timer_sigkill = 0;
}
+ action->output = read_output(action->fd_stdout);
+ action->error = read_output(action->fd_stderr);
+
if (action->last_timeout_signo) {
action->rc = -ETIME;
crm_notice("Child process %d performing action '%s' timed out with signal %d",
@@ -794,13 +797,28 @@ stonith_action_async_done(mainloop_child_t * p, pid_t pid, int core, int signo,
pid, action->action, signo);
} else {
- action->rc = exitcode;
crm_debug("Child process %d performing action '%s' exited with rc %d",
pid, action->action, exitcode);
- }
+ if (exitcode > 0) {
+ /* Try to provide a useful error code based on the fence agent's
+ * error output.
+ */
+ if (action->error == NULL) {
+ exitcode = -ENODATA;
- action->output = read_output(action->fd_stdout);
- action->error = read_output(action->fd_stderr);
+ } else if (strstr(action->error, "imed out")) {
+ /* Some agents have their own internal timeouts */
+ exitcode = -ETIMEDOUT;
+
+ } else if (strstr(action->error, "Unrecognised action")) {
+ exitcode = -EOPNOTSUPP;
+
+ } else {
+ exitcode = -pcmk_err_generic;
+ }
+ }
+ action->rc = exitcode;
+ }
log_action(action, pid);