Blame SOURCES/009-shutdown-lock.patch

ed4e54
From 8a0e19a7702f61622d06b1c473fb3d9a5924c8f4 Mon Sep 17 00:00:00 2001
ed4e54
From: Ken Gaillot <kgaillot@redhat.com>
ed4e54
Date: Tue, 14 Jan 2020 18:07:18 -0600
ed4e54
Subject: [PATCH 05/18] Refactor: liblrmd: new convenience function for
ed4e54
 allocating lrmd_event_data_t
ed4e54
ed4e54
---
ed4e54
 daemons/controld/controld_execd.c     |  7 +------
ed4e54
 include/crm/lrmd.h                    |  2 ++
ed4e54
 lib/lrmd/lrmd_client.c                | 34 +++++++++++++++++++++++++++++++++-
ed4e54
 lib/pacemaker/pcmk_sched_transition.c |  7 +------
ed4e54
 lib/pacemaker/pcmk_trans_unpack.c     |  9 +++------
ed4e54
 5 files changed, 40 insertions(+), 19 deletions(-)
ed4e54
ed4e54
diff --git a/daemons/controld/controld_execd.c b/daemons/controld/controld_execd.c
ed4e54
index 82f2bf1..17cc8d6 100644
ed4e54
--- a/daemons/controld/controld_execd.c
ed4e54
+++ b/daemons/controld/controld_execd.c
ed4e54
@@ -1878,15 +1878,10 @@ construct_op(lrm_state_t * lrm_state, xmlNode * rsc_op, const char *rsc_id, cons
ed4e54
 
ed4e54
     CRM_ASSERT(rsc_id && operation);
ed4e54
 
ed4e54
-    op = calloc(1, sizeof(lrmd_event_data_t));
ed4e54
-    CRM_ASSERT(op != NULL);
ed4e54
-
ed4e54
+    op = lrmd_new_event(rsc_id, operation, 0);
ed4e54
     op->type = lrmd_event_exec_complete;
ed4e54
-    op->op_type = strdup(operation);
ed4e54
     op->op_status = PCMK_LRM_OP_PENDING;
ed4e54
     op->rc = -1;
ed4e54
-    op->rsc_id = strdup(rsc_id);
ed4e54
-    op->interval_ms = 0;
ed4e54
     op->timeout = 0;
ed4e54
     op->start_delay = 0;
ed4e54
 
ed4e54
diff --git a/include/crm/lrmd.h b/include/crm/lrmd.h
ed4e54
index cfa2925..3ad1f05 100644
ed4e54
--- a/include/crm/lrmd.h
ed4e54
+++ b/include/crm/lrmd.h
ed4e54
@@ -248,6 +248,8 @@ typedef struct lrmd_event_data_s {
ed4e54
     const char *exit_reason;
ed4e54
 } lrmd_event_data_t;
ed4e54
 
ed4e54
+lrmd_event_data_t *lrmd_new_event(const char *rsc_id, const char *task,
ed4e54
+                                  guint interval_ms);
ed4e54
 lrmd_event_data_t *lrmd_copy_event(lrmd_event_data_t * event);
ed4e54
 void lrmd_free_event(lrmd_event_data_t * event);
ed4e54
 
ed4e54
diff --git a/lib/lrmd/lrmd_client.c b/lib/lrmd/lrmd_client.c
ed4e54
index 2469c52..d16743d 100644
ed4e54
--- a/lib/lrmd/lrmd_client.c
ed4e54
+++ b/lib/lrmd/lrmd_client.c
ed4e54
@@ -1,5 +1,7 @@
ed4e54
 /*
ed4e54
- * Copyright 2012-2018 David Vossel <davidvossel@gmail.com>
ed4e54
+ * Copyright 2012-2020 the Pacemaker project contributors
ed4e54
+ *
ed4e54
+ * The version control history for this file may have further details.
ed4e54
  *
ed4e54
  * This source code is licensed under the GNU Lesser General Public License
ed4e54
  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
ed4e54
@@ -175,6 +177,36 @@ lrmd_key_value_freeall(lrmd_key_value_t * head)
ed4e54
     }
ed4e54
 }
ed4e54
 
ed4e54
+/*!
ed4e54
+ * Create a new lrmd_event_data_t object
ed4e54
+ *
ed4e54
+ * \param[in] rsc_id       ID of resource involved in event
ed4e54
+ * \param[in] task         Action name
ed4e54
+ * \param[in] interval_ms  Action interval
ed4e54
+ *
ed4e54
+ * \return Newly allocated and initialized lrmd_event_data_t
ed4e54
+ * \note This functions asserts on memory errors, so the return value is
ed4e54
+ *       guaranteed to be non-NULL. The caller is responsible for freeing the
ed4e54
+ *       result with lrmd_free_event().
ed4e54
+ */
ed4e54
+lrmd_event_data_t *
ed4e54
+lrmd_new_event(const char *rsc_id, const char *task, guint interval_ms)
ed4e54
+{
ed4e54
+    lrmd_event_data_t *event = calloc(1, sizeof(lrmd_event_data_t));
ed4e54
+
ed4e54
+    CRM_ASSERT(event != NULL);
ed4e54
+    if (rsc_id != NULL) {
ed4e54
+        event->rsc_id = strdup(rsc_id);
ed4e54
+        CRM_ASSERT(event->rsc_id != NULL);
ed4e54
+    }
ed4e54
+    if (task != NULL) {
ed4e54
+        event->op_type = strdup(task);
ed4e54
+        CRM_ASSERT(event->op_type != NULL);
ed4e54
+    }
ed4e54
+    event->interval_ms = interval_ms;
ed4e54
+    return event;
ed4e54
+}
ed4e54
+
ed4e54
 lrmd_event_data_t *
ed4e54
 lrmd_copy_event(lrmd_event_data_t * event)
ed4e54
 {
ed4e54
diff --git a/lib/pacemaker/pcmk_sched_transition.c b/lib/pacemaker/pcmk_sched_transition.c
ed4e54
index c415b75..1698c85 100644
ed4e54
--- a/lib/pacemaker/pcmk_sched_transition.c
ed4e54
+++ b/lib/pacemaker/pcmk_sched_transition.c
ed4e54
@@ -131,12 +131,7 @@ create_op(xmlNode *cib_resource, const char *task, guint interval_ms,
ed4e54
     lrmd_event_data_t *op = NULL;
ed4e54
     xmlNode *xop = NULL;
ed4e54
 
ed4e54
-    op = calloc(1, sizeof(lrmd_event_data_t));
ed4e54
-
ed4e54
-    op->rsc_id = strdup(ID(cib_resource));
ed4e54
-    op->interval_ms = interval_ms;
ed4e54
-    op->op_type = strdup(task);
ed4e54
-
ed4e54
+    op = lrmd_new_event(ID(cib_resource), task, interval_ms);
ed4e54
     op->rc = outcome;
ed4e54
     op->op_status = 0;
ed4e54
     op->params = NULL;          /* TODO: Fill me in */
ed4e54
diff --git a/lib/pacemaker/pcmk_trans_unpack.c b/lib/pacemaker/pcmk_trans_unpack.c
ed4e54
index e57f386..3e53289 100644
ed4e54
--- a/lib/pacemaker/pcmk_trans_unpack.c
ed4e54
+++ b/lib/pacemaker/pcmk_trans_unpack.c
ed4e54
@@ -298,12 +298,9 @@ convert_graph_action(xmlNode * resource, crm_action_t * action, int status, int
ed4e54
     CRM_CHECK(action_resource != NULL, crm_log_xml_warn(action->xml, "Bad");
ed4e54
               return NULL);
ed4e54
 
ed4e54
-    op = calloc(1, sizeof(lrmd_event_data_t));
ed4e54
-
ed4e54
-    op->rsc_id = strdup(ID(action_resource));
ed4e54
-    op->interval_ms = action->interval_ms;
ed4e54
-    op->op_type = strdup(crm_element_value(action->xml, XML_LRM_ATTR_TASK));
ed4e54
-
ed4e54
+    op = lrmd_new_event(ID(action_resource),
ed4e54
+                        crm_element_value(action->xml, XML_LRM_ATTR_TASK),
ed4e54
+                        action->interval_ms);
ed4e54
     op->rc = rc;
ed4e54
     op->op_status = status;
ed4e54
     op->t_run = time(NULL);
ed4e54
-- 
ed4e54
1.8.3.1
ed4e54