26ad17
From b49880467c18ade43cc283036949b686d1413118 Mon Sep 17 00:00:00 2001
26ad17
From: Ken Gaillot <kgaillot@redhat.com>
26ad17
Date: Tue, 14 Apr 2020 14:12:22 -0500
26ad17
Subject: [PATCH 1/5] Low: pacemakerd: remove unneeded IPC and CPG commands
26ad17
26ad17
Now that the controller handles crm_node's -l/-p needs, pacemakerd no longer
26ad17
needs to. Backward compatibility isn't an issue because pacemakerd IPC isn't
26ad17
proxied for Pacemaker Remote, so only local clients are relevant, and the
26ad17
pacemakerd IPC never had a C API, which means it was internal only.
26ad17
26ad17
Without those commands, pacemakerd no longer needs to track a process mask,
26ad17
connect to CPG, or maintain the peer cache.
26ad17
26ad17
The only remaining need for the cluster layer is to use corosync CFG to tell
26ad17
corosync to initiate or block shutdown.
26ad17
---
26ad17
 daemons/pacemakerd/pacemakerd.c     | 283 ++----------------------------------
26ad17
 daemons/pacemakerd/pacemakerd.h     |   2 +-
26ad17
 daemons/pacemakerd/pcmkd_corosync.c |   7 +-
26ad17
 3 files changed, 16 insertions(+), 276 deletions(-)
26ad17
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
26ad17
index 64c30e2..0f7b2db 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.c
26ad17
+++ b/daemons/pacemakerd/pacemakerd.c
26ad17
@@ -36,15 +36,12 @@
26ad17
 #include <dirent.h>
26ad17
 #include <ctype.h>
26ad17
 
26ad17
-static gboolean pcmk_quorate = FALSE;
26ad17
 static gboolean fatal_error = FALSE;
26ad17
 static GMainLoop *mainloop = NULL;
26ad17
 static bool global_keep_tracking = false;
26ad17
 
26ad17
 #define PCMK_PROCESS_CHECK_INTERVAL 5
26ad17
 
26ad17
-static const char *local_name = NULL;
26ad17
-static uint32_t local_nodeid = 0;
26ad17
 static crm_trigger_t *shutdown_trigger = NULL;
26ad17
 static const char *pid_file = PCMK_RUN_DIR "/pacemaker.pid";
26ad17
 
26ad17
@@ -105,23 +102,6 @@ static pcmk_child_t pcmk_children[] = {
26ad17
 static gboolean check_active_before_startup_processes(gpointer user_data);
26ad17
 static int child_liveness(pcmk_child_t *child);
26ad17
 static gboolean start_child(pcmk_child_t * child);
26ad17
-static gboolean update_node_processes(uint32_t id, const char *uname,
26ad17
-                                      uint32_t procs);
26ad17
-void update_process_clients(pcmk__client_t *client);
26ad17
-
26ad17
-static uint32_t
26ad17
-get_process_list(void)
26ad17
-{
26ad17
-    int lpc = 0;
26ad17
-    uint32_t procs = crm_get_cluster_proc();
26ad17
-
26ad17
-    for (lpc = 0; lpc < SIZEOF(pcmk_children); lpc++) {
26ad17
-        if (pcmk_children[lpc].pid != 0) {
26ad17
-            procs |= pcmk_children[lpc].flag;
26ad17
-        }
26ad17
-    }
26ad17
-    return procs;
26ad17
-}
26ad17
 
26ad17
 static void
26ad17
 pcmk_process_exit(pcmk_child_t * child)
26ad17
@@ -129,16 +109,6 @@ pcmk_process_exit(pcmk_child_t * child)
26ad17
     child->pid = 0;
26ad17
     child->active_before_startup = FALSE;
26ad17
 
26ad17
-    /* Broadcast the fact that one of our processes died ASAP
26ad17
-     *
26ad17
-     * Try to get some logging of the cause out first though
26ad17
-     * because we're probably about to get fenced
26ad17
-     *
26ad17
-     * Potentially do this only if respawn_count > N
26ad17
-     * to allow for local recovery
26ad17
-     */
26ad17
-    update_node_processes(local_nodeid, NULL, get_process_list());
26ad17
-
26ad17
     child->respawn_count += 1;
26ad17
     if (child->respawn_count > MAX_RESPAWN) {
26ad17
         crm_err("Child respawn count exceeded by %s", child->name);
26ad17
@@ -148,8 +118,6 @@ pcmk_process_exit(pcmk_child_t * child)
26ad17
     if (shutdown_trigger) {
26ad17
         /* resume step-wise shutdown (returned TRUE yields no parallelizing) */
26ad17
         mainloop_set_trigger(shutdown_trigger);
26ad17
-        /* intended to speed up propagating expected lay-off of the daemons? */
26ad17
-        update_node_processes(local_nodeid, NULL, get_process_list());
26ad17
 
26ad17
     } else if (!child->respawn) {
26ad17
         /* nothing to do */
26ad17
@@ -341,7 +309,6 @@ start_child(pcmk_child_t * child)
26ad17
         crm_info("Forked child %lld for process %s%s",
26ad17
                  (long long) child->pid, child->name,
26ad17
                  use_valgrind ? " (valgrind enabled: " VALGRIND_BIN ")" : "");
26ad17
-        update_node_processes(local_nodeid, NULL, get_process_list());
26ad17
         return TRUE;
26ad17
 
26ad17
     } else {
26ad17
@@ -492,7 +459,6 @@ pcmk_shutdown_worker(gpointer user_data)
26ad17
         }
26ad17
     }
26ad17
 
26ad17
-    /* send_cluster_id(); */
26ad17
     crm_notice("Shutdown complete");
26ad17
 
26ad17
     {
26ad17
@@ -567,22 +533,12 @@ pcmk_ipc_dispatch(qb_ipcs_connection_t * qbc, void *data, size_t size)
26ad17
         pcmk_shutdown(15);
26ad17
 
26ad17
     } else if (crm_str_eq(task, CRM_OP_RM_NODE_CACHE, TRUE)) {
26ad17
-        /* Send to everyone */
26ad17
-        struct iovec *iov;
26ad17
-        int id = 0;
26ad17
-        const char *name = NULL;
26ad17
-
26ad17
-        crm_element_value_int(msg, XML_ATTR_ID, &id;;
26ad17
-        name = crm_element_value(msg, XML_ATTR_UNAME);
26ad17
-        crm_notice("Instructing peers to remove references to node %s/%u", name, id);
26ad17
-
26ad17
-        iov = calloc(1, sizeof(struct iovec));
26ad17
-        iov->iov_base = dump_xml_unformatted(msg);
26ad17
-        iov->iov_len = 1 + strlen(iov->iov_base);
26ad17
-        send_cpg_iov(iov);
26ad17
+        crm_trace("Ignoring IPC request to purge node "
26ad17
+                  "because peer cache is not used");
26ad17
 
26ad17
     } else {
26ad17
-        update_process_clients(c);
26ad17
+        crm_debug("Unrecognized IPC command '%s' sent to pacemakerd",
26ad17
+                  crm_str(task));
26ad17
     }
26ad17
 
26ad17
     free_xml(msg);
26ad17
@@ -618,113 +574,6 @@ struct qb_ipcs_service_handlers mcp_ipc_callbacks = {
26ad17
     .connection_destroyed = pcmk_ipc_destroy
26ad17
 };
26ad17
 
26ad17
-static void
26ad17
-send_xml_to_client(gpointer key, gpointer value, gpointer user_data)
26ad17
-{
26ad17
-    pcmk__ipc_send_xml((pcmk__client_t *) value, 0, (xmlNode *) user_data,
26ad17
-                       crm_ipc_server_event);
26ad17
-}
26ad17
-
26ad17
-/*!
26ad17
- * \internal
26ad17
- * \brief Send an XML message with process list of all known peers to client(s)
26ad17
- *
26ad17
- * \param[in] client  Send message to this client, or all clients if NULL
26ad17
- */
26ad17
-void
26ad17
-update_process_clients(pcmk__client_t *client)
26ad17
-{
26ad17
-    GHashTableIter iter;
26ad17
-    crm_node_t *node = NULL;
26ad17
-    xmlNode *update = create_xml_node(NULL, "nodes");
26ad17
-
26ad17
-    if (is_corosync_cluster()) {
26ad17
-        crm_xml_add_int(update, "quorate", pcmk_quorate);
26ad17
-    }
26ad17
-
26ad17
-    g_hash_table_iter_init(&iter, crm_peer_cache);
26ad17
-    while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & node)) {
26ad17
-        xmlNode *xml = create_xml_node(update, "node");
26ad17
-
26ad17
-        crm_xml_add_int(xml, "id", node->id);
26ad17
-        crm_xml_add(xml, "uname", node->uname);
26ad17
-        crm_xml_add(xml, "state", node->state);
26ad17
-        crm_xml_add_int(xml, "processes", node->processes);
26ad17
-    }
26ad17
-
26ad17
-    if(client) {
26ad17
-        crm_trace("Sending process list to client %s", client->id);
26ad17
-        send_xml_to_client(NULL, client, update);
26ad17
-
26ad17
-    } else {
26ad17
-        crm_trace("Sending process list to %d clients",
26ad17
-                  pcmk__ipc_client_count());
26ad17
-        pcmk__foreach_ipc_client(send_xml_to_client, update);
26ad17
-    }
26ad17
-    free_xml(update);
26ad17
-}
26ad17
-
26ad17
-/*!
26ad17
- * \internal
26ad17
- * \brief Send a CPG message with local node's process list to all peers
26ad17
- */
26ad17
-static void
26ad17
-update_process_peers(void)
26ad17
-{
26ad17
-    /* Do nothing for corosync-2 based clusters */
26ad17
-
26ad17
-    struct iovec *iov = calloc(1, sizeof(struct iovec));
26ad17
-
26ad17
-    CRM_ASSERT(iov);
26ad17
-    if (local_name) {
26ad17
-        iov->iov_base = crm_strdup_printf("<node uname=\"%s\" proclist=\"%u\"/>",
26ad17
-                                          local_name, get_process_list());
26ad17
-    } else {
26ad17
-        iov->iov_base = crm_strdup_printf("<node proclist=\"%u\"/>",
26ad17
-                                          get_process_list());
26ad17
-    }
26ad17
-    iov->iov_len = strlen(iov->iov_base) + 1;
26ad17
-    crm_trace("Sending %s", (char*) iov->iov_base);
26ad17
-    send_cpg_iov(iov);
26ad17
-}
26ad17
-
26ad17
-/*!
26ad17
- * \internal
26ad17
- * \brief Update a node's process list, notifying clients and peers if needed
26ad17
- *
26ad17
- * \param[in] id     Node ID of affected node
26ad17
- * \param[in] uname  Uname of affected node
26ad17
- * \param[in] procs  Affected node's process list mask
26ad17
- *
26ad17
- * \return TRUE if the process list changed, FALSE otherwise
26ad17
- */
26ad17
-static gboolean
26ad17
-update_node_processes(uint32_t id, const char *uname, uint32_t procs)
26ad17
-{
26ad17
-    gboolean changed = FALSE;
26ad17
-    crm_node_t *node = crm_get_peer(id, uname);
26ad17
-
26ad17
-    if (procs != 0) {
26ad17
-        if (procs != node->processes) {
26ad17
-            crm_debug("Node %s now has process list: %.32x (was %.32x)",
26ad17
-                      node->uname, procs, node->processes);
26ad17
-            node->processes = procs;
26ad17
-            changed = TRUE;
26ad17
-
26ad17
-            /* If local node's processes have changed, notify clients/peers */
26ad17
-            if (id == local_nodeid) {
26ad17
-                update_process_clients(NULL);
26ad17
-                update_process_peers();
26ad17
-            }
26ad17
-
26ad17
-        } else {
26ad17
-            crm_trace("Node %s still has process list: %.32x", node->uname, procs);
26ad17
-        }
26ad17
-    }
26ad17
-    return changed;
26ad17
-}
26ad17
-
26ad17
-
26ad17
 static pcmk__cli_option_t long_options[] = {
26ad17
     // long option, argument type, storage, short option, description, flags
26ad17
     {
26ad17
@@ -1126,91 +975,6 @@ init_children_processes(void)
26ad17
     setenv("PCMK_respawned", "true", 1);
26ad17
 }
26ad17
 
26ad17
-static void
26ad17
-mcp_cpg_destroy(gpointer user_data)
26ad17
-{
26ad17
-    crm_crit("Lost connection to cluster layer, shutting down");
26ad17
-    crm_exit(CRM_EX_DISCONNECT);
26ad17
-}
26ad17
-
26ad17
-/*!
26ad17
- * \internal
26ad17
- * \brief Process a CPG message (process list or manual peer cache removal)
26ad17
- *
26ad17
- * \param[in] handle     CPG connection (ignored)
26ad17
- * \param[in] groupName  CPG group name (ignored)
26ad17
- * \param[in] nodeid     ID of affected node
26ad17
- * \param[in] pid        Process ID (ignored)
26ad17
- * \param[in] msg        CPG XML message
26ad17
- * \param[in] msg_len    Length of msg in bytes (ignored)
26ad17
- */
26ad17
-static void
26ad17
-mcp_cpg_deliver(cpg_handle_t handle,
26ad17
-                 const struct cpg_name *groupName,
26ad17
-                 uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
26ad17
-{
26ad17
-    xmlNode *xml = string2xml(msg);
26ad17
-    const char *task = crm_element_value(xml, F_CRM_TASK);
26ad17
-
26ad17
-    crm_trace("Received CPG message (%s): %.200s",
26ad17
-              (task? task : "process list"), (char*)msg);
26ad17
-
26ad17
-    if (task == NULL) {
26ad17
-        if (nodeid == local_nodeid) {
26ad17
-            crm_debug("Ignoring message with local node's process list");
26ad17
-        } else {
26ad17
-            uint32_t procs = 0;
26ad17
-            const char *uname = crm_element_value(xml, "uname");
26ad17
-
26ad17
-            crm_element_value_int(xml, "proclist", (int *)&procs);
26ad17
-            if (update_node_processes(nodeid, uname, procs)) {
26ad17
-                update_process_clients(NULL);
26ad17
-            }
26ad17
-        }
26ad17
-
26ad17
-    } else if (crm_str_eq(task, CRM_OP_RM_NODE_CACHE, TRUE)) {
26ad17
-        int id = 0;
26ad17
-        const char *name = NULL;
26ad17
-
26ad17
-        crm_element_value_int(xml, XML_ATTR_ID, &id;;
26ad17
-        name = crm_element_value(xml, XML_ATTR_UNAME);
26ad17
-        reap_crm_member(id, name);
26ad17
-    }
26ad17
-
26ad17
-    if (xml != NULL) {
26ad17
-        free_xml(xml);
26ad17
-    }
26ad17
-}
26ad17
-
26ad17
-static void
26ad17
-mcp_cpg_membership(cpg_handle_t handle,
26ad17
-                    const struct cpg_name *groupName,
26ad17
-                    const struct cpg_address *member_list, size_t member_list_entries,
26ad17
-                    const struct cpg_address *left_list, size_t left_list_entries,
26ad17
-                    const struct cpg_address *joined_list, size_t joined_list_entries)
26ad17
-{
26ad17
-    /* Update peer cache if needed */
26ad17
-    pcmk_cpg_membership(handle, groupName, member_list, member_list_entries,
26ad17
-                        left_list, left_list_entries,
26ad17
-                        joined_list, joined_list_entries);
26ad17
-
26ad17
-    /* Always broadcast our own presence after any membership change */
26ad17
-    update_process_peers();
26ad17
-}
26ad17
-
26ad17
-static gboolean
26ad17
-mcp_quorum_callback(unsigned long long seq, gboolean quorate)
26ad17
-{
26ad17
-    pcmk_quorate = quorate;
26ad17
-    return TRUE;
26ad17
-}
26ad17
-
26ad17
-static void
26ad17
-mcp_quorum_destroy(gpointer user_data)
26ad17
-{
26ad17
-    crm_info("connection lost");
26ad17
-}
26ad17
-
26ad17
 int
26ad17
 main(int argc, char **argv)
26ad17
 {
26ad17
@@ -1226,7 +990,6 @@ main(int argc, char **argv)
26ad17
     struct rlimit cores;
26ad17
     crm_ipc_t *old_instance = NULL;
26ad17
     qb_ipcs_service_t *ipcs = NULL;
26ad17
-    static crm_cluster_t cluster;
26ad17
 
26ad17
     crm_log_preinit(NULL, argc, argv);
26ad17
     pcmk__set_cli_options(NULL, "[options]", long_options,
26ad17
@@ -1397,7 +1160,7 @@ main(int argc, char **argv)
26ad17
     }
26ad17
 
26ad17
     /* Allows us to block shutdown */
26ad17
-    if (cluster_connect_cfg(&local_nodeid) == FALSE) {
26ad17
+    if (!cluster_connect_cfg()) {
26ad17
         crm_err("Couldn't connect to Corosync's CFG service");
26ad17
         crm_exit(CRM_EX_PROTOCOL);
26ad17
     }
26ad17
@@ -1417,34 +1180,13 @@ main(int argc, char **argv)
26ad17
             crm_exit(CRM_EX_FATAL);
26ad17
     };
26ad17
 
26ad17
-    cluster.destroy = mcp_cpg_destroy;
26ad17
-    cluster.cpg.cpg_deliver_fn = mcp_cpg_deliver;
26ad17
-    cluster.cpg.cpg_confchg_fn = mcp_cpg_membership;
26ad17
-
26ad17
-    crm_set_autoreap(FALSE);
26ad17
+    mainloop_add_signal(SIGTERM, pcmk_shutdown);
26ad17
+    mainloop_add_signal(SIGINT, pcmk_shutdown);
26ad17
 
26ad17
-    rc = pcmk_ok;
26ad17
+    init_children_processes();
26ad17
 
26ad17
-    if (cluster_connect_cpg(&cluster) == FALSE) {
26ad17
-        crm_err("Couldn't connect to Corosync's CPG service");
26ad17
-        rc = -ENOPROTOOPT;
26ad17
-
26ad17
-    } else if (cluster_connect_quorum(mcp_quorum_callback, mcp_quorum_destroy)
26ad17
-               == FALSE) {
26ad17
-        rc = -ENOTCONN;
26ad17
-
26ad17
-    } else {
26ad17
-        local_name = get_local_node_name();
26ad17
-        update_node_processes(local_nodeid, local_name, get_process_list());
26ad17
-
26ad17
-        mainloop_add_signal(SIGTERM, pcmk_shutdown);
26ad17
-        mainloop_add_signal(SIGINT, pcmk_shutdown);
26ad17
-
26ad17
-        init_children_processes();
26ad17
-
26ad17
-        crm_notice("Pacemaker daemon successfully started and accepting connections");
26ad17
-        g_main_loop_run(mainloop);
26ad17
-    }
26ad17
+    crm_notice("Pacemaker daemon successfully started and accepting connections");
26ad17
+    g_main_loop_run(mainloop);
26ad17
 
26ad17
     if (ipcs) {
26ad17
         crm_trace("Closing IPC server");
26ad17
@@ -1453,9 +1195,6 @@ main(int argc, char **argv)
26ad17
     }
26ad17
 
26ad17
     g_main_loop_unref(mainloop);
26ad17
-
26ad17
-    cluster_disconnect_cpg(&cluster);
26ad17
     cluster_disconnect_cfg();
26ad17
-
26ad17
-    crm_exit(crm_errno2exit(rc));
26ad17
+    crm_exit(CRM_EX_OK);
26ad17
 }
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.h b/daemons/pacemakerd/pacemakerd.h
26ad17
index d66ab10..ac2d842 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.h
26ad17
+++ b/daemons/pacemakerd/pacemakerd.h
26ad17
@@ -22,7 +22,7 @@
26ad17
 
26ad17
 gboolean mcp_read_config(void);
26ad17
 
26ad17
-gboolean cluster_connect_cfg(uint32_t * nodeid);
26ad17
+gboolean cluster_connect_cfg(void);
26ad17
 gboolean cluster_disconnect_cfg(void);
26ad17
 
26ad17
 void pcmk_shutdown(int nsig);
26ad17
diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c
26ad17
index ec74908..156f965 100644
26ad17
--- a/daemons/pacemakerd/pcmkd_corosync.c
26ad17
+++ b/daemons/pacemakerd/pcmkd_corosync.c
26ad17
@@ -93,13 +93,14 @@ cluster_disconnect_cfg(void)
26ad17
     } while(counter < max)
26ad17
 
26ad17
 gboolean
26ad17
-cluster_connect_cfg(uint32_t * nodeid)
26ad17
+cluster_connect_cfg(void)
26ad17
 {
26ad17
     cs_error_t rc;
26ad17
     int fd = -1, retries = 0, rv;
26ad17
     uid_t found_uid = 0;
26ad17
     gid_t found_gid = 0;
26ad17
     pid_t found_pid = 0;
26ad17
+    uint32_t nodeid;
26ad17
 
26ad17
     static struct mainloop_fd_callbacks cfg_fd_callbacks = {
26ad17
         .dispatch = pcmk_cfg_dispatch,
26ad17
@@ -134,14 +135,14 @@ cluster_connect_cfg(uint32_t * nodeid)
26ad17
     }
26ad17
 
26ad17
     retries = 0;
26ad17
-    cs_repeat(retries, 30, rc = corosync_cfg_local_get(cfg_handle, nodeid));
26ad17
+    cs_repeat(retries, 30, rc = corosync_cfg_local_get(cfg_handle, &nodeid));
26ad17
 
26ad17
     if (rc != CS_OK) {
26ad17
         crm_err("corosync cfg local_get error %d", rc);
26ad17
         goto bail;
26ad17
     }
26ad17
 
26ad17
-    crm_debug("Our nodeid: %d", *nodeid);
26ad17
+    crm_debug("Our nodeid: %lu", (unsigned long) nodeid);
26ad17
     mainloop_add_fd("corosync-cfg", G_PRIORITY_DEFAULT, fd, &cfg_handle, &cfg_fd_callbacks);
26ad17
 
26ad17
     return TRUE;
26ad17
-- 
26ad17
1.8.3.1
26ad17
26ad17
26ad17
From 23ad3803a12189a369d188f3d3e606142cf16c52 Mon Sep 17 00:00:00 2001
26ad17
From: Ken Gaillot <kgaillot@redhat.com>
26ad17
Date: Thu, 2 Jul 2020 11:25:28 -0500
26ad17
Subject: [PATCH 2/5] Refactor: pacemakerd: functionize removing core file
26ad17
 limit
26ad17
26ad17
... for readability and code isolation
26ad17
---
26ad17
 daemons/pacemakerd/pacemakerd.c | 50 ++++++++++++++++++++++++-----------------
26ad17
 1 file changed, 29 insertions(+), 21 deletions(-)
26ad17
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
26ad17
index 0f7b2db..ac308e7 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.c
26ad17
+++ b/daemons/pacemakerd/pacemakerd.c
26ad17
@@ -975,10 +975,37 @@ init_children_processes(void)
26ad17
     setenv("PCMK_respawned", "true", 1);
26ad17
 }
26ad17
 
26ad17
+static void
26ad17
+remove_core_file_limit(void)
26ad17
+{
26ad17
+    struct rlimit cores;
26ad17
+    int rc = getrlimit(RLIMIT_CORE, &cores);
26ad17
+
26ad17
+    if (rc < 0) {
26ad17
+        crm_perror(LOG_ERR, "Cannot determine current maximum core size.");
26ad17
+        return;
26ad17
+    }
26ad17
+
26ad17
+    if ((cores.rlim_max == 0) && (geteuid() == 0)) {
26ad17
+        cores.rlim_max = RLIM_INFINITY;
26ad17
+    } else {
26ad17
+        crm_info("Maximum core file size is %llu bytes",
26ad17
+                 (unsigned long long) cores.rlim_max);
26ad17
+    }
26ad17
+    cores.rlim_cur = cores.rlim_max;
26ad17
+
26ad17
+    rc = setrlimit(RLIMIT_CORE, &cores);
26ad17
+    if (rc < 0) {
26ad17
+        crm_perror(LOG_ERR,
26ad17
+                   "Core file generation will remain disabled."
26ad17
+                   " Core files are an important diagnostic tool, so"
26ad17
+                   " please consider enabling them by default.");
26ad17
+    }
26ad17
+}
26ad17
+
26ad17
 int
26ad17
 main(int argc, char **argv)
26ad17
 {
26ad17
-    int rc;
26ad17
     int flag;
26ad17
     int argerr = 0;
26ad17
 
26ad17
@@ -987,7 +1014,6 @@ main(int argc, char **argv)
26ad17
 
26ad17
     uid_t pcmk_uid = 0;
26ad17
     gid_t pcmk_gid = 0;
26ad17
-    struct rlimit cores;
26ad17
     crm_ipc_t *old_instance = NULL;
26ad17
     qb_ipcs_service_t *ipcs = NULL;
26ad17
 
26ad17
@@ -1099,25 +1125,7 @@ main(int argc, char **argv)
26ad17
                PACEMAKER_VERSION, BUILD_VERSION, CRM_FEATURES);
26ad17
     mainloop = g_main_loop_new(NULL, FALSE);
26ad17
 
26ad17
-    rc = getrlimit(RLIMIT_CORE, &cores);
26ad17
-    if (rc < 0) {
26ad17
-        crm_perror(LOG_ERR, "Cannot determine current maximum core size.");
26ad17
-    } else {
26ad17
-        if (cores.rlim_max == 0 && geteuid() == 0) {
26ad17
-            cores.rlim_max = RLIM_INFINITY;
26ad17
-        } else {
26ad17
-            crm_info("Maximum core file size is: %lu", (unsigned long)cores.rlim_max);
26ad17
-        }
26ad17
-        cores.rlim_cur = cores.rlim_max;
26ad17
-
26ad17
-        rc = setrlimit(RLIMIT_CORE, &cores);
26ad17
-        if (rc < 0) {
26ad17
-            crm_perror(LOG_ERR,
26ad17
-                       "Core file generation will remain disabled."
26ad17
-                       " Core files are an important diagnostic tool, so"
26ad17
-                       " please consider enabling them by default.");
26ad17
-        }
26ad17
-    }
26ad17
+    remove_core_file_limit();
26ad17
 
26ad17
     if (pcmk_daemon_user(&pcmk_uid, &pcmk_gid) < 0) {
26ad17
         crm_err("Cluster user %s does not exist, aborting Pacemaker startup", CRM_DAEMON_USER);
26ad17
-- 
26ad17
1.8.3.1
26ad17
26ad17
26ad17
From 40b0891dc92767aad8495121afcbd6e68fd3830a Mon Sep 17 00:00:00 2001
26ad17
From: Ken Gaillot <kgaillot@redhat.com>
26ad17
Date: Thu, 2 Jul 2020 11:26:09 -0500
26ad17
Subject: [PATCH 3/5] Log: pacemakerd: improve messages
26ad17
26ad17
---
26ad17
 daemons/pacemakerd/pacemakerd.c     | 22 +++++-----
26ad17
 daemons/pacemakerd/pcmkd_corosync.c | 85 +++++++++++++++++--------------------
26ad17
 2 files changed, 50 insertions(+), 57 deletions(-)
26ad17
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
26ad17
index ac308e7..0f459c0 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.c
26ad17
+++ b/daemons/pacemakerd/pacemakerd.c
26ad17
@@ -13,6 +13,7 @@
26ad17
 #include <pwd.h>
26ad17
 #include <grp.h>
26ad17
 #include <poll.h>
26ad17
+#include <errno.h>
26ad17
 #include <stdio.h>
26ad17
 #include <stdbool.h>
26ad17
 #include <sys/stat.h>
26ad17
@@ -344,7 +345,7 @@ start_child(pcmk_child_t * child)
26ad17
 
26ad17
             // Drop root group access if not needed
26ad17
             if (!need_root_group && (setgid(gid) < 0)) {
26ad17
-                crm_perror(LOG_ERR, "Could not set group to %d", gid);
26ad17
+                crm_warn("Could not set group to %d: %s", gid, strerror(errno));
26ad17
             }
26ad17
 
26ad17
             /* Initialize supplementary groups to only those always granted to
26ad17
@@ -356,7 +357,8 @@ start_child(pcmk_child_t * child)
26ad17
         }
26ad17
 
26ad17
         if (uid && setuid(uid) < 0) {
26ad17
-            crm_perror(LOG_ERR, "Could not set user to %d (%s)", uid, child->uid);
26ad17
+            crm_warn("Could not set user to %s (id %d): %s",
26ad17
+                     child->uid, uid, strerror(errno));
26ad17
         }
26ad17
 
26ad17
         pcmk__close_fds_in_child(true);
26ad17
@@ -370,7 +372,7 @@ start_child(pcmk_child_t * child)
26ad17
         } else {
26ad17
             (void)execvp(child->command, opts_default);
26ad17
         }
26ad17
-        crm_perror(LOG_ERR, "FATAL: Cannot exec %s", child->command);
26ad17
+        crm_crit("Could not execute %s: %s", child->command, strerror(errno));
26ad17
         crm_exit(CRM_EX_FATAL);
26ad17
     }
26ad17
     return TRUE;                /* never reached */
26ad17
@@ -527,8 +529,7 @@ pcmk_ipc_dispatch(qb_ipcs_connection_t * qbc, void *data, size_t size)
26ad17
 
26ad17
     task = crm_element_value(msg, F_CRM_TASK);
26ad17
     if (crm_str_eq(task, CRM_OP_QUIT, TRUE)) {
26ad17
-        /* Time to quit */
26ad17
-        crm_notice("Shutting down in response to ticket %s (%s)",
26ad17
+        crm_notice("Shutting down in response to IPC request %s from %s",
26ad17
                    crm_element_value(msg, F_CRM_REFERENCE), crm_element_value(msg, F_CRM_ORIGIN));
26ad17
         pcmk_shutdown(15);
26ad17
 
26ad17
@@ -982,7 +983,8 @@ remove_core_file_limit(void)
26ad17
     int rc = getrlimit(RLIMIT_CORE, &cores);
26ad17
 
26ad17
     if (rc < 0) {
26ad17
-        crm_perror(LOG_ERR, "Cannot determine current maximum core size.");
26ad17
+        crm_warn("Cannot determine current maximum core file size: %s",
26ad17
+                 strerror(errno));
26ad17
         return;
26ad17
     }
26ad17
 
26ad17
@@ -996,10 +998,8 @@ remove_core_file_limit(void)
26ad17
 
26ad17
     rc = setrlimit(RLIMIT_CORE, &cores);
26ad17
     if (rc < 0) {
26ad17
-        crm_perror(LOG_ERR,
26ad17
-                   "Core file generation will remain disabled."
26ad17
-                   " Core files are an important diagnostic tool, so"
26ad17
-                   " please consider enabling them by default.");
26ad17
+        crm_warn("Cannot raise system limit on core file size "
26ad17
+                 "(consider doing so manually)");
26ad17
     }
26ad17
 }
26ad17
 
26ad17
@@ -1108,7 +1108,6 @@ main(int argc, char **argv)
26ad17
     crm_ipc_destroy(old_instance);
26ad17
 
26ad17
     if (mcp_read_config() == FALSE) {
26ad17
-        crm_notice("Could not obtain corosync config data, exiting");
26ad17
         crm_exit(CRM_EX_UNAVAILABLE);
26ad17
     }
26ad17
 
26ad17
@@ -1169,7 +1168,6 @@ main(int argc, char **argv)
26ad17
 
26ad17
     /* Allows us to block shutdown */
26ad17
     if (!cluster_connect_cfg()) {
26ad17
-        crm_err("Couldn't connect to Corosync's CFG service");
26ad17
         crm_exit(CRM_EX_PROTOCOL);
26ad17
     }
26ad17
 
26ad17
diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c
26ad17
index 156f965..6f19803 100644
26ad17
--- a/daemons/pacemakerd/pcmkd_corosync.c
26ad17
+++ b/daemons/pacemakerd/pcmkd_corosync.c
26ad17
@@ -28,7 +28,6 @@
26ad17
 
26ad17
 #include <crm/common/ipc_internal.h>  /* PCMK__SPECIAL_PID* */
26ad17
 
26ad17
-enum cluster_type_e stack = pcmk_cluster_unknown;
26ad17
 static corosync_cfg_handle_t cfg_handle;
26ad17
 
26ad17
 /* =::=::=::= CFG - Shutdown stuff =::=::=::= */
26ad17
@@ -63,9 +62,8 @@ pcmk_cfg_dispatch(gpointer user_data)
26ad17
 static void
26ad17
 cfg_connection_destroy(gpointer user_data)
26ad17
 {
26ad17
-    crm_err("Connection destroyed");
26ad17
+    crm_err("Lost connection to Corosync");
26ad17
     cfg_handle = 0;
26ad17
-
26ad17
     pcmk_shutdown(SIGTERM);
26ad17
 }
26ad17
 
26ad17
@@ -85,7 +83,7 @@ cluster_disconnect_cfg(void)
26ad17
 	code;						\
26ad17
 	if(rc == CS_ERR_TRY_AGAIN || rc == CS_ERR_QUEUE_FULL) {  \
26ad17
 	    counter++;					\
26ad17
-	    crm_debug("Retrying operation after %ds", counter);	\
26ad17
+	    crm_debug("Retrying Corosync operation after %ds", counter);    \
26ad17
 	    sleep(counter);				\
26ad17
 	} else {                                        \
26ad17
             break;                                      \
26ad17
@@ -110,41 +108,42 @@ cluster_connect_cfg(void)
26ad17
     cs_repeat(retries, 30, rc = corosync_cfg_initialize(&cfg_handle, &cfg_callbacks));
26ad17
 
26ad17
     if (rc != CS_OK) {
26ad17
-        crm_err("corosync cfg init: %s (%d)", cs_strerror(rc), rc);
26ad17
+        crm_crit("Could not connect to Corosync CFG: %s " CRM_XS " rc=%d",
26ad17
+                 cs_strerror(rc), rc);
26ad17
         return FALSE;
26ad17
     }
26ad17
 
26ad17
     rc = corosync_cfg_fd_get(cfg_handle, &fd;;
26ad17
     if (rc != CS_OK) {
26ad17
-        crm_err("corosync cfg fd_get: %s (%d)", cs_strerror(rc), rc);
26ad17
+        crm_crit("Could not get Corosync CFG descriptor: %s " CRM_XS " rc=%d",
26ad17
+                 cs_strerror(rc), rc);
26ad17
         goto bail;
26ad17
     }
26ad17
 
26ad17
     /* CFG provider run as root (in given user namespace, anyway)? */
26ad17
     if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid,
26ad17
                                             &found_uid, &found_gid))) {
26ad17
-        crm_err("CFG provider is not authentic:"
26ad17
-                " process %lld (uid: %lld, gid: %lld)",
26ad17
-                (long long) PCMK__SPECIAL_PID_AS_0(found_pid),
26ad17
-                (long long) found_uid, (long long) found_gid);
26ad17
+        crm_crit("Rejecting Corosync CFG provider because process %lld "
26ad17
+                 "is running as uid %lld gid %lld, not root",
26ad17
+                  (long long) PCMK__SPECIAL_PID_AS_0(found_pid),
26ad17
+                 (long long) found_uid, (long long) found_gid);
26ad17
         goto bail;
26ad17
     } else if (rv < 0) {
26ad17
-        crm_err("Could not verify authenticity of CFG provider: %s (%d)",
26ad17
-                strerror(-rv), -rv);
26ad17
+        crm_crit("Could not authenticate Corosync CFG provider: %s "
26ad17
+                 CRM_XS " rc=%d", strerror(-rv), -rv);
26ad17
         goto bail;
26ad17
     }
26ad17
 
26ad17
     retries = 0;
26ad17
     cs_repeat(retries, 30, rc = corosync_cfg_local_get(cfg_handle, &nodeid));
26ad17
-
26ad17
     if (rc != CS_OK) {
26ad17
-        crm_err("corosync cfg local_get error %d", rc);
26ad17
+        crm_crit("Could not get local node ID from Corosync: %s "
26ad17
+                 CRM_XS " rc=%d", cs_strerror(rc), rc);
26ad17
         goto bail;
26ad17
     }
26ad17
+    crm_debug("Corosync reports local node ID is %lu", (unsigned long) nodeid);
26ad17
 
26ad17
-    crm_debug("Our nodeid: %lu", (unsigned long) nodeid);
26ad17
     mainloop_add_fd("corosync-cfg", G_PRIORITY_DEFAULT, fd, &cfg_handle, &cfg_fd_callbacks);
26ad17
-
26ad17
     return TRUE;
26ad17
 
26ad17
   bail:
26ad17
@@ -184,14 +183,15 @@ mcp_read_config(void)
26ad17
     gid_t found_gid = 0;
26ad17
     pid_t found_pid = 0;
26ad17
     int rv;
26ad17
+    enum cluster_type_e stack;
26ad17
 
26ad17
     // There can be only one possibility
26ad17
     do {
26ad17
         rc = cmap_initialize(&local_handle);
26ad17
         if (rc != CS_OK) {
26ad17
             retries++;
26ad17
-            printf("cmap connection setup failed: %s.  Retrying in %ds\n", cs_strerror(rc), retries);
26ad17
-            crm_info("cmap connection setup failed: %s.  Retrying in %ds", cs_strerror(rc), retries);
26ad17
+            crm_info("Could not connect to Corosync CMAP: %s (retrying in %ds) "
26ad17
+                     CRM_XS " rc=%d", cs_strerror(rc), retries, rc);
26ad17
             sleep(retries);
26ad17
 
26ad17
         } else {
26ad17
@@ -201,15 +201,15 @@ mcp_read_config(void)
26ad17
     } while (retries < 5);
26ad17
 
26ad17
     if (rc != CS_OK) {
26ad17
-        printf("Could not connect to Cluster Configuration Database API, error %d\n", rc);
26ad17
-        crm_warn("Could not connect to Cluster Configuration Database API, error %d", rc);
26ad17
+        crm_crit("Could not connect to Corosync CMAP: %s "
26ad17
+                 CRM_XS " rc=%d", cs_strerror(rc), rc);
26ad17
         return FALSE;
26ad17
     }
26ad17
 
26ad17
     rc = cmap_fd_get(local_handle, &fd;;
26ad17
     if (rc != CS_OK) {
26ad17
-        crm_err("Could not obtain the CMAP API connection: %s (%d)",
26ad17
-                cs_strerror(rc), rc);
26ad17
+        crm_crit("Could not get Corosync CMAP descriptor: %s " CRM_XS " rc=%d",
26ad17
+                 cs_strerror(rc), rc);
26ad17
         cmap_finalize(local_handle);
26ad17
         return FALSE;
26ad17
     }
26ad17
@@ -217,38 +217,33 @@ mcp_read_config(void)
26ad17
     /* CMAP provider run as root (in given user namespace, anyway)? */
26ad17
     if (!(rv = crm_ipc_is_authentic_process(fd, (uid_t) 0,(gid_t) 0, &found_pid,
26ad17
                                             &found_uid, &found_gid))) {
26ad17
-        crm_err("CMAP provider is not authentic:"
26ad17
-                " process %lld (uid: %lld, gid: %lld)",
26ad17
-                (long long) PCMK__SPECIAL_PID_AS_0(found_pid),
26ad17
-                (long long) found_uid, (long long) found_gid);
26ad17
+        crm_crit("Rejecting Corosync CMAP provider because process %lld "
26ad17
+                 "is running as uid %lld gid %lld, not root",
26ad17
+                 (long long) PCMK__SPECIAL_PID_AS_0(found_pid),
26ad17
+                 (long long) found_uid, (long long) found_gid);
26ad17
         cmap_finalize(local_handle);
26ad17
         return FALSE;
26ad17
     } else if (rv < 0) {
26ad17
-        crm_err("Could not verify authenticity of CMAP provider: %s (%d)",
26ad17
-                strerror(-rv), -rv);
26ad17
+        crm_crit("Could not authenticate Corosync CMAP provider: %s "
26ad17
+                 CRM_XS " rc=%d", strerror(-rv), -rv);
26ad17
         cmap_finalize(local_handle);
26ad17
         return FALSE;
26ad17
     }
26ad17
 
26ad17
     stack = get_cluster_type();
26ad17
-    crm_info("Reading configure for stack: %s", name_for_cluster_type(stack));
26ad17
-
26ad17
-    /* =::=::= Should we be here =::=::= */
26ad17
-    if (stack == pcmk_cluster_corosync) {
26ad17
-        pcmk__set_env_option("cluster_type", "corosync");
26ad17
-        pcmk__set_env_option("quorum_type", "corosync");
26ad17
-
26ad17
-    } else {
26ad17
-        crm_err("Unsupported stack type: %s", name_for_cluster_type(stack));
26ad17
+    if (stack != pcmk_cluster_corosync) {
26ad17
+        crm_crit("Expected corosync stack but detected %s " CRM_XS " stack=%d",
26ad17
+                 name_for_cluster_type(stack), stack);
26ad17
         return FALSE;
26ad17
     }
26ad17
 
26ad17
-    /* =::=::= Logging =::=::= */
26ad17
-    if (pcmk__env_option("debug")) {
26ad17
-        /* Syslog logging is already setup by crm_log_init() */
26ad17
+    crm_info("Reading configuration for %s stack",
26ad17
+             name_for_cluster_type(stack));
26ad17
+    pcmk__set_env_option("cluster_type", "corosync");
26ad17
+    pcmk__set_env_option("quorum_type", "corosync");
26ad17
 
26ad17
-    } else {
26ad17
-        /* Check corosync */
26ad17
+    // If debug logging is not configured, check whether corosync has it
26ad17
+    if (pcmk__env_option("debug") == NULL) {
26ad17
         char *debug_enabled = NULL;
26ad17
 
26ad17
         get_config_opt(config, local_handle, "logging.debug", &debug_enabled, "off");
26ad17
@@ -269,7 +264,7 @@ mcp_read_config(void)
26ad17
     if(local_handle){
26ad17
         gid_t gid = 0;
26ad17
         if (pcmk_daemon_user(NULL, &gid) < 0) {
26ad17
-            crm_warn("Could not authorize group with corosync " CRM_XS
26ad17
+            crm_warn("Could not authorize group with Corosync " CRM_XS
26ad17
                      " No group found for user %s", CRM_DAEMON_USER);
26ad17
 
26ad17
         } else {
26ad17
@@ -277,8 +272,8 @@ mcp_read_config(void)
26ad17
             snprintf(key, PATH_MAX, "uidgid.gid.%u", gid);
26ad17
             rc = cmap_set_uint8(local_handle, key, 1);
26ad17
             if (rc != CS_OK) {
26ad17
-                crm_warn("Could not authorize group with corosync "CRM_XS
26ad17
-                         " group=%u rc=%d (%s)", gid, rc, ais_error2text(rc));
26ad17
+                crm_warn("Could not authorize group with Corosync: %s " CRM_XS
26ad17
+                         " group=%u rc=%d", ais_error2text(rc), gid, rc);
26ad17
             }
26ad17
         }
26ad17
     }
26ad17
-- 
26ad17
1.8.3.1
26ad17
26ad17
26ad17
From c1e12aeb58366f508730defcb8eb6f3ebedac469 Mon Sep 17 00:00:00 2001
26ad17
From: Ken Gaillot <kgaillot@redhat.com>
26ad17
Date: Thu, 23 Apr 2020 13:30:58 -0500
26ad17
Subject: [PATCH 4/5] Refactor: pacemakerd: use existing handle for corosync
26ad17
 shutdown
26ad17
26ad17
---
26ad17
 daemons/pacemakerd/pacemakerd.c     | 31 ++++---------------------------
26ad17
 daemons/pacemakerd/pacemakerd.h     |  1 +
26ad17
 daemons/pacemakerd/pcmkd_corosync.c | 24 +++++++++++++++++++++++-
26ad17
 3 files changed, 28 insertions(+), 28 deletions(-)
26ad17
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
26ad17
index 0f459c0..fb35dfc 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.c
26ad17
+++ b/daemons/pacemakerd/pacemakerd.c
26ad17
@@ -30,10 +30,6 @@
26ad17
 #include <crm/cluster/internal.h>
26ad17
 #include <crm/cluster.h>
26ad17
 
26ad17
-#ifdef SUPPORT_COROSYNC
26ad17
-#include <corosync/cfg.h>
26ad17
-#endif
26ad17
-
26ad17
 #include <dirent.h>
26ad17
 #include <ctype.h>
26ad17
 
26ad17
@@ -145,28 +141,6 @@ pcmk_process_exit(pcmk_child_t * child)
26ad17
     }
26ad17
 }
26ad17
 
26ad17
-static void pcmk_exit_with_cluster(int exitcode)
26ad17
-{
26ad17
-#ifdef SUPPORT_COROSYNC
26ad17
-    corosync_cfg_handle_t cfg_handle;
26ad17
-    cs_error_t err;
26ad17
-
26ad17
-    if (exitcode == CRM_EX_FATAL) {
26ad17
-	    crm_info("Asking Corosync to shut down");
26ad17
-	    err = corosync_cfg_initialize(&cfg_handle, NULL);
26ad17
-	    if (err != CS_OK) {
26ad17
-		    crm_warn("Unable to open handle to corosync to close it down. err=%d", err);
26ad17
-	    }
26ad17
-	    err = corosync_cfg_try_shutdown(cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_IMMEDIATE);
26ad17
-	    if (err != CS_OK) {
26ad17
-		    crm_warn("Corosync shutdown failed. err=%d", err);
26ad17
-	    }
26ad17
-	    corosync_cfg_finalize(cfg_handle);
26ad17
-    }
26ad17
-#endif
26ad17
-    crm_exit(exitcode);
26ad17
-}
26ad17
-
26ad17
 static void
26ad17
 pcmk_child_exit(mainloop_child_t * p, pid_t pid, int core, int signo, int exitcode)
26ad17
 {
26ad17
@@ -475,7 +449,10 @@ pcmk_shutdown_worker(gpointer user_data)
26ad17
 
26ad17
     if (fatal_error) {
26ad17
         crm_notice("Shutting down and staying down after fatal error");
26ad17
-        pcmk_exit_with_cluster(CRM_EX_FATAL);
26ad17
+#ifdef SUPPORT_COROSYNC
26ad17
+        pcmkd_shutdown_corosync();
26ad17
+#endif
26ad17
+        crm_exit(CRM_EX_FATAL);
26ad17
     }
26ad17
 
26ad17
     return TRUE;
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.h b/daemons/pacemakerd/pacemakerd.h
26ad17
index ac2d842..5f475fd 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.h
26ad17
+++ b/daemons/pacemakerd/pacemakerd.h
26ad17
@@ -24,5 +24,6 @@ gboolean mcp_read_config(void);
26ad17
 
26ad17
 gboolean cluster_connect_cfg(void);
26ad17
 gboolean cluster_disconnect_cfg(void);
26ad17
+void pcmkd_shutdown_corosync(void);
26ad17
 
26ad17
 void pcmk_shutdown(int nsig);
26ad17
diff --git a/daemons/pacemakerd/pcmkd_corosync.c b/daemons/pacemakerd/pcmkd_corosync.c
26ad17
index 6f19803..82bd257 100644
26ad17
--- a/daemons/pacemakerd/pcmkd_corosync.c
26ad17
+++ b/daemons/pacemakerd/pcmkd_corosync.c
26ad17
@@ -28,7 +28,7 @@
26ad17
 
26ad17
 #include <crm/common/ipc_internal.h>  /* PCMK__SPECIAL_PID* */
26ad17
 
26ad17
-static corosync_cfg_handle_t cfg_handle;
26ad17
+static corosync_cfg_handle_t cfg_handle = 0;
26ad17
 
26ad17
 /* =::=::=::= CFG - Shutdown stuff =::=::=::= */
26ad17
 
26ad17
@@ -151,6 +151,28 @@ cluster_connect_cfg(void)
26ad17
     return FALSE;
26ad17
 }
26ad17
 
26ad17
+void
26ad17
+pcmkd_shutdown_corosync(void)
26ad17
+{
26ad17
+    cs_error_t rc;
26ad17
+
26ad17
+    if (cfg_handle == 0) {
26ad17
+        crm_warn("Unable to shut down Corosync: No connection");
26ad17
+        return;
26ad17
+    }
26ad17
+    crm_info("Asking Corosync to shut down");
26ad17
+    rc = corosync_cfg_try_shutdown(cfg_handle,
26ad17
+                                    COROSYNC_CFG_SHUTDOWN_FLAG_IMMEDIATE);
26ad17
+    if (rc == CS_OK) {
26ad17
+        corosync_cfg_finalize(cfg_handle);
26ad17
+        cfg_handle = 0;
26ad17
+    } else {
26ad17
+        crm_warn("Corosync shutdown failed: %s " CRM_XS " rc=%d",
26ad17
+                 cs_strerror(rc), rc);
26ad17
+    }
26ad17
+}
26ad17
+
26ad17
+
26ad17
 /* =::=::=::= Configuration =::=::=::= */
26ad17
 static int
26ad17
 get_config_opt(uint64_t unused, cmap_handle_t object_handle, const char *key, char **value,
26ad17
-- 
26ad17
1.8.3.1
26ad17
26ad17
26ad17
From e93857b25a22045d5db7bd45c3f026fb82e6da8d Mon Sep 17 00:00:00 2001
26ad17
From: Ken Gaillot <kgaillot@redhat.com>
26ad17
Date: Thu, 23 Apr 2020 13:36:08 -0500
26ad17
Subject: [PATCH 5/5] Build: pacemakerd: properly conditionalize corosync calls
26ad17
26ad17
Previously, pacemakerd in its entirety was not built unless corosync support
26ad17
was enabled, a throwback to when CMAN and Corosync 1 were supported. Now,
26ad17
pacemakerd is built unconditionally, and just its corosync-related calls are
26ad17
guarded by corosync support.
26ad17
26ad17
This has no effect currently since corosync 2+ is the only supported cluster
26ad17
layer, but it offers some future-proofing.
26ad17
---
26ad17
 daemons/pacemakerd/Makefile.am  | 9 ++++-----
26ad17
 daemons/pacemakerd/pacemakerd.c | 6 ++++++
26ad17
 2 files changed, 10 insertions(+), 5 deletions(-)
26ad17
26ad17
diff --git a/daemons/pacemakerd/Makefile.am b/daemons/pacemakerd/Makefile.am
26ad17
index b01d8ef..4cc8a7c 100644
26ad17
--- a/daemons/pacemakerd/Makefile.am
26ad17
+++ b/daemons/pacemakerd/Makefile.am
26ad17
@@ -1,5 +1,5 @@
26ad17
 #
26ad17
-# Copyright 2004-2019 the Pacemaker project contributors
26ad17
+# Copyright 2004-2020 the Pacemaker project contributors
26ad17
 #
26ad17
 # The version control history for this file may have further details.
26ad17
 #
26ad17
@@ -9,8 +9,6 @@
26ad17
 
26ad17
 include $(top_srcdir)/mk/common.mk
26ad17
 
26ad17
-if BUILD_CS_SUPPORT
26ad17
-
26ad17
 initdir			= $(INITDIR)
26ad17
 init_SCRIPTS		= pacemaker
26ad17
 sbin_PROGRAMS		= pacemakerd
26ad17
@@ -30,8 +28,9 @@ pacemakerd_LDFLAGS	= $(LDFLAGS_HARDENED_EXE)
26ad17
 
26ad17
 pacemakerd_LDADD	= $(top_builddir)/lib/cluster/libcrmcluster.la $(top_builddir)/lib/common/libcrmcommon.la
26ad17
 pacemakerd_LDADD	+= $(CLUSTERLIBS)
26ad17
-pacemakerd_SOURCES	= pacemakerd.c pcmkd_corosync.c
26ad17
-
26ad17
+pacemakerd_SOURCES	= pacemakerd.c
26ad17
+if BUILD_CS_SUPPORT
26ad17
+pacemakerd_SOURCES	+= pcmkd_corosync.c
26ad17
 endif
26ad17
 
26ad17
 CLEANFILES = $(man8_MANS)
26ad17
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
26ad17
index fb35dfc..652d6ca 100644
26ad17
--- a/daemons/pacemakerd/pacemakerd.c
26ad17
+++ b/daemons/pacemakerd/pacemakerd.c
26ad17
@@ -1084,9 +1084,11 @@ main(int argc, char **argv)
26ad17
     crm_ipc_close(old_instance);
26ad17
     crm_ipc_destroy(old_instance);
26ad17
 
26ad17
+#ifdef SUPPORT_COROSYNC
26ad17
     if (mcp_read_config() == FALSE) {
26ad17
         crm_exit(CRM_EX_UNAVAILABLE);
26ad17
     }
26ad17
+#endif
26ad17
 
26ad17
     // OCF shell functions and cluster-glue need facility under different name
26ad17
     {
26ad17
@@ -1143,10 +1145,12 @@ main(int argc, char **argv)
26ad17
         crm_exit(CRM_EX_OSERR);
26ad17
     }
26ad17
 
26ad17
+#ifdef SUPPORT_COROSYNC
26ad17
     /* Allows us to block shutdown */
26ad17
     if (!cluster_connect_cfg()) {
26ad17
         crm_exit(CRM_EX_PROTOCOL);
26ad17
     }
26ad17
+#endif
26ad17
 
26ad17
     if(pcmk_locate_sbd() > 0) {
26ad17
         setenv("PCMK_watchdog", "true", 1);
26ad17
@@ -1178,6 +1182,8 @@ main(int argc, char **argv)
26ad17
     }
26ad17
 
26ad17
     g_main_loop_unref(mainloop);
26ad17
+#ifdef SUPPORT_COROSYNC
26ad17
     cluster_disconnect_cfg();
26ad17
+#endif
26ad17
     crm_exit(CRM_EX_OK);
26ad17
 }
26ad17
-- 
26ad17
1.8.3.1
26ad17