File bsc#1210857-0001-Low-daemons-pacemakerd-S-should-wait-for-shutdown-be.patch of Package pacemaker.32051
From 6ec6bac351b4eaf74e4abd76d172190d60d016b6 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 1 May 2023 14:47:12 -0400
Subject: [PATCH] Low: daemons: pacemakerd -S should wait for shutdown before
returning
Previously, `pacemakerd -S` would request a shutdown and then sit in a
loop for 30 minutes, waiting for the IPC connection to drop. Only then
would it return to the command line. This gave the user a way of
knowing the shutdown completed.
There are potentially various ways of solving this problem. However, a
shutdown works by adding an event to the main loop which makes it
difficult to know exactly when it happens. So, just go with the easiest
fix and re-implement the loop checking the IPC connection status.
Regression in 2.1.1 introduced by 64d4f9b5f
---
daemons/pacemakerd/pacemakerd.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
index cc55a6af1..9f77ccca2 100644
--- a/daemons/pacemakerd/pacemakerd.c
+++ b/daemons/pacemakerd/pacemakerd.c
@@ -337,9 +337,32 @@ main(int argc, char **argv)
if (old_instance_connected) {
rc = pcmk_pacemakerd_api_shutdown(old_instance, crm_system_name);
pcmk_dispatch_ipc(old_instance);
- pcmk_free_ipc_api(old_instance);
+
exit_code = pcmk_rc2exitc(rc);
+
+ if (exit_code != CRM_EX_OK) {
+ pcmk_free_ipc_api(old_instance);
+ goto done;
+ }
+
+ /* We get the ACK immediately, and the response right after that,
+ * but it might take a while for pacemakerd to get around to
+ * shutting down. Wait for that to happen (with 30-minute timeout).
+ */
+ for (int i = 0; i < 900; i++) {
+ if (!pcmk_ipc_is_connected(old_instance)) {
+ exit_code = CRM_EX_OK;
+ pcmk_free_ipc_api(old_instance);
+ goto done;
+ }
+
+ sleep(2);
+ }
+
+ exit_code = CRM_EX_TIMEOUT;
+ pcmk_free_ipc_api(old_instance);
goto done;
+
} else {
out->err(out, "Could not request shutdown "
"of existing Pacemaker instance: %s", pcmk_rc_str(rc));
--
2.35.3