Skip to content

Commit 3416148

Browse files
committed
Refactor: based: Move based_shutdown() to pacemaker-based.c
And make it static. It seems logical to have it in the same file as the main() function. Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 57f932e commit 3416148

3 files changed

Lines changed: 52 additions & 54 deletions

File tree

daemons/based/based_callbacks.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434

3535
#include <pacemaker-based.h>
3636

37-
#define EXIT_ESCALATION_MS 10000
38-
3937
static mainloop_timer_t *digest_timer = NULL;
4038
static long long ping_seq = 0;
4139
static char *ping_digest = NULL;
@@ -823,57 +821,6 @@ based_process_request(xmlNode *request, bool privileged,
823821
return rc;
824822
}
825823

826-
static gboolean
827-
cib_force_exit(gpointer data)
828-
{
829-
pcmk__notice("Exiting immediately after %s without shutdown acknowledgment",
830-
pcmk__readable_interval(EXIT_ESCALATION_MS));
831-
based_terminate(CRM_EX_ERROR);
832-
return FALSE;
833-
}
834-
835-
void
836-
based_shutdown(int nsig)
837-
{
838-
int active = 0;
839-
xmlNode *notification = NULL;
840-
841-
if (cib_shutdown_flag) {
842-
// Already shutting down
843-
return;
844-
}
845-
846-
cib_shutdown_flag = true;
847-
848-
/* The client count should be 0 by now. If it isn't, that means GLib had
849-
* some other reference to a remote client's source when we dropped the
850-
* remote client. This is believed not to be possible.
851-
*
852-
* If this occurs, continue the shutdown. The clients will be dropped
853-
* eventually.
854-
*/
855-
CRM_LOG_ASSERT(pcmk__ipc_client_count() == 0);
856-
857-
active = pcmk__cluster_num_active_nodes();
858-
if (active < 2) {
859-
pcmk__info("Exiting without sending shutdown request (no active "
860-
"peers)");
861-
based_terminate(CRM_EX_OK);
862-
return;
863-
}
864-
865-
pcmk__info("Sending shutdown request to %d peers", active);
866-
867-
notification = pcmk__xe_create(NULL, PCMK__XE_EXIT_NOTIFICATION);
868-
pcmk__xe_set(notification, PCMK__XA_T, PCMK__VALUE_CIB);
869-
pcmk__xe_set(notification, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_SHUTDOWN);
870-
871-
pcmk__cluster_send_message(NULL, pcmk_ipc_based, notification);
872-
pcmk__xml_free(notification);
873-
874-
pcmk__create_timer(EXIT_ESCALATION_MS, cib_force_exit, NULL);
875-
}
876-
877824
/*!
878825
* \internal
879826
* \brief Close remote sockets, free the global CIB and quit

daemons/based/based_callbacks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
int based_process_request(xmlNode *request, bool privileged,
2020
const pcmk__client_t *client);
21-
void based_shutdown(int nsig);
2221
void based_terminate(int exit_status);
2322

2423
#endif // BASED_CALLBACKS__H

daemons/based/pacemaker-based.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <pacemaker-based.h>
3232

33+
#define EXIT_ESCALATION_MS 10000
3334
#define SUMMARY "daemon for managing the configuration of a Pacemaker cluster"
3435

3536
bool cib_shutdown_flag = false;
@@ -156,6 +157,57 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group)
156157
return context;
157158
}
158159

160+
static gboolean
161+
based_force_exit(gpointer data)
162+
{
163+
pcmk__notice("Exiting immediately after %s without shutdown acknowledgment",
164+
pcmk__readable_interval(EXIT_ESCALATION_MS));
165+
based_terminate(CRM_EX_ERROR);
166+
return G_SOURCE_REMOVE;
167+
}
168+
169+
static void
170+
based_shutdown(int nsig)
171+
{
172+
int active = 0;
173+
xmlNode *notification = NULL;
174+
175+
if (cib_shutdown_flag) {
176+
// Already shutting down
177+
return;
178+
}
179+
180+
cib_shutdown_flag = true;
181+
182+
/* The client count should be 0 by now. If it isn't, that means GLib had
183+
* some other reference to a remote client's source when we dropped the
184+
* remote client. This is believed not to be possible.
185+
*
186+
* If this occurs, continue the shutdown. The clients will be dropped
187+
* eventually.
188+
*/
189+
CRM_LOG_ASSERT(pcmk__ipc_client_count() == 0);
190+
191+
active = pcmk__cluster_num_active_nodes();
192+
if (active < 2) {
193+
pcmk__info("Exiting without sending shutdown request (no active "
194+
"peers)");
195+
based_terminate(CRM_EX_OK);
196+
return;
197+
}
198+
199+
pcmk__info("Sending shutdown request to %d peers", active);
200+
201+
notification = pcmk__xe_create(NULL, PCMK__XE_EXIT_NOTIFICATION);
202+
pcmk__xe_set(notification, PCMK__XA_T, PCMK__VALUE_CIB);
203+
pcmk__xe_set(notification, PCMK__XA_CIB_OP, PCMK__CIB_REQUEST_SHUTDOWN);
204+
205+
pcmk__cluster_send_message(NULL, pcmk_ipc_based, notification);
206+
pcmk__xml_free(notification);
207+
208+
pcmk__create_timer(EXIT_ESCALATION_MS, based_force_exit, NULL);
209+
}
210+
159211
int
160212
main(int argc, char **argv)
161213
{

0 commit comments

Comments
 (0)