diff --git a/lib/fencing/st_output.c b/lib/fencing/st_output.c index e0ff848c2f..eb10ad0c54 100644 --- a/lib/fencing/st_output.c +++ b/lib/fencing/st_output.c @@ -1,572 +1,571 @@ /* * Copyright 2019-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include #include #include #include #include #include #include #include #include #include #include static char * time_t_string(time_t when) { crm_time_t *crm_when = crm_time_new(NULL); char *buf = NULL; crm_time_set_timet(crm_when, &when); buf = crm_time_as_string(crm_when, crm_time_log_date | crm_time_log_timeofday | crm_time_log_with_timezone); crm_time_free(crm_when); return buf; } /*! * \internal * \brief Return a status-friendly description of fence history entry state * * \param[in] history Fence history entry to describe * * \return One-word description of history entry state * \note This is similar to stonith_op_state_str() except user-oriented (i.e. * for cluster status) instead of developer-oriented (for debug logs). */ static const char * state_str(stonith_history_t *history) { switch (history->state) { case st_failed: return "failed"; case st_done: return "successful"; default: return "pending"; } } /*! * \internal * \brief Create a description of a fencing history entry for status displays * * \param[in] history Fencing history entry to describe * \param[in] full_history Whether this is for full or condensed history * \param[in] later_succeeded Node that a later equivalent attempt succeeded * from, or NULL if none * \param[in] show_opts Flag group of pcmk_show_opt_e * * \return Newly created string with fencing history entry description * * \note The caller is responsible for freeing the return value with g_free(). * \note This is similar to stonith__event_description(), except this is used * for history entries (stonith_history_t) in status displays rather than * event notifications (stonith_event_t) in log messages. */ gchar * stonith__history_description(stonith_history_t *history, bool full_history, const char *later_succeeded, uint32_t show_opts) { GString *str = g_string_sized_new(256); // Generous starting size char *retval = NULL; char *completed_time = NULL; if ((history->state == st_failed) || (history->state == st_done)) { completed_time = time_t_string(history->completed); } g_string_printf(str, "%s of %s", stonith_action_str(history->action), history->target); if (!pcmk_is_set(show_opts, pcmk_show_failed_detail)) { // More human-friendly if (((history->state == st_failed) || (history->state == st_done)) && (history->delegate != NULL)) { g_string_append_printf(str, " by %s", history->delegate); } g_string_append_printf(str, " for %s@%s", history->client, history->origin); if (!full_history) { g_string_append(str, " last"); // For example, "last failed at ..." } } g_string_append_printf(str, " %s", state_str(history)); // For failed actions, add exit reason if available if ((history->state == st_failed) && (history->exit_reason != NULL)) { g_string_append_printf(str, " (%s)", history->exit_reason); } if (pcmk_is_set(show_opts, pcmk_show_failed_detail)) { // More technical g_string_append(str, ": "); // For completed actions, add delegate if available if (((history->state == st_failed) || (history->state == st_done)) && (history->delegate != NULL)) { g_string_append_printf(str, "delegate=%s, ", history->delegate); } // Add information about originator g_string_append_printf(str, "client=%s, origin=%s", history->client, history->origin); // For completed actions, add completion time if (completed_time != NULL) { if (full_history) { g_string_append(str, ", completed"); } else if (history->state == st_failed) { g_string_append(str, ", last-failed"); } else { g_string_append(str, ", last-successful"); } g_string_append_printf(str, "='%s'", completed_time); } } else { // More human-friendly if (completed_time != NULL) { g_string_append_printf(str, " at %s", completed_time); } } if ((history->state == st_failed) && (later_succeeded != NULL)) { g_string_append_printf(str, " (a later attempt from %s succeeded)", later_succeeded); } retval = str->str; g_string_free(str, FALSE); free(completed_time); return retval; } PCMK__OUTPUT_ARGS("failed-fencing-list", "stonith_history_t *", "GList *", "uint32_t", "uint32_t", "gboolean") int stonith__failed_history(pcmk__output_t *out, va_list args) { stonith_history_t *history = va_arg(args, stonith_history_t *); GList *only_node = va_arg(args, GList *); uint32_t section_opts = va_arg(args, uint32_t); uint32_t show_opts = va_arg(args, uint32_t); gboolean print_spacer = va_arg(args, gboolean); int rc = pcmk_rc_no_output; for (stonith_history_t *hp = history; hp; hp = hp->next) { if (hp->state != st_failed) { continue; } if (!pcmk__str_in_list(hp->target, only_node, pcmk__str_star_matches|pcmk__str_casei)) { continue; } PCMK__OUTPUT_LIST_HEADER(out, print_spacer, rc, "Failed Fencing Actions"); out->message(out, "stonith-event", hp, pcmk_all_flags_set(section_opts, pcmk_section_fencing_all), stonith__later_succeeded(hp, history), show_opts); out->increment_list(out); } PCMK__OUTPUT_LIST_FOOTER(out, rc); return rc; } PCMK__OUTPUT_ARGS("fencing-list", "stonith_history_t *", "GList *", "uint32_t", "uint32_t", "gboolean") int stonith__history(pcmk__output_t *out, va_list args) { stonith_history_t *history = va_arg(args, stonith_history_t *); GList *only_node = va_arg(args, GList *); uint32_t section_opts = va_arg(args, uint32_t); uint32_t show_opts = va_arg(args, uint32_t); gboolean print_spacer = va_arg(args, gboolean); int rc = pcmk_rc_no_output; for (stonith_history_t *hp = history; hp; hp = hp->next) { if (!pcmk__str_in_list(hp->target, only_node, pcmk__str_star_matches|pcmk__str_casei)) { continue; } if (hp->state != st_failed) { PCMK__OUTPUT_LIST_HEADER(out, print_spacer, rc, "Fencing History"); out->message(out, "stonith-event", hp, pcmk_all_flags_set(section_opts, pcmk_section_fencing_all), stonith__later_succeeded(hp, history), show_opts); out->increment_list(out); } } PCMK__OUTPUT_LIST_FOOTER(out, rc); return rc; } PCMK__OUTPUT_ARGS("full-fencing-list", "crm_exit_t", "stonith_history_t *", "GList *", "uint32_t", "uint32_t", "gboolean") int stonith__full_history(pcmk__output_t *out, va_list args) { crm_exit_t history_rc G_GNUC_UNUSED = va_arg(args, crm_exit_t); stonith_history_t *history = va_arg(args, stonith_history_t *); GList *only_node = va_arg(args, GList *); uint32_t section_opts = va_arg(args, uint32_t); uint32_t show_opts = va_arg(args, uint32_t); gboolean print_spacer = va_arg(args, gboolean); int rc = pcmk_rc_no_output; for (stonith_history_t *hp = history; hp; hp = hp->next) { if (!pcmk__str_in_list(hp->target, only_node, pcmk__str_star_matches|pcmk__str_casei)) { continue; } PCMK__OUTPUT_LIST_HEADER(out, print_spacer, rc, "Fencing History"); out->message(out, "stonith-event", hp, pcmk_all_flags_set(section_opts, pcmk_section_fencing_all), stonith__later_succeeded(hp, history), show_opts); out->increment_list(out); } PCMK__OUTPUT_LIST_FOOTER(out, rc); return rc; } PCMK__OUTPUT_ARGS("full-fencing-list", "crm_exit_t", "stonith_history_t *", "GList *", "uint32_t", "uint32_t", "gboolean") static int full_history_xml(pcmk__output_t *out, va_list args) { crm_exit_t history_rc = va_arg(args, crm_exit_t); stonith_history_t *history = va_arg(args, stonith_history_t *); GList *only_node = va_arg(args, GList *); uint32_t section_opts = va_arg(args, uint32_t); uint32_t show_opts = va_arg(args, uint32_t); gboolean print_spacer G_GNUC_UNUSED = va_arg(args, gboolean); int rc = pcmk_rc_no_output; if (history_rc == 0) { for (stonith_history_t *hp = history; hp; hp = hp->next) { if (!pcmk__str_in_list(hp->target, only_node, pcmk__str_star_matches|pcmk__str_casei)) { continue; } PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Fencing History"); out->message(out, "stonith-event", hp, pcmk_all_flags_set(section_opts, pcmk_section_fencing_all), stonith__later_succeeded(hp, history), show_opts); out->increment_list(out); } PCMK__OUTPUT_LIST_FOOTER(out, rc); } else { char *rc_s = pcmk__itoa(history_rc); pcmk__output_create_xml_node(out, "fence_history", "status", rc_s, NULL); free(rc_s); rc = pcmk_rc_ok; } return rc; } PCMK__OUTPUT_ARGS("last-fenced", "const char *", "time_t") static int last_fenced_html(pcmk__output_t *out, va_list args) { const char *target = va_arg(args, const char *); time_t when = va_arg(args, time_t); if (when) { char *buf = crm_strdup_printf("Node %s last fenced at: %s", target, ctime(&when)); pcmk__output_create_html_node(out, "div", NULL, NULL, buf); free(buf); return pcmk_rc_ok; } else { return pcmk_rc_no_output; } } PCMK__OUTPUT_ARGS("last-fenced", "const char *", "time_t") static int last_fenced_text(pcmk__output_t *out, va_list args) { const char *target = va_arg(args, const char *); time_t when = va_arg(args, time_t); if (when) { pcmk__indented_printf(out, "Node %s last fenced at: %s", target, ctime(&when)); } else { pcmk__indented_printf(out, "Node %s has never been fenced\n", target); } return pcmk_rc_ok; } PCMK__OUTPUT_ARGS("last-fenced", "const char *", "time_t") static int last_fenced_xml(pcmk__output_t *out, va_list args) { const char *target = va_arg(args, const char *); time_t when = va_arg(args, time_t); if (when) { char *buf = time_t_string(when); pcmk__output_create_xml_node(out, "last-fenced", "target", target, "when", buf, NULL); free(buf); return pcmk_rc_ok; } else { return pcmk_rc_no_output; } } PCMK__OUTPUT_ARGS("pending-fencing-list", "stonith_history_t *", "GList *", "uint32_t", "uint32_t", "gboolean") int stonith__pending_actions(pcmk__output_t *out, va_list args) { stonith_history_t *history = va_arg(args, stonith_history_t *); GList *only_node = va_arg(args, GList *); uint32_t section_opts = va_arg(args, uint32_t); uint32_t show_opts = va_arg(args, uint32_t); gboolean print_spacer = va_arg(args, gboolean); int rc = pcmk_rc_no_output; for (stonith_history_t *hp = history; hp; hp = hp->next) { if (!pcmk__str_in_list(hp->target, only_node, pcmk__str_star_matches|pcmk__str_casei)) { continue; } /* Skip the rest of the history after we see a failed/done action */ if ((hp->state == st_failed) || (hp->state == st_done)) { break; } PCMK__OUTPUT_LIST_HEADER(out, print_spacer, rc, "Pending Fencing Actions"); out->message(out, "stonith-event", hp, pcmk_all_flags_set(section_opts, pcmk_section_fencing_all), stonith__later_succeeded(hp, history), show_opts); out->increment_list(out); } PCMK__OUTPUT_LIST_FOOTER(out, rc); return rc; } PCMK__OUTPUT_ARGS("stonith-event", "stonith_history_t *", "int", "const char *", "uint32_t") static int stonith_event_html(pcmk__output_t *out, va_list args) { stonith_history_t *event = va_arg(args, stonith_history_t *); int full_history = va_arg(args, int); const char *succeeded = va_arg(args, const char *); uint32_t show_opts = va_arg(args, uint32_t); gchar *desc = stonith__history_description(event, full_history, succeeded, show_opts); switch(event->state) { case st_done: out->list_item(out, "successful-stonith-event", "%s", desc); break; case st_failed: out->list_item(out, "failed-stonith-event", "%s", desc); break; default: out->list_item(out, "pending-stonith-event", "%s", desc); break; } g_free(desc); return pcmk_rc_ok; } PCMK__OUTPUT_ARGS("stonith-event", "stonith_history_t *", "int", "const char *", "uint32_t") static int stonith_event_text(pcmk__output_t *out, va_list args) { stonith_history_t *event = va_arg(args, stonith_history_t *); int full_history = va_arg(args, int); const char *succeeded = va_arg(args, const char *); uint32_t show_opts = va_arg(args, uint32_t); gchar *desc = stonith__history_description(event, full_history, succeeded, show_opts); pcmk__indented_printf(out, "%s\n", desc); g_free(desc); return pcmk_rc_ok; } PCMK__OUTPUT_ARGS("stonith-event", "stonith_history_t *", "int", "const char *", "uint32_t") static int stonith_event_xml(pcmk__output_t *out, va_list args) { stonith_history_t *event = va_arg(args, stonith_history_t *); int full_history G_GNUC_UNUSED = va_arg(args, int); const char *succeeded G_GNUC_UNUSED = va_arg(args, const char *); uint32_t show_opts G_GNUC_UNUSED = va_arg(args, uint32_t); char *buf = NULL; xmlNodePtr node = pcmk__output_create_xml_node(out, "fence_event", "action", event->action, "target", event->target, "client", event->client, "origin", event->origin, NULL); switch (event->state) { case st_failed: pcmk__xe_set_props(node, "status", "failed", XML_LRM_ATTR_EXIT_REASON, event->exit_reason, NULL); break; case st_done: crm_xml_add(node, "status", "success"); break; default: { char *state = pcmk__itoa(event->state); pcmk__xe_set_props(node, "status", "pending", "extended-status", state, NULL); free(state); break; } } if (event->delegate != NULL) { crm_xml_add(node, "delegate", event->delegate); } if (event->state == st_failed || event->state == st_done) { buf = time_t_string(event->completed); crm_xml_add(node, "completed", buf); free(buf); } return pcmk_rc_ok; } PCMK__OUTPUT_ARGS("validate", "const char *", "const char *", "char *", "char *", "int") static int validate_agent_html(pcmk__output_t *out, va_list args) { const char *agent = va_arg(args, const char *); const char *device = va_arg(args, const char *); char *output = va_arg(args, char *); char *error_output = va_arg(args, char *); int rc = va_arg(args, int); if (device) { char *buf = crm_strdup_printf("Validation of %s on %s %s", agent, device, rc ? "failed" : "succeeded"); pcmk__output_create_html_node(out, "div", NULL, NULL, buf); free(buf); } else { char *buf = crm_strdup_printf("Validation of %s %s", agent, rc ? "failed" : "succeeded"); pcmk__output_create_html_node(out, "div", NULL, NULL, buf); free(buf); } out->subprocess_output(out, rc, output, error_output); return rc; } PCMK__OUTPUT_ARGS("validate", "const char *", "const char *", "char *", "char *", "int") static int validate_agent_text(pcmk__output_t *out, va_list args) { const char *agent = va_arg(args, const char *); const char *device = va_arg(args, const char *); char *output = va_arg(args, char *); char *error_output = va_arg(args, char *); int rc = va_arg(args, int); if (device) { pcmk__indented_printf(out, "Validation of %s on %s %s\n", agent, device, rc ? "failed" : "succeeded"); } else { pcmk__indented_printf(out, "Validation of %s %s\n", agent, rc ? "failed" : "succeeded"); } out->subprocess_output(out, rc, output, error_output); return rc; } PCMK__OUTPUT_ARGS("validate", "const char *", "const char *", "char *", "char *", "int") static int validate_agent_xml(pcmk__output_t *out, va_list args) { const char *agent = va_arg(args, const char *); const char *device = va_arg(args, const char *); char *output = va_arg(args, char *); char *error_output = va_arg(args, char *); int rc = va_arg(args, int); - xmlNodePtr node = pcmk__output_create_xml_node(out, "validate", - "agent", agent, - "valid", pcmk__btoa(rc), - NULL); + xmlNodePtr node = pcmk__output_create_xml_node( + out, "validate", "agent", agent, "valid", pcmk__btoa(rc == pcmk_ok), + NULL); if (device != NULL) { crm_xml_add(node, "device", device); } pcmk__output_xml_push_parent(out, node); out->subprocess_output(out, rc, output, error_output); pcmk__output_xml_pop_parent(out); return rc; } static pcmk__message_entry_t fmt_functions[] = { { "failed-fencing-list", "default", stonith__failed_history }, { "fencing-list", "default", stonith__history }, { "full-fencing-list", "default", stonith__full_history }, { "full-fencing-list", "xml", full_history_xml }, { "last-fenced", "html", last_fenced_html }, { "last-fenced", "log", last_fenced_text }, { "last-fenced", "text", last_fenced_text }, { "last-fenced", "xml", last_fenced_xml }, { "pending-fencing-list", "default", stonith__pending_actions }, { "stonith-event", "html", stonith_event_html }, { "stonith-event", "log", stonith_event_text }, { "stonith-event", "text", stonith_event_text }, { "stonith-event", "xml", stonith_event_xml }, { "validate", "html", validate_agent_html }, { "validate", "log", validate_agent_text }, { "validate", "text", validate_agent_text }, { "validate", "xml", validate_agent_xml }, { NULL, NULL, NULL } }; void stonith__register_messages(pcmk__output_t *out) { pcmk__register_messages(out, fmt_functions); } diff --git a/lib/fencing/st_rhcs.c b/lib/fencing/st_rhcs.c index 39485013eb..029c97eeaa 100644 --- a/lib/fencing/st_rhcs.c +++ b/lib/fencing/st_rhcs.c @@ -1,318 +1,318 @@ /* * Copyright 2004-2022 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include #include #include #include #include #include #include #include #include "fencing_private.h" #define RH_STONITH_PREFIX "fence_" /*! * \internal * \brief Add available RHCS-compatible agents to a list * * \param[in,out] List to add to * * \return Number of agents added */ int stonith__list_rhcs_agents(stonith_key_value_t **devices) { // Essentially: ls -1 @sbin_dir@/fence_* int count = 0, i; struct dirent **namelist; const int file_num = scandir(PCMK__FENCE_BINDIR, &namelist, 0, alphasort); #if _POSIX_C_SOURCE < 200809L && !(defined(O_SEARCH) || defined(O_PATH)) char buffer[FILENAME_MAX + 1]; #elif defined(O_SEARCH) const int dirfd = open(PCMK__FENCE_BINDIR, O_SEARCH); #else const int dirfd = open(PCMK__FENCE_BINDIR, O_PATH); #endif for (i = 0; i < file_num; i++) { struct stat prop; if (pcmk__starts_with(namelist[i]->d_name, RH_STONITH_PREFIX)) { #if _POSIX_C_SOURCE < 200809L && !(defined(O_SEARCH) || defined(O_PATH)) snprintf(buffer, sizeof(buffer), "%s/%s", PCMK__FENCE_BINDIR, namelist[i]->d_name); if (stat(buffer, &prop) == 0 && S_ISREG(prop.st_mode)) { #else if (dirfd == -1) { if (i == 0) { crm_notice("Problem with listing %s directory" CRM_XS "errno=%d", RH_STONITH_PREFIX, errno); } free(namelist[i]); continue; } /* note: we can possibly prevent following symlinks here, which may be a good idea, but fall on the nose when these agents are moved elsewhere & linked back */ if (fstatat(dirfd, namelist[i]->d_name, &prop, 0) == 0 && S_ISREG(prop.st_mode)) { #endif *devices = stonith_key_value_add(*devices, NULL, namelist[i]->d_name); count++; } } free(namelist[i]); } if (file_num > 0) { free(namelist); } #if _POSIX_C_SOURCE >= 200809L || defined(O_SEARCH) || defined(O_PATH) if (dirfd >= 0) { close(dirfd); } #endif return count; } static void stonith_rhcs_parameter_not_required(xmlNode *metadata, const char *parameter) { char *xpath = NULL; xmlXPathObject *xpathObj = NULL; CRM_CHECK(metadata != NULL, return); CRM_CHECK(parameter != NULL, return); xpath = crm_strdup_printf("//parameter[@name='%s']", parameter); /* Fudge metadata so that the parameter isn't required in config * Pacemaker handles and adds it */ xpathObj = xpath_search(metadata, xpath); if (numXpathResults(xpathObj) > 0) { xmlNode *tmp = getXpathResult(xpathObj, 0); crm_xml_add(tmp, "required", "0"); } freeXpathObject(xpathObj); free(xpath); } /*! * \brief Execute RHCS-compatible agent's meta-data action * * \param[in] agent Agent to execute * \param[in] timeout Action timeout * \param[out] metadata Where to store output xmlNode (or NULL to ignore) * * \todo timeout is currently ignored; shouldn't we use it? */ static int stonith__rhcs_get_metadata(const char *agent, int timeout, xmlNode **metadata) { xmlNode *xml = NULL; xmlNode *actions = NULL; xmlXPathObject *xpathObj = NULL; pcmk__action_result_t *result = NULL; stonith_action_t *action = stonith_action_create(agent, "metadata", NULL, 0, 5, NULL, NULL, NULL); int rc = stonith__execute(action); + result = stonith__action_result(action); - if (rc < 0) { + if (rc < 0 && result == NULL) { crm_warn("Could not execute metadata action for %s: %s " CRM_XS " rc=%d", agent, pcmk_strerror(rc), rc); stonith__destroy_action(action); return rc; } - result = stonith__action_result(action); - if (result->execution_status != PCMK_EXEC_DONE) { crm_warn("Could not execute metadata action for %s: %s", agent, pcmk_exec_status_str(result->execution_status)); rc = pcmk_rc2legacy(stonith__result2rc(result)); stonith__destroy_action(action); return rc; } if (!pcmk__result_ok(result)) { crm_warn("Metadata action for %s returned error code %d", agent, result->exit_status); rc = pcmk_rc2legacy(stonith__result2rc(result)); stonith__destroy_action(action); return rc; } if (result->action_stdout == NULL) { crm_warn("Metadata action for %s returned no data", agent); stonith__destroy_action(action); return -ENODATA; } xml = string2xml(result->action_stdout); stonith__destroy_action(action); if (xml == NULL) { crm_warn("Metadata for %s is invalid", agent); return -pcmk_err_schema_validation; } xpathObj = xpath_search(xml, "//actions"); if (numXpathResults(xpathObj) > 0) { actions = getXpathResult(xpathObj, 0); } freeXpathObject(xpathObj); // Add start and stop (implemented by pacemaker, not agent) to meta-data xpathObj = xpath_search(xml, "//action[@name='stop']"); if (numXpathResults(xpathObj) <= 0) { xmlNode *tmp = NULL; tmp = create_xml_node(actions, "action"); crm_xml_add(tmp, "name", "stop"); crm_xml_add(tmp, "timeout", CRM_DEFAULT_OP_TIMEOUT_S); tmp = create_xml_node(actions, "action"); crm_xml_add(tmp, "name", "start"); crm_xml_add(tmp, "timeout", CRM_DEFAULT_OP_TIMEOUT_S); } freeXpathObject(xpathObj); // Fudge metadata so parameters are not required in config (pacemaker adds them) stonith_rhcs_parameter_not_required(xml, "action"); stonith_rhcs_parameter_not_required(xml, "plug"); stonith_rhcs_parameter_not_required(xml, "port"); if (metadata) { *metadata = xml; } else { free_xml(xml); } return pcmk_ok; } /*! * \brief Execute RHCS-compatible agent's meta-data action * * \param[in] agent Agent to execute * \param[in] timeout Action timeout * \param[out] output Where to store action output (or NULL to ignore) * * \todo timeout is currently ignored; shouldn't we use it? */ int stonith__rhcs_metadata(const char *agent, int timeout, char **output) { char *buffer = NULL; xmlNode *xml = NULL; int rc = stonith__rhcs_get_metadata(agent, timeout, &xml); if (rc != pcmk_ok) { free_xml(xml); return rc; } buffer = dump_xml_formatted_with_text(xml); free_xml(xml); if (buffer == NULL) { return -pcmk_err_schema_validation; } if (output) { *output = buffer; } else { free(buffer); } return pcmk_ok; } bool stonith__agent_is_rhcs(const char *agent) { struct stat prop; char *buffer = crm_strdup_printf(PCMK__FENCE_BINDIR "/%s", agent); int rc = stat(buffer, &prop); free(buffer); return (rc >= 0) && S_ISREG(prop.st_mode); } int stonith__rhcs_validate(stonith_t *st, int call_options, const char *target, const char *agent, GHashTable *params, const char * host_arg, int timeout, char **output, char **error_output) { int rc = pcmk_ok; int remaining_timeout = timeout; xmlNode *metadata = NULL; stonith_action_t *action = NULL; + pcmk__action_result_t *result = NULL; if (host_arg == NULL) { time_t start_time = time(NULL); rc = stonith__rhcs_get_metadata(agent, remaining_timeout, &metadata); if (rc == pcmk_ok) { uint32_t device_flags = 0; stonith__device_parameter_flags(&device_flags, agent, metadata); if (pcmk_is_set(device_flags, st_device_supports_parameter_port)) { host_arg = "port"; } else if (pcmk_is_set(device_flags, st_device_supports_parameter_plug)) { host_arg = "plug"; } } free_xml(metadata); remaining_timeout -= time(NULL) - start_time; if (rc == -ETIME || remaining_timeout <= 0 ) { return -ETIME; } } else if (pcmk__str_eq(host_arg, PCMK__VALUE_NONE, pcmk__str_casei)) { host_arg = NULL; } action = stonith_action_create(agent, "validate-all", target, 0, remaining_timeout, params, NULL, host_arg); rc = stonith__execute(action); - if (rc == pcmk_ok) { - pcmk__action_result_t *result = stonith__action_result(action); + result = stonith__action_result(action); + if (result != NULL) { rc = pcmk_rc2legacy(stonith__result2rc(result)); // Take ownership of output so stonith__destroy_action() doesn't free it if (output != NULL) { *output = result->action_stdout; result->action_stdout = NULL; } if (error_output != NULL) { *error_output = result->action_stderr; result->action_stderr = NULL; } } stonith__destroy_action(action); return rc; }