109fe2
From a2305469012b5fe3713427412c12459085ed61a1 Mon Sep 17 00:00:00 2001
109fe2
From: Ken Gaillot <kgaillot@redhat.com>
109fe2
Date: Tue, 12 Dec 2017 10:02:22 -0600
109fe2
Subject: [PATCH] Fix: tools: crm_resource --cleanup with no resource specified
109fe2
109fe2
7a813755 failed to completely fix --cleanup without --resource
109fe2
---
109fe2
 tools/crm_resource_runtime.c | 20 ++++++++++++--------
109fe2
 1 file changed, 12 insertions(+), 8 deletions(-)
109fe2
109fe2
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
109fe2
index bdebb0b..79f8b98 100644
109fe2
--- a/tools/crm_resource_runtime.c
109fe2
+++ b/tools/crm_resource_runtime.c
109fe2
@@ -569,6 +569,7 @@ clear_rsc_failures(crm_ipc_t *crmd_channel, const char *node_name,
109fe2
 {
109fe2
     int rc = pcmk_ok;
109fe2
     const char *failed_value = NULL;
109fe2
+    const char *failed_id = NULL;
109fe2
     const char *interval_ms_str = NULL;
109fe2
     GHashTable *rscs = NULL;
109fe2
     GHashTableIter iter;
109fe2
@@ -587,11 +588,14 @@ clear_rsc_failures(crm_ipc_t *crmd_channel, const char *node_name,
109fe2
     for (xmlNode *xml_op = __xml_first_child(data_set->failed); xml_op != NULL;
109fe2
          xml_op = __xml_next(xml_op)) {
109fe2
 
109fe2
+        failed_id = crm_element_value(xml_op, XML_LRM_ATTR_RSCID);
109fe2
+        if (failed_id == NULL) {
109fe2
+            // Malformed history entry, should never happen
109fe2
+            continue;
109fe2
+        }
109fe2
+
109fe2
         // No resource specified means all resources match
109fe2
-        failed_value = crm_element_value(xml_op, XML_LRM_ATTR_RSCID);
109fe2
-        if (rsc_id == NULL) {
109fe2
-            rsc_id = failed_value;
109fe2
-        } else if (safe_str_neq(rsc_id, failed_value)) {
109fe2
+        if (rsc_id && safe_str_neq(rsc_id, failed_id)) {
109fe2
             continue;
109fe2
         }
109fe2
 
109fe2
@@ -615,13 +619,13 @@ clear_rsc_failures(crm_ipc_t *crmd_channel, const char *node_name,
109fe2
             }
109fe2
         }
109fe2
 
109fe2
-        g_hash_table_add(rscs, (gpointer) rsc_id);
109fe2
+        g_hash_table_add(rscs, (gpointer) failed_id);
109fe2
     }
109fe2
 
109fe2
     g_hash_table_iter_init(&iter, rscs);
109fe2
-    while (g_hash_table_iter_next(&iter, (gpointer *) &rsc_id, NULL)) {
109fe2
-        crm_debug("Erasing failures of %s on %s", rsc_id, node_name);
109fe2
-        rc = clear_rsc_history(crmd_channel, node_name, rsc_id, data_set);
109fe2
+    while (g_hash_table_iter_next(&iter, (gpointer *) &failed_id, NULL)) {
109fe2
+        crm_debug("Erasing failures of %s on %s", failed_id, node_name);
109fe2
+        rc = clear_rsc_history(crmd_channel, node_name, failed_id, data_set);
109fe2
         if (rc != pcmk_ok) {
109fe2
             return rc;
109fe2
         }
109fe2
-- 
109fe2
1.8.3.1
109fe2