13 #include <libxml/tree.h> 30 #define DEFAULT_MESSAGE_TIMEOUT_MS 30000 37 guint message_timer_id;
38 guint message_timeout_ms;
42 quit_main_loop(data_t *
data)
44 if (
data->mainloop != NULL) {
45 GMainLoop *mloop =
data->mainloop;
47 data->mainloop = NULL;
49 g_main_loop_unref(mloop);
54 admin_message_timeout(gpointer user_data)
56 data_t *
data = user_data;
59 out->
err(out,
"error: No reply received from controller before timeout (%dms)",
60 data->message_timeout_ms);
61 data->message_timer_id = 0;
68 start_main_loop(data_t *
data)
70 if (
data->message_timeout_ms < 1) {
74 data->rc = ECONNRESET;
75 data->mainloop = g_main_loop_new(NULL, FALSE);
76 data->message_timer_id = g_timeout_add(
data->message_timeout_ms,
77 admin_message_timeout,
79 g_main_loop_run(
data->mainloop);
97 if (
data->rc == ECONNRESET) {
98 out->
err(out,
"error: Lost connection to controller");
100 event_done(
data, controld_api);
110 if (
data->message_timer_id != 0) {
111 g_source_remove(
data->message_timer_id);
112 data->message_timer_id = 0;
116 out->
err(out,
"error: Bad reply from controller: %s",
119 event_done(
data, controld_api);
124 out->
err(out,
"error: Unknown reply type %d from controller",
127 event_done(
data, controld_api);
137 void *event_data,
void *user_data)
139 data_t *
data = user_data;
142 event_type, status, event_data);
153 event_done(
data, controld_api);
159 void *event_data,
void *user_data)
161 data_t *
data = user_data;
164 event_type, status, event_data);
171 event_done(
data, controld_api);
177 void *event_data,
void *user_data)
179 data_t *
data = user_data;
184 char *pinged_buf = NULL;
186 switch (event_type) {
188 if (
data->rc == ECONNRESET) {
189 out->
err(out,
"error: Lost connection to pacemakerd");
191 event_done(
data, pacemakerd_api);
201 if (
data->message_timer_id != 0) {
202 g_source_remove(
data->message_timer_id);
203 data->message_timer_id = 0;
207 out->
err(out,
"error: Bad reply from pacemakerd: %s",
209 event_done(
data, pacemakerd_api);
214 out->
err(out,
"error: Unknown reply type %d from pacemakerd",
216 event_done(
data, pacemakerd_api);
227 out->
message(out,
"pacemakerd-health",
231 reply->
data.
ping.state):
"query failed",
237 event_done(
data, pacemakerd_api);
250 out->
err(out,
"error: Could not connect to %s: %s",
261 out->
err(out,
"error: Could not connect to %s: %s",
278 .message_timer_id = 0,
279 .message_timeout_ms = message_timeout_ms
283 if (controld_api != NULL) {
290 start_main_loop(&
data);
323 .message_timer_id = 0,
324 .message_timeout_ms = message_timeout_ms
328 if (controld_api != NULL) {
335 start_main_loop(&
data);
368 .message_timer_id = 0,
369 .message_timeout_ms = message_timeout_ms
373 if (pacemakerd_api != NULL) {
380 start_main_loop(&
data);
412 gboolean BASH_EXPORT;
416 remote_node_print_helper(xmlNode *
result,
void *user_data)
418 struct node_data *
data = user_data;
435 xmlNode *xml_node = NULL;
441 struct node_data
data = {
444 .BASH_EXPORT = BASH_EXPORT
449 if (!pcmk__str_empty(node_types) && strstr(node_types,
"all")) {
453 if (pcmk__str_empty(node_types) || strstr(node_types,
"cluster")) {
455 data.type =
"cluster";
457 remote_node_print_helper, &
data);
460 if (pcmk__str_empty(node_types) || strstr(node_types,
"guest")) {
461 data.field =
"value";
464 remote_node_print_helper, &
data);
469 data.type =
"remote";
471 remote_node_print_helper, &
data);
476 if (
data.found == 0) {
477 out->
info(out,
"No nodes configured");
void(* end_list)(pcmk__output_t *out)
enum pcmk_controld_api_reply reply_type
int pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms)
Get designated controller.
#define crm_time_log_timeofday
int pcmk_connect_ipc(pcmk_ipc_api_t *api, enum pcmk_ipc_dispatch dispatch_type)
Connect to a Pacemaker daemon via IPC.
int(* message)(pcmk__output_t *out, const char *message_id,...)
int pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT)
const char * host_from
Name of node that sent reply.
struct crm_time_s crm_time_t
int pcmk_controld_api_ping(pcmk_ipc_api_t *api, const char *node_name)
Ask the controller for status.
int pcmk_new_ipc_api(pcmk_ipc_api_t **api, enum pcmk_ipc_server server)
Create a new object for using Pacemaker daemon IPC.
struct pcmk_pacemakerd_api_reply_t::@4::@5 ping
enum crm_exit_e crm_exit_t
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
enum crm_ais_msg_types type
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Wrappers for and extensions to glib mainloop.
union pcmk_controld_api_reply_t::@0 data
int pcmk__out_prologue(pcmk__output_t **out, xmlNodePtr *xml)
int cib__signon_query(cib_t **cib, xmlNode **cib_object)
struct pcmk_controld_api_reply_t::@0::@3 ping
enum pcmk_pacemakerd_api_reply reply_type
Formatted output for pacemaker tools.
union pcmk_pacemakerd_api_reply_t::@4 data
#define PCMK__XP_GUEST_NODE_CONFIG
pcmk_ipc_server
Available IPC interfaces.
const char * crm_exit_str(crm_exit_t exit_code)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
int pcmk_pacemakerd_status(xmlNodePtr *xml, char *ipc_name, unsigned int message_timeout_ms)
Get pacemakerd status.
void crm_time_set_timet(crm_time_t *target, time_t *source)
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__register_lib_messages(pcmk__output_t *out)
#define PCMK__XP_REMOTE_NODE_CONFIG
const char * pcmk_ipc_name(pcmk_ipc_api_t *api, bool for_log)
Get the IPC name used with an IPC API connection.
Wrappers for and extensions to libxml2.
IPC commands for Pacemakerd.
void free_xml(xmlNode *child)
#define crm_time_log_with_timezone
void(* pcmk_ipc_callback_t)(pcmk_ipc_api_t *api, enum pcmk_ipc_event event_type, crm_exit_t status, void *event_data, void *user_data)
Callback function type for Pacemaker daemon IPC APIs.
void pcmk__out_epilogue(pcmk__output_t *out, xmlNodePtr *xml, int retval)
IPC commands for Pacemaker controller.
char * crm_time_as_string(crm_time_t *dt, int flags)
int pcmk_pacemakerd_api_ping(pcmk_ipc_api_t *api, const char *ipc_name)
pcmk_ipc_event
Possible event types that an IPC event callback can be called for.
Attach IPC to GMainLoop for dispatch.
Termination of IPC connection.
int pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms)
Get controller status.
pcmk__action_result_t result
int pcmk__controller_status(pcmk__output_t *out, char *dest_node, guint message_timeout_ms)
const char * pcmk_pacemakerd_api_daemon_state_enum2text(enum pcmk_pacemakerd_state state)
crm_time_t * crm_time_new(const char *string)
void pcmk_free_ipc_api(pcmk_ipc_api_t *api)
Free the contents of an IPC API object.
void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n)
Drain some remaining main loop events then quit it.
This structure contains everything that makes up a single output formatter.
int pcmk__strcmp(const char *s1, const char *s2, uint32_t flags)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
void crm_foreach_xpath_result(xmlNode *xml, const char *xpath, void(*helper)(xmlNode *, void *), void *user_data)
Run a supplied function for each result of an xpath search.
int pcmk__pacemakerd_status(pcmk__output_t *out, char *ipc_name, guint message_timeout_ms)
Daemon's reply to client IPC request.
int pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms)
#define PCMK__XP_MEMBER_NODE_CONFIG
void pcmk_register_ipc_callback(pcmk_ipc_api_t *api, pcmk_ipc_callback_t cb, void *user_data)
Register a callback for IPC API events.
void pcmk_disconnect_ipc(pcmk_ipc_api_t *api)
Disconnect an IPC API instance.
#define crm_time_log_date
int pcmk_list_nodes(xmlNodePtr *xml, char *node_types)
Get nodes list.
#define DEFAULT_MESSAGE_TIMEOUT_MS
void crm_time_free(crm_time_t *dt)