summaryrefslogtreecommitdiffstats
path: root/daemons/execd
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:39:28 +0000
commit924f5ea83e48277e014ebf0d19a27187cb93e2f7 (patch)
tree75920a275bba045f6d108204562c218a9a26ea15 /daemons/execd
parentAdding upstream version 2.1.7. (diff)
downloadpacemaker-upstream.tar.xz
pacemaker-upstream.zip
Adding upstream version 2.1.8~rc1.upstream/2.1.8_rc1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'daemons/execd')
-rw-r--r--daemons/execd/Makefile.am4
-rw-r--r--daemons/execd/cts-exec-helper.c14
-rw-r--r--daemons/execd/execd_alerts.c36
-rw-r--r--daemons/execd/execd_commands.c224
-rw-r--r--daemons/execd/pacemaker-execd.c53
-rw-r--r--daemons/execd/pacemaker-execd.h1
-rw-r--r--daemons/execd/remoted_pidone.c10
-rw-r--r--daemons/execd/remoted_proxy.c71
-rw-r--r--daemons/execd/remoted_schemas.c286
-rw-r--r--daemons/execd/remoted_tls.c24
10 files changed, 520 insertions, 203 deletions
diff --git a/daemons/execd/Makefile.am b/daemons/execd/Makefile.am
index ab8544f..ce0e161 100644
--- a/daemons/execd/Makefile.am
+++ b/daemons/execd/Makefile.am
@@ -44,12 +44,14 @@ pacemaker_remoted_LDFLAGS = $(LDFLAGS_HARDENED_EXE)
pacemaker_remoted_LDADD = $(top_builddir)/lib/fencing/libstonithd.la
pacemaker_remoted_LDADD += $(top_builddir)/lib/services/libcrmservice.la
+pacemaker_remoted_LDADD += $(top_builddir)/lib/cib/libcib.la
pacemaker_remoted_LDADD += $(top_builddir)/lib/lrmd/liblrmd.la
pacemaker_remoted_LDADD += $(top_builddir)/lib/common/libcrmcommon.la
pacemaker_remoted_SOURCES = $(pacemaker_execd_SOURCES) \
remoted_tls.c \
remoted_pidone.c \
- remoted_proxy.c
+ remoted_proxy.c \
+ remoted_schemas.c
endif
cts_exec_helper_LDADD = $(top_builddir)/lib/pengine/libpe_status.la
diff --git a/daemons/execd/cts-exec-helper.c b/daemons/execd/cts-exec-helper.c
index 6ebbedf..b8f4407 100644
--- a/daemons/execd/cts-exec-helper.c
+++ b/daemons/execd/cts-exec-helper.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2023 the Pacemaker project contributors
+ * Copyright 2012-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -56,8 +56,8 @@ static struct {
static gboolean
interval_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error) {
- options.interval_ms = crm_parse_interval_spec(optarg);
- return errno == 0;
+ return pcmk_parse_interval_spec(optarg,
+ &options.interval_ms) == pcmk_rc_ok;
}
static gboolean
@@ -461,9 +461,9 @@ generate_params(void)
if (rc != pcmk_rc_ok) {
return rc;
}
- if (!cli_config_update(&cib_xml_copy, NULL, FALSE)) {
- crm_err("Could not update CIB");
- return pcmk_rc_cib_corrupt;
+ rc = pcmk_update_configured_schema(&cib_xml_copy, false);
+ if (rc != pcmk_rc_ok) {
+ return rc;
}
// Calculate cluster status
@@ -472,7 +472,7 @@ generate_params(void)
crm_crit("Could not allocate scheduler data");
return ENOMEM;
}
- pe__set_working_set_flags(scheduler,
+ pcmk__set_scheduler_flags(scheduler,
pcmk_sched_no_counts|pcmk_sched_no_compat);
scheduler->input = cib_xml_copy;
scheduler->now = crm_time_new(NULL);
diff --git a/daemons/execd/execd_alerts.c b/daemons/execd/execd_alerts.c
index 5944d93..362f7a5 100644
--- a/daemons/execd/execd_alerts.c
+++ b/daemons/execd/execd_alerts.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2022 the Pacemaker project contributors
+ * Copyright 2016-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -17,7 +17,7 @@
#include <crm/common/ipc.h>
#include <crm/common/ipc_internal.h>
#include <crm/common/alerts_internal.h>
-#include <crm/msg_xml.h>
+#include <crm/common/xml.h>
#include "pacemaker-execd.h"
@@ -105,9 +105,11 @@ process_lrmd_alert_exec(pcmk__client_t *client, uint32_t id, xmlNode *request)
{
static int alert_sequence_no = 0;
- xmlNode *alert_xml = get_xpath_object("//" F_LRMD_ALERT, request, LOG_ERR);
- const char *alert_id = crm_element_value(alert_xml, F_LRMD_ALERT_ID);
- const char *alert_path = crm_element_value(alert_xml, F_LRMD_ALERT_PATH);
+ xmlNode *alert_xml = get_xpath_object("//" PCMK__XE_LRMD_ALERT, request,
+ LOG_ERR);
+ const char *alert_id = crm_element_value(alert_xml, PCMK__XA_LRMD_ALERT_ID);
+ const char *alert_path = crm_element_value(alert_xml,
+ PCMK__XA_LRMD_ALERT_PATH);
svc_action_t *action = NULL;
int alert_timeout = 0;
int rc = pcmk_ok;
@@ -116,13 +118,14 @@ process_lrmd_alert_exec(pcmk__client_t *client, uint32_t id, xmlNode *request)
if ((alert_id == NULL) || (alert_path == NULL) ||
(client == NULL) || (client->id == NULL)) { /* hint static analyzer */
- return -EINVAL;
+ rc = -EINVAL;
+ goto err;
}
if (draining_alerts) {
return pcmk_ok;
}
- crm_element_value_int(alert_xml, F_LRMD_TIMEOUT, &alert_timeout);
+ crm_element_value_int(alert_xml, PCMK__XA_LRMD_TIMEOUT, &alert_timeout);
crm_info("Executing alert %s for %s", alert_id, client->id);
@@ -130,20 +133,11 @@ process_lrmd_alert_exec(pcmk__client_t *client, uint32_t id, xmlNode *request)
pcmk__add_alert_key_int(params, PCMK__alert_key_node_sequence,
++alert_sequence_no);
- cb_data = calloc(1, sizeof(struct alert_cb_s));
- if (cb_data == NULL) {
- rc = -errno;
- goto err;
- }
+ cb_data = pcmk__assert_alloc(1, sizeof(struct alert_cb_s));
- /* coverity[deref_ptr] False Positive */
- cb_data->client_id = strdup(client->id);
- if (cb_data->client_id == NULL) {
- rc = -errno;
- goto err;
- }
+ cb_data->client_id = pcmk__str_copy(client->id);
- crm_element_value_int(request, F_LRMD_CALLID, &(cb_data->call_id));
+ crm_element_value_int(request, PCMK__XA_LRMD_CALLID, &(cb_data->call_id));
action = services_alert_create(alert_id, alert_path, alert_timeout, params,
alert_sequence_no, cb_data);
@@ -165,9 +159,7 @@ process_lrmd_alert_exec(pcmk__client_t *client, uint32_t id, xmlNode *request)
err:
if (cb_data) {
- if (cb_data->client_id) {
- free(cb_data->client_id);
- }
+ free(cb_data->client_id);
free(cb_data);
}
services_action_free(action);
diff --git a/daemons/execd/execd_commands.c b/daemons/execd/execd_commands.c
index cf4503a..6b1ded1 100644
--- a/daemons/execd/execd_commands.c
+++ b/daemons/execd/execd_commands.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2023 the Pacemaker project contributors
+ * Copyright 2012-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -28,7 +28,7 @@
#include <crm/common/mainloop.h>
#include <crm/common/ipc.h>
#include <crm/common/ipc_internal.h>
-#include <crm/msg_xml.h>
+#include <crm/common/xml.h>
#include "pacemaker-execd.h"
@@ -274,17 +274,17 @@ normalize_action_name(lrmd_rsc_t * rsc, const char *action)
static lrmd_rsc_t *
build_rsc_from_xml(xmlNode * msg)
{
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, msg, LOG_ERR);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, msg, LOG_ERR);
lrmd_rsc_t *rsc = NULL;
- rsc = calloc(1, sizeof(lrmd_rsc_t));
+ rsc = pcmk__assert_alloc(1, sizeof(lrmd_rsc_t));
- crm_element_value_int(msg, F_LRMD_CALLOPTS, &rsc->call_opts);
+ crm_element_value_int(msg, PCMK__XA_LRMD_CALLOPT, &rsc->call_opts);
- rsc->rsc_id = crm_element_value_copy(rsc_xml, F_LRMD_RSC_ID);
- rsc->class = crm_element_value_copy(rsc_xml, F_LRMD_CLASS);
- rsc->provider = crm_element_value_copy(rsc_xml, F_LRMD_PROVIDER);
- rsc->type = crm_element_value_copy(rsc_xml, F_LRMD_TYPE);
+ rsc->rsc_id = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_RSC_ID);
+ rsc->class = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_CLASS);
+ rsc->provider = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_PROVIDER);
+ rsc->type = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_TYPE);
rsc->work = mainloop_add_trigger(G_PRIORITY_HIGH, execute_resource_action,
rsc);
@@ -298,29 +298,33 @@ static lrmd_cmd_t *
create_lrmd_cmd(xmlNode *msg, pcmk__client_t *client)
{
int call_options = 0;
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, msg, LOG_ERR);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, msg, LOG_ERR);
lrmd_cmd_t *cmd = NULL;
- cmd = calloc(1, sizeof(lrmd_cmd_t));
+ cmd = pcmk__assert_alloc(1, sizeof(lrmd_cmd_t));
- crm_element_value_int(msg, F_LRMD_CALLOPTS, &call_options);
+ crm_element_value_int(msg, PCMK__XA_LRMD_CALLOPT, &call_options);
cmd->call_opts = call_options;
- cmd->client_id = strdup(client->id);
-
- crm_element_value_int(msg, F_LRMD_CALLID, &cmd->call_id);
- crm_element_value_ms(rsc_xml, F_LRMD_RSC_INTERVAL, &cmd->interval_ms);
- crm_element_value_int(rsc_xml, F_LRMD_TIMEOUT, &cmd->timeout);
- crm_element_value_int(rsc_xml, F_LRMD_RSC_START_DELAY, &cmd->start_delay);
+ cmd->client_id = pcmk__str_copy(client->id);
+
+ crm_element_value_int(msg, PCMK__XA_LRMD_CALLID, &cmd->call_id);
+ crm_element_value_ms(rsc_xml, PCMK__XA_LRMD_RSC_INTERVAL,
+ &cmd->interval_ms);
+ crm_element_value_int(rsc_xml, PCMK__XA_LRMD_TIMEOUT, &cmd->timeout);
+ crm_element_value_int(rsc_xml, PCMK__XA_LRMD_RSC_START_DELAY,
+ &cmd->start_delay);
cmd->timeout_orig = cmd->timeout;
- cmd->origin = crm_element_value_copy(rsc_xml, F_LRMD_ORIGIN);
- cmd->action = crm_element_value_copy(rsc_xml, F_LRMD_RSC_ACTION);
- cmd->userdata_str = crm_element_value_copy(rsc_xml, F_LRMD_RSC_USERDATA_STR);
- cmd->rsc_id = crm_element_value_copy(rsc_xml, F_LRMD_RSC_ID);
+ cmd->origin = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_ORIGIN);
+ cmd->action = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_RSC_ACTION);
+ cmd->userdata_str = crm_element_value_copy(rsc_xml,
+ PCMK__XA_LRMD_RSC_USERDATA_STR);
+ cmd->rsc_id = crm_element_value_copy(rsc_xml, PCMK__XA_LRMD_RSC_ID);
cmd->params = xml2list(rsc_xml);
- if (pcmk__str_eq(g_hash_table_lookup(cmd->params, "CRM_meta_on_fail"), "block", pcmk__str_casei)) {
+ if (pcmk__str_eq(g_hash_table_lookup(cmd->params, "CRM_meta_on_fail"),
+ PCMK_VALUE_BLOCK, pcmk__str_casei)) {
crm_debug("Setting flag to leave pid group on timeout and "
"only kill action pid for " PCMK__OP_FMT,
cmd->rsc_id, cmd->action, cmd->interval_ms);
@@ -535,11 +539,11 @@ schedule_lrmd_cmd(lrmd_rsc_t * rsc, lrmd_cmd_t * cmd)
static xmlNode *
create_lrmd_reply(const char *origin, int rc, int call_id)
{
- xmlNode *reply = create_xml_node(NULL, T_LRMD_REPLY);
+ xmlNode *reply = pcmk__xe_create(NULL, PCMK__XE_LRMD_REPLY);
- crm_xml_add(reply, F_LRMD_ORIGIN, origin);
- crm_xml_add_int(reply, F_LRMD_RC, rc);
- crm_xml_add_int(reply, F_LRMD_CALLID, call_id);
+ crm_xml_add(reply, PCMK__XA_LRMD_ORIGIN, origin);
+ crm_xml_add_int(reply, PCMK__XA_LRMD_RC, rc);
+ crm_xml_add_int(reply, PCMK__XA_LRMD_CALLID, call_id);
return reply;
}
@@ -614,41 +618,44 @@ send_cmd_complete_notify(lrmd_cmd_t * cmd)
cmd->last_notify_rc = cmd->result.exit_status;
cmd->last_notify_op_status = cmd->result.execution_status;
- notify = create_xml_node(NULL, T_LRMD_NOTIFY);
+ notify = pcmk__xe_create(NULL, PCMK__XE_LRMD_NOTIFY);
- crm_xml_add(notify, F_LRMD_ORIGIN, __func__);
- crm_xml_add_int(notify, F_LRMD_TIMEOUT, cmd->timeout);
- crm_xml_add_ms(notify, F_LRMD_RSC_INTERVAL, cmd->interval_ms);
- crm_xml_add_int(notify, F_LRMD_RSC_START_DELAY, cmd->start_delay);
- crm_xml_add_int(notify, F_LRMD_EXEC_RC, cmd->result.exit_status);
- crm_xml_add_int(notify, F_LRMD_OP_STATUS, cmd->result.execution_status);
- crm_xml_add_int(notify, F_LRMD_CALLID, cmd->call_id);
- crm_xml_add_int(notify, F_LRMD_RSC_DELETED, cmd->rsc_deleted);
+ crm_xml_add(notify, PCMK__XA_LRMD_ORIGIN, __func__);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_TIMEOUT, cmd->timeout);
+ crm_xml_add_ms(notify, PCMK__XA_LRMD_RSC_INTERVAL, cmd->interval_ms);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_RSC_START_DELAY, cmd->start_delay);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_EXEC_RC, cmd->result.exit_status);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_EXEC_OP_STATUS,
+ cmd->result.execution_status);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_CALLID, cmd->call_id);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_RSC_DELETED, cmd->rsc_deleted);
- crm_xml_add_ll(notify, F_LRMD_RSC_RUN_TIME,
+ crm_xml_add_ll(notify, PCMK__XA_LRMD_RUN_TIME,
(long long) cmd->epoch_last_run);
- crm_xml_add_ll(notify, F_LRMD_RSC_RCCHANGE_TIME,
+ crm_xml_add_ll(notify, PCMK__XA_LRMD_RCCHANGE_TIME,
(long long) cmd->epoch_rcchange);
#ifdef PCMK__TIME_USE_CGT
- crm_xml_add_int(notify, F_LRMD_RSC_EXEC_TIME, exec_time);
- crm_xml_add_int(notify, F_LRMD_RSC_QUEUE_TIME, queue_time);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_EXEC_TIME, exec_time);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_QUEUE_TIME, queue_time);
#endif
- crm_xml_add(notify, F_LRMD_OPERATION, LRMD_OP_RSC_EXEC);
- crm_xml_add(notify, F_LRMD_RSC_ID, cmd->rsc_id);
+ crm_xml_add(notify, PCMK__XA_LRMD_OP, LRMD_OP_RSC_EXEC);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_ID, cmd->rsc_id);
if(cmd->real_action) {
- crm_xml_add(notify, F_LRMD_RSC_ACTION, cmd->real_action);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_ACTION, cmd->real_action);
} else {
- crm_xml_add(notify, F_LRMD_RSC_ACTION, cmd->action);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_ACTION, cmd->action);
}
- crm_xml_add(notify, F_LRMD_RSC_USERDATA_STR, cmd->userdata_str);
- crm_xml_add(notify, F_LRMD_RSC_EXIT_REASON, cmd->result.exit_reason);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_USERDATA_STR, cmd->userdata_str);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_EXIT_REASON, cmd->result.exit_reason);
if (cmd->result.action_stderr != NULL) {
- crm_xml_add(notify, F_LRMD_RSC_OUTPUT, cmd->result.action_stderr);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_OUTPUT,
+ cmd->result.action_stderr);
} else if (cmd->result.action_stdout != NULL) {
- crm_xml_add(notify, F_LRMD_RSC_OUTPUT, cmd->result.action_stdout);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_OUTPUT,
+ cmd->result.action_stdout);
}
if (cmd->params) {
@@ -656,7 +663,7 @@ send_cmd_complete_notify(lrmd_cmd_t * cmd)
char *value = NULL;
GHashTableIter iter;
- xmlNode *args = create_xml_node(notify, XML_TAG_ATTRS);
+ xmlNode *args = pcmk__xe_create(notify, PCMK__XE_ATTRIBUTES);
g_hash_table_iter_init(&iter, cmd->params);
while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value)) {
@@ -684,18 +691,19 @@ send_generic_notify(int rc, xmlNode * request)
if (pcmk__ipc_client_count() != 0) {
int call_id = 0;
xmlNode *notify = NULL;
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, request, LOG_ERR);
- const char *rsc_id = crm_element_value(rsc_xml, F_LRMD_RSC_ID);
- const char *op = crm_element_value(request, F_LRMD_OPERATION);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, request,
+ LOG_ERR);
+ const char *rsc_id = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ID);
+ const char *op = crm_element_value(request, PCMK__XA_LRMD_OP);
- crm_element_value_int(request, F_LRMD_CALLID, &call_id);
+ crm_element_value_int(request, PCMK__XA_LRMD_CALLID, &call_id);
- notify = create_xml_node(NULL, T_LRMD_NOTIFY);
- crm_xml_add(notify, F_LRMD_ORIGIN, __func__);
- crm_xml_add_int(notify, F_LRMD_RC, rc);
- crm_xml_add_int(notify, F_LRMD_CALLID, call_id);
- crm_xml_add(notify, F_LRMD_OPERATION, op);
- crm_xml_add(notify, F_LRMD_RSC_ID, rsc_id);
+ notify = pcmk__xe_create(NULL, PCMK__XE_LRMD_NOTIFY);
+ crm_xml_add(notify, PCMK__XA_LRMD_ORIGIN, __func__);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_RC, rc);
+ crm_xml_add_int(notify, PCMK__XA_LRMD_CALLID, call_id);
+ crm_xml_add(notify, PCMK__XA_LRMD_OP, op);
+ crm_xml_add(notify, PCMK__XA_LRMD_RSC_ID, rsc_id);
pcmk__foreach_ipc_client(send_client_notify, notify);
@@ -778,9 +786,9 @@ notify_of_new_client(pcmk__client_t *new_client)
struct notify_new_client_data data;
data.new_client = new_client;
- data.notify = create_xml_node(NULL, T_LRMD_NOTIFY);
- crm_xml_add(data.notify, F_LRMD_ORIGIN, __func__);
- crm_xml_add(data.notify, F_LRMD_OPERATION, LRMD_OP_NEW_CLIENT);
+ data.notify = pcmk__xe_create(NULL, PCMK__XE_LRMD_NOTIFY);
+ crm_xml_add(data.notify, PCMK__XA_LRMD_ORIGIN, __func__);
+ crm_xml_add(data.notify, PCMK__XA_LRMD_OP, LRMD_OP_NEW_CLIENT);
pcmk__foreach_ipc_client(notify_one_client, &data);
free_xml(data.notify);
}
@@ -853,7 +861,7 @@ action_complete(svc_action_t * action)
*/
goagain = true;
cmd->real_action = cmd->action;
- cmd->action = strdup(PCMK_ACTION_MONITOR);
+ cmd->action = pcmk__str_copy(PCMK_ACTION_MONITOR);
} else if (cmd->real_action != NULL) {
// This is follow-up monitor to check whether start/stop completed
@@ -1479,23 +1487,33 @@ process_lrmd_signon(pcmk__client_t *client, xmlNode *request, int call_id,
{
int rc = pcmk_ok;
time_t now = time(NULL);
- const char *protocol_version = crm_element_value(request, F_LRMD_PROTOCOL_VERSION);
+ const char *protocol_version =
+ crm_element_value(request, PCMK__XA_LRMD_PROTOCOL_VERSION);
const char *start_state = pcmk__env_option(PCMK__ENV_NODE_START_STATE);
- if (compare_version(protocol_version, LRMD_MIN_PROTOCOL_VERSION) < 0) {
+ if (compare_version(protocol_version, LRMD_COMPATIBLE_PROTOCOL) < 0) {
crm_err("Cluster API version must be greater than or equal to %s, not %s",
- LRMD_MIN_PROTOCOL_VERSION, protocol_version);
+ LRMD_COMPATIBLE_PROTOCOL, protocol_version);
rc = -EPROTO;
}
- if (pcmk__xe_attr_is_true(request, F_LRMD_IS_IPC_PROVIDER)) {
+ if (pcmk__xe_attr_is_true(request, PCMK__XA_LRMD_IS_IPC_PROVIDER)) {
#ifdef PCMK__COMPILE_REMOTE
if ((client->remote != NULL)
&& pcmk_is_set(client->flags,
pcmk__client_tls_handshake_complete)) {
+ const char *op = crm_element_value(request, PCMK__XA_LRMD_OP);
// This is a remote connection from a cluster node's controller
ipc_proxy_add_provider(client);
+
+ /* If this was a register operation, also ask for new schema files but
+ * only if it's supported by the protocol version.
+ */
+ if (pcmk__str_eq(op, CRM_OP_REGISTER, pcmk__str_none) &&
+ LRMD_SUPPORTS_SCHEMA_XFER(protocol_version)) {
+ remoted_request_cib_schema_files();
+ }
} else {
rc = -EACCES;
}
@@ -1505,9 +1523,9 @@ process_lrmd_signon(pcmk__client_t *client, xmlNode *request, int call_id,
}
*reply = create_lrmd_reply(__func__, rc, call_id);
- crm_xml_add(*reply, F_LRMD_OPERATION, CRM_OP_REGISTER);
- crm_xml_add(*reply, F_LRMD_CLIENTID, client->id);
- crm_xml_add(*reply, F_LRMD_PROTOCOL_VERSION, LRMD_PROTOCOL_VERSION);
+ crm_xml_add(*reply, PCMK__XA_LRMD_OP, CRM_OP_REGISTER);
+ crm_xml_add(*reply, PCMK__XA_LRMD_CLIENTID, client->id);
+ crm_xml_add(*reply, PCMK__XA_LRMD_PROTOCOL_VERSION, LRMD_PROTOCOL_VERSION);
crm_xml_add_ll(*reply, PCMK__XA_UPTIME, now - start_time);
if (start_state) {
@@ -1542,8 +1560,9 @@ static xmlNode *
process_lrmd_get_rsc_info(xmlNode *request, int call_id)
{
int rc = pcmk_ok;
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, request, LOG_ERR);
- const char *rsc_id = crm_element_value(rsc_xml, F_LRMD_RSC_ID);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, request,
+ LOG_ERR);
+ const char *rsc_id = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ID);
xmlNode *reply = NULL;
lrmd_rsc_t *rsc = NULL;
@@ -1559,10 +1578,10 @@ process_lrmd_get_rsc_info(xmlNode *request, int call_id)
reply = create_lrmd_reply(__func__, rc, call_id);
if (rsc) {
- crm_xml_add(reply, F_LRMD_RSC_ID, rsc->rsc_id);
- crm_xml_add(reply, F_LRMD_CLASS, rsc->class);
- crm_xml_add(reply, F_LRMD_PROVIDER, rsc->provider);
- crm_xml_add(reply, F_LRMD_TYPE, rsc->type);
+ crm_xml_add(reply, PCMK__XA_LRMD_RSC_ID, rsc->rsc_id);
+ crm_xml_add(reply, PCMK__XA_LRMD_CLASS, rsc->class);
+ crm_xml_add(reply, PCMK__XA_LRMD_PROVIDER, rsc->provider);
+ crm_xml_add(reply, PCMK__XA_LRMD_TYPE, rsc->type);
}
return reply;
}
@@ -1573,8 +1592,9 @@ process_lrmd_rsc_unregister(pcmk__client_t *client, uint32_t id,
{
int rc = pcmk_ok;
lrmd_rsc_t *rsc = NULL;
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, request, LOG_ERR);
- const char *rsc_id = crm_element_value(rsc_xml, F_LRMD_RSC_ID);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, request,
+ LOG_ERR);
+ const char *rsc_id = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ID);
if (!rsc_id) {
return -ENODEV;
@@ -1604,8 +1624,9 @@ process_lrmd_rsc_exec(pcmk__client_t *client, uint32_t id, xmlNode *request)
{
lrmd_rsc_t *rsc = NULL;
lrmd_cmd_t *cmd = NULL;
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, request, LOG_ERR);
- const char *rsc_id = crm_element_value(rsc_xml, F_LRMD_RSC_ID);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, request,
+ LOG_ERR);
+ const char *rsc_id = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ID);
int call_id;
if (!rsc_id) {
@@ -1727,12 +1748,13 @@ cancel_all_recurring(lrmd_rsc_t * rsc, const char *client_id)
static int
process_lrmd_rsc_cancel(pcmk__client_t *client, uint32_t id, xmlNode *request)
{
- xmlNode *rsc_xml = get_xpath_object("//" F_LRMD_RSC, request, LOG_ERR);
- const char *rsc_id = crm_element_value(rsc_xml, F_LRMD_RSC_ID);
- const char *action = crm_element_value(rsc_xml, F_LRMD_RSC_ACTION);
+ xmlNode *rsc_xml = get_xpath_object("//" PCMK__XE_LRMD_RSC, request,
+ LOG_ERR);
+ const char *rsc_id = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ID);
+ const char *action = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ACTION);
guint interval_ms = 0;
- crm_element_value_ms(rsc_xml, F_LRMD_RSC_INTERVAL, &interval_ms);
+ crm_element_value_ms(rsc_xml, PCMK__XA_LRMD_RSC_INTERVAL, &interval_ms);
if (!rsc_id || !action) {
return -EINVAL;
@@ -1744,17 +1766,17 @@ process_lrmd_rsc_cancel(pcmk__client_t *client, uint32_t id, xmlNode *request)
static void
add_recurring_op_xml(xmlNode *reply, lrmd_rsc_t *rsc)
{
- xmlNode *rsc_xml = create_xml_node(reply, F_LRMD_RSC);
+ xmlNode *rsc_xml = pcmk__xe_create(reply, PCMK__XE_LRMD_RSC);
- crm_xml_add(rsc_xml, F_LRMD_RSC_ID, rsc->rsc_id);
+ crm_xml_add(rsc_xml, PCMK__XA_LRMD_RSC_ID, rsc->rsc_id);
for (GList *item = rsc->recurring_ops; item != NULL; item = item->next) {
lrmd_cmd_t *cmd = item->data;
- xmlNode *op_xml = create_xml_node(rsc_xml, T_LRMD_RSC_OP);
+ xmlNode *op_xml = pcmk__xe_create(rsc_xml, PCMK__XE_LRMD_RSC_OP);
- crm_xml_add(op_xml, F_LRMD_RSC_ACTION,
- (cmd->real_action? cmd->real_action : cmd->action));
- crm_xml_add_ms(op_xml, F_LRMD_RSC_INTERVAL, cmd->interval_ms);
- crm_xml_add_int(op_xml, F_LRMD_TIMEOUT, cmd->timeout_orig);
+ crm_xml_add(op_xml, PCMK__XA_LRMD_RSC_ACTION,
+ pcmk__s(cmd->real_action, cmd->action));
+ crm_xml_add_ms(op_xml, PCMK__XA_LRMD_RSC_INTERVAL, cmd->interval_ms);
+ crm_xml_add_int(op_xml, PCMK__XA_LRMD_TIMEOUT, cmd->timeout_orig);
}
}
@@ -1768,12 +1790,12 @@ process_lrmd_get_recurring(xmlNode *request, int call_id)
xmlNode *rsc_xml = NULL;
// Resource ID is optional
- rsc_xml = first_named_child(request, F_LRMD_CALLDATA);
+ rsc_xml = pcmk__xe_first_child(request, PCMK__XE_LRMD_CALLDATA, NULL, NULL);
if (rsc_xml) {
- rsc_xml = first_named_child(rsc_xml, F_LRMD_RSC);
+ rsc_xml = pcmk__xe_first_child(rsc_xml, PCMK__XE_LRMD_RSC, NULL, NULL);
}
if (rsc_xml) {
- rsc_id = crm_element_value(rsc_xml, F_LRMD_RSC_ID);
+ rsc_id = crm_element_value(rsc_xml, PCMK__XA_LRMD_RSC_ID);
}
// If resource ID is specified, resource must exist
@@ -1809,7 +1831,7 @@ process_lrmd_message(pcmk__client_t *client, uint32_t id, xmlNode *request)
{
int rc = pcmk_ok;
int call_id = 0;
- const char *op = crm_element_value(request, F_LRMD_OPERATION);
+ const char *op = crm_element_value(request, PCMK__XA_LRMD_OP);
int do_reply = 0;
int do_notify = 0;
xmlNode *reply = NULL;
@@ -1821,7 +1843,7 @@ process_lrmd_message(pcmk__client_t *client, uint32_t id, xmlNode *request)
bool allowed = pcmk_is_set(client->flags, pcmk__client_privileged);
crm_trace("Processing %s operation from %s", op, client->id);
- crm_element_value_int(request, F_LRMD_CALLID, &call_id);
+ crm_element_value_int(request, PCMK__XA_LRMD_CALLID, &call_id);
if (pcmk__str_eq(op, CRM_OP_IPC_FWD, pcmk__str_none)) {
#ifdef PCMK__COMPILE_REMOTE
@@ -1882,10 +1904,16 @@ process_lrmd_message(pcmk__client_t *client, uint32_t id, xmlNode *request)
do_reply = 1;
} else if (pcmk__str_eq(op, LRMD_OP_CHECK, pcmk__str_none)) {
if (allowed) {
- xmlNode *data = get_message_xml(request, F_LRMD_CALLDATA);
+ xmlNode *wrapper = pcmk__xe_first_child(request,
+ PCMK__XE_LRMD_CALLDATA,
+ NULL, NULL);
+ xmlNode *data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+
+ const char *timeout = NULL;
CRM_LOG_ASSERT(data != NULL);
- pcmk__valid_sbd_timeout(crm_element_value(data, F_LRMD_WATCHDOG));
+ timeout = crm_element_value(data, PCMK__XA_LRMD_WATCHDOG);
+ pcmk__valid_stonith_watchdog_timeout(timeout);
} else {
rc = -EACCES;
}
diff --git a/daemons/execd/pacemaker-execd.c b/daemons/execd/pacemaker-execd.c
index e7e30eb..926e278 100644
--- a/daemons/execd/pacemaker-execd.c
+++ b/daemons/execd/pacemaker-execd.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2023 the Pacemaker project contributors
+ * Copyright 2012-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -14,7 +14,7 @@
#include <sys/types.h>
#include <crm/crm.h>
-#include <crm/msg_xml.h>
+#include <crm/common/xml.h>
#include <crm/services.h>
#include <crm/common/cmdline_internal.h>
#include <crm/common/ipc.h>
@@ -89,9 +89,11 @@ get_stonith_connection(void)
stonith_api_delete(stonith_api);
stonith_api = NULL;
} else {
- stonith_api->cmds->register_notification(stonith_api,
- T_STONITH_NOTIFY_DISCONNECT,
- stonith_connection_destroy_cb);
+ stonith_api_operations_t *cmds = stonith_api->cmds;
+
+ cmds->register_notification(stonith_api,
+ PCMK__VALUE_ST_NOTIFY_DISCONNECT,
+ stonith_connection_destroy_cb);
}
}
return stonith_api;
@@ -102,7 +104,7 @@ lrmd_ipc_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
{
crm_trace("Connection %p", c);
if (pcmk__new_client(c, uid, gid) == NULL) {
- return -EIO;
+ return -ENOMEM;
}
return 0;
}
@@ -141,12 +143,13 @@ lrmd_ipc_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
}
if (!client->name) {
- const char *value = crm_element_value(request, F_LRMD_CLIENTNAME);
+ const char *value = crm_element_value(request,
+ PCMK__XA_LRMD_CLIENTNAME);
if (value == NULL) {
client->name = pcmk__itoa(pcmk__client_pid(c));
} else {
- client->name = strdup(value);
+ client->name = pcmk__str_copy(value);
}
}
@@ -155,9 +158,9 @@ lrmd_ipc_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
lrmd_call_id = 1;
}
- crm_xml_add(request, F_LRMD_CLIENTID, client->id);
- crm_xml_add(request, F_LRMD_CLIENTNAME, client->name);
- crm_xml_add_int(request, F_LRMD_CALLID, lrmd_call_id);
+ crm_xml_add(request, PCMK__XA_LRMD_CLIENTID, client->id);
+ crm_xml_add(request, PCMK__XA_LRMD_CLIENTNAME, client->name);
+ crm_xml_add_int(request, PCMK__XA_LRMD_CALLID, lrmd_call_id);
process_lrmd_message(client, id, request);
@@ -281,11 +284,7 @@ static gboolean
lrmd_exit(gpointer data)
{
crm_info("Terminating with %d clients", pcmk__ipc_client_count());
- if (stonith_api) {
- stonith_api->cmds->remove_notification(stonith_api, T_STONITH_NOTIFY_DISCONNECT);
- stonith_api->cmds->disconnect(stonith_api);
- stonith_api_delete(stonith_api);
- }
+ stonith_api_delete(stonith_api);
if (ipcs) {
mainloop_del_ipc_server(ipcs);
}
@@ -443,19 +442,23 @@ main(int argc, char **argv, char **envp)
GError *error = NULL;
GOptionGroup *output_group = NULL;
- pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
-#ifdef PCMK__COMPILE_REMOTE
- gchar **processed_args = pcmk__cmdline_preproc(argv, "lp");
-#else
- gchar **processed_args = pcmk__cmdline_preproc(argv, "l");
-#endif // PCMK__COMPILE_REMOTE
- GOptionContext *context = build_arg_context(args, &output_group);
+ pcmk__common_args_t *args = NULL;
+ gchar **processed_args = NULL;
+ GOptionContext *context = NULL;
#ifdef PCMK__COMPILE_REMOTE
// If necessary, create PID 1 now before any file descriptors are opened
remoted_spawn_pidone(argc, argv, envp);
#endif
+ args = pcmk__new_common_args(SUMMARY);
+#ifdef PCMK__COMPILE_REMOTE
+ processed_args = pcmk__cmdline_preproc(argv, "lp");
+#else
+ processed_args = pcmk__cmdline_preproc(argv, "l");
+#endif // PCMK__COMPILE_REMOTE
+ context = build_arg_context(args, &output_group);
+
crm_log_preinit(EXECD_NAME, argc, argv);
pcmk__register_formats(output_group, formats);
@@ -495,7 +498,7 @@ main(int argc, char **argv, char **envp)
// ocf_log() (in resource-agents) uses the capitalized env options below
option = pcmk__env_option(PCMK__ENV_LOGFACILITY);
- if (!pcmk__str_eq(option, PCMK__VALUE_NONE,
+ if (!pcmk__str_eq(option, PCMK_VALUE_NONE,
pcmk__str_casei|pcmk__str_null_matches)
&& !pcmk__str_eq(option, "/dev/null", pcmk__str_none)) {
@@ -503,7 +506,7 @@ main(int argc, char **argv, char **envp)
}
option = pcmk__env_option(PCMK__ENV_LOGFILE);
- if (!pcmk__str_eq(option, PCMK__VALUE_NONE,
+ if (!pcmk__str_eq(option, PCMK_VALUE_NONE,
pcmk__str_casei|pcmk__str_null_matches)) {
pcmk__set_env_option("LOGFILE", option, true);
diff --git a/daemons/execd/pacemaker-execd.h b/daemons/execd/pacemaker-execd.h
index 9c1d173..6fb8ef4 100644
--- a/daemons/execd/pacemaker-execd.h
+++ b/daemons/execd/pacemaker-execd.h
@@ -101,6 +101,7 @@ void ipc_proxy_forward_client(pcmk__client_t *client, xmlNode *xml);
pcmk__client_t *ipc_proxy_get_provider(void);
int ipc_proxy_shutdown_req(pcmk__client_t *ipc_proxy);
void remoted_spawn_pidone(int argc, char **argv, char **envp);
+void remoted_request_cib_schema_files(void);
#endif
int process_lrmd_alert_exec(pcmk__client_t *client, uint32_t id,
diff --git a/daemons/execd/remoted_pidone.c b/daemons/execd/remoted_pidone.c
index 08271bf..0a6c251 100644
--- a/daemons/execd/remoted_pidone.c
+++ b/daemons/execd/remoted_pidone.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2023 the Pacemaker project contributors
+ * Copyright 2017-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -25,7 +25,7 @@ static pid_t main_pid = 0;
static void
sigdone(void)
{
- exit(CRM_EX_OK);
+ crm_exit(CRM_EX_OK);
}
static void
@@ -44,9 +44,9 @@ sigreap(void)
if (pid == main_pid) {
/* Exit when pacemaker-remote exits and use the same return code */
if (WIFEXITED(status)) {
- exit(WEXITSTATUS(status));
+ crm_exit(WEXITSTATUS(status));
}
- exit(CRM_EX_ERROR);
+ crm_exit(CRM_EX_ERROR);
}
} while (pid > 0);
}
@@ -203,7 +203,7 @@ remoted_spawn_pidone(int argc, char **argv, char **envp)
* from /etc/pacemaker/pcmk-init.env, which could be useful for testing or
* containers with a custom PID 1 script that launches pacemaker-remoted.
*/
- const char *pid1 = "default";
+ const char *pid1 = PCMK_VALUE_DEFAULT;
if (getpid() != 1) {
pid1 = pcmk__env_option(PCMK__ENV_REMOTE_PID1);
diff --git a/daemons/execd/remoted_proxy.c b/daemons/execd/remoted_proxy.c
index 62c8c3a..40dfdc6 100644
--- a/daemons/execd/remoted_proxy.c
+++ b/daemons/execd/remoted_proxy.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2022 the Pacemaker project contributors
+ * Copyright 2012-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -14,7 +14,7 @@
#include "pacemaker-execd.h"
#include <crm/crm.h>
-#include <crm/msg_xml.h>
+#include <crm/common/xml.h>
#include <crm/services.h>
#include <crm/common/mainloop.h>
#include <crm/common/ipc.h>
@@ -81,12 +81,12 @@ ipc_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid, const char *ipc
*/
client = pcmk__new_client(c, uid, gid);
if (client == NULL) {
- return -EREMOTEIO;
+ return -ENOMEM;
}
/* This ipc client is bound to a single ipc provider. If the
* provider goes away, this client is disconnected */
- client->userdata = strdup(ipc_proxy->id);
+ client->userdata = pcmk__str_copy(ipc_proxy->id);
client->name = crm_strdup_printf("proxy-%s-%d-%.8s", ipc_channel, client->pid, client->id);
/* Allow remote executor to distinguish between proxied local clients and
@@ -96,10 +96,10 @@ ipc_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid, const char *ipc
g_hash_table_insert(ipc_clients, client->id, client);
- msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
- crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_NEW);
- crm_xml_add(msg, F_LRMD_IPC_IPC_SERVER, ipc_channel);
- crm_xml_add(msg, F_LRMD_IPC_SESSION, client->id);
+ msg = pcmk__xe_create(NULL, PCMK__XE_LRMD_IPC_PROXY);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_OP, LRMD_IPC_OP_NEW);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_SERVER, ipc_channel);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_SESSION, client->id);
lrmd_server_send_notify(ipc_proxy, msg);
free_xml(msg);
crm_debug("Accepted IPC proxy connection (session ID %s) "
@@ -117,7 +117,7 @@ crmd_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
static int32_t
attrd_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
{
- return ipc_proxy_accept(c, uid, gid, T_ATTRD);
+ return ipc_proxy_accept(c, uid, gid, PCMK__VALUE_ATTRD);
}
static int32_t
@@ -147,9 +147,13 @@ cib_proxy_accept_ro(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
void
ipc_proxy_forward_client(pcmk__client_t *ipc_proxy, xmlNode *xml)
{
- const char *session = crm_element_value(xml, F_LRMD_IPC_SESSION);
- const char *msg_type = crm_element_value(xml, F_LRMD_IPC_OP);
- xmlNode *msg = get_message_xml(xml, F_LRMD_IPC_MSG);
+ const char *session = crm_element_value(xml, PCMK__XA_LRMD_IPC_SESSION);
+ const char *msg_type = crm_element_value(xml, PCMK__XA_LRMD_IPC_OP);
+
+ xmlNode *wrapper = pcmk__xe_first_child(xml, PCMK__XE_LRMD_IPC_MSG, NULL,
+ NULL);
+ xmlNode *msg = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
+
pcmk__client_t *ipc_client;
int rc = pcmk_rc_ok;
@@ -169,9 +173,9 @@ ipc_proxy_forward_client(pcmk__client_t *ipc_proxy, xmlNode *xml)
ipc_client = pcmk__find_client_by_id(session);
if (ipc_client == NULL) {
- xmlNode *msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
- crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_DESTROY);
- crm_xml_add(msg, F_LRMD_IPC_SESSION, session);
+ xmlNode *msg = pcmk__xe_create(NULL, PCMK__XE_LRMD_IPC_PROXY);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_OP, LRMD_IPC_OP_DESTROY);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_SESSION, session);
lrmd_server_send_notify(ipc_proxy, msg);
free_xml(msg);
return;
@@ -198,7 +202,7 @@ ipc_proxy_forward_client(pcmk__client_t *ipc_proxy, xmlNode *xml)
} else if (pcmk__str_eq(msg_type, LRMD_IPC_OP_RESPONSE, pcmk__str_casei)) {
int msg_id = 0;
- crm_element_value_int(xml, F_LRMD_IPC_MSG_ID, &msg_id);
+ crm_element_value_int(xml, PCMK__XA_LRMD_IPC_MSG_ID, &msg_id);
crm_trace("Sending response to %d - %s", ipc_client->request_id, ipc_client->id);
rc = pcmk__ipc_send_xml(ipc_client, msg_id, msg, FALSE);
@@ -225,6 +229,7 @@ ipc_proxy_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
uint32_t flags = 0;
pcmk__client_t *client = pcmk__find_client(c);
pcmk__client_t *ipc_proxy = pcmk__find_client_by_id(client->userdata);
+ xmlNode *wrapper = NULL;
xmlNode *request = NULL;
xmlNode *msg = NULL;
@@ -263,18 +268,22 @@ ipc_proxy_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
pcmk__set_ipc_flags(flags, pcmk__client_name(client), crm_ipc_proxied);
client->request_id = id;
- msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
- crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_REQUEST);
- crm_xml_add(msg, F_LRMD_IPC_SESSION, client->id);
- crm_xml_add(msg, F_LRMD_IPC_CLIENT, pcmk__client_name(client));
- crm_xml_add(msg, F_LRMD_IPC_USER, client->user);
- crm_xml_add_int(msg, F_LRMD_IPC_MSG_ID, id);
- crm_xml_add_int(msg, F_LRMD_IPC_MSG_FLAGS, flags);
- add_message_xml(msg, F_LRMD_IPC_MSG, request);
+ msg = pcmk__xe_create(NULL, PCMK__XE_LRMD_IPC_PROXY);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_OP, LRMD_IPC_OP_REQUEST);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_SESSION, client->id);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_CLIENT, pcmk__client_name(client));
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_USER, client->user);
+ crm_xml_add_int(msg, PCMK__XA_LRMD_IPC_MSG_ID, id);
+ crm_xml_add_int(msg, PCMK__XA_LRMD_IPC_MSG_FLAGS, flags);
+
+ wrapper = pcmk__xe_create(msg, PCMK__XE_LRMD_IPC_MSG);
+
+ pcmk__xml_copy(wrapper, request);
+
lrmd_server_send_notify(ipc_proxy, msg);
+
free_xml(request);
free_xml(msg);
-
return 0;
}
@@ -289,15 +298,15 @@ ipc_proxy_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
int
ipc_proxy_shutdown_req(pcmk__client_t *ipc_proxy)
{
- xmlNode *msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
+ xmlNode *msg = pcmk__xe_create(NULL, PCMK__XE_LRMD_IPC_PROXY);
int rc;
- crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_SHUTDOWN_REQ);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_OP, LRMD_IPC_OP_SHUTDOWN_REQ);
/* We don't really have a session, but the controller needs this attribute
* to recognize this as proxy communication.
*/
- crm_xml_add(msg, F_LRMD_IPC_SESSION, "0");
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_SESSION, "0");
rc = (lrmd_server_send_notify(ipc_proxy, msg) != pcmk_rc_ok)? -1 : 0;
free_xml(msg);
@@ -319,9 +328,9 @@ ipc_proxy_closed(qb_ipcs_connection_t * c)
crm_trace("Connection %p", c);
if (ipc_proxy) {
- xmlNode *msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
- crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_DESTROY);
- crm_xml_add(msg, F_LRMD_IPC_SESSION, client->id);
+ xmlNode *msg = pcmk__xe_create(NULL, PCMK__XE_LRMD_IPC_PROXY);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_OP, LRMD_IPC_OP_DESTROY);
+ crm_xml_add(msg, PCMK__XA_LRMD_IPC_SESSION, client->id);
lrmd_server_send_notify(ipc_proxy, msg);
free_xml(msg);
}
diff --git a/daemons/execd/remoted_schemas.c b/daemons/execd/remoted_schemas.c
new file mode 100644
index 0000000..f0ec068
--- /dev/null
+++ b/daemons/execd/remoted_schemas.c
@@ -0,0 +1,286 @@
+/*
+ * Copyright 2023-2024 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+#include <ftw.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include <crm/cib.h>
+#include <crm/cib/cib_types.h>
+#include <crm/cib/internal.h>
+#include <crm/crm.h>
+#include <crm/common/mainloop.h>
+#include <crm/common/xml.h>
+
+#include "pacemaker-execd.h"
+
+static pid_t schema_fetch_pid = 0;
+
+static int
+rm_files(const char *pathname, const struct stat *sbuf, int type, struct FTW *ftwb)
+{
+ /* Don't delete PCMK__REMOTE_SCHEMA_DIR . */
+ if (ftwb->level == 0) {
+ return 0;
+ }
+
+ if (remove(pathname) != 0) {
+ int rc = errno;
+ crm_err("Could not remove %s: %s", pathname, pcmk_rc_str(rc));
+ return -1;
+ }
+
+ return 0;
+}
+
+static void
+clean_up_extra_schema_files(void)
+{
+ const char *remote_schema_dir = pcmk__remote_schema_dir();
+ struct stat sb;
+ int rc;
+
+ rc = stat(remote_schema_dir, &sb);
+
+ if (rc == -1) {
+ if (errno == ENOENT) {
+ /* If the directory doesn't exist, try to make it first. */
+ if (mkdir(remote_schema_dir, 0755) != 0) {
+ rc = errno;
+ crm_err("Could not create directory for schemas: %s",
+ pcmk_rc_str(rc));
+ }
+
+ } else {
+ rc = errno;
+ crm_err("Could not create directory for schemas: %s",
+ pcmk_rc_str(rc));
+ }
+
+ } else if (!S_ISDIR(sb.st_mode)) {
+ /* If something exists with the same name that's not a directory, that's
+ * an error.
+ */
+ crm_err("%s already exists but is not a directory", remote_schema_dir);
+
+ } else {
+ /* It's a directory - clear it out so we can download potentially new
+ * schema files.
+ */
+ rc = nftw(remote_schema_dir, rm_files, 10, FTW_DEPTH|FTW_MOUNT|FTW_PHYS);
+
+ if (rc != 0) {
+ crm_err("Could not remove %s: %s", remote_schema_dir, pcmk_rc_str(rc));
+ }
+ }
+}
+
+static void
+write_extra_schema_file(xmlNode *xml, void *user_data)
+{
+ const char *remote_schema_dir = pcmk__remote_schema_dir();
+ const char *file = NULL;
+ char *path = NULL;
+ int rc;
+
+ file = crm_element_value(xml, PCMK_XA_PATH);
+ if (file == NULL) {
+ crm_warn("No destination path given in schema request");
+ return;
+ }
+
+ path = crm_strdup_printf("%s/%s", remote_schema_dir, file);
+
+ /* The schema is a CDATA node, which is a child of the <file> node. Traverse
+ * all children and look for the first CDATA child. There can't be more than
+ * one because we only have one file attribute on the parent.
+ */
+ for (xmlNode *child = xml->children; child != NULL; child = child->next) {
+ FILE *stream = NULL;
+
+ if (child->type != XML_CDATA_SECTION_NODE) {
+ continue;
+ }
+
+ stream = fopen(path, "w+");
+ if (stream == NULL) {
+ crm_warn("Could not write schema file %s: %s", path, strerror(errno));
+ } else {
+ rc = fprintf(stream, "%s", child->content);
+
+ if (rc < 0) {
+ crm_warn("Could not write schema file %s: %s", path, strerror(errno));
+ }
+
+ fclose(stream);
+ }
+
+ break;
+ }
+
+ free(path);
+}
+
+static void
+get_schema_files(void)
+{
+ int rc = pcmk_rc_ok;
+ cib_t *cib = NULL;
+ xmlNode *reply;
+
+ cib = cib_new();
+ if (cib == NULL) {
+ _exit(ENOTCONN);
+ }
+
+ rc = cib->cmds->signon(cib, crm_system_name, cib_query);
+ if (rc != pcmk_ok) {
+ crm_err("Could not connect to the CIB manager: %s", pcmk_strerror(rc));
+ _exit(pcmk_rc2exitc(rc));
+ }
+
+ rc = cib->cmds->fetch_schemas(cib, &reply, pcmk__highest_schema_name(),
+ cib_sync_call);
+ if (rc != pcmk_ok) {
+ crm_err("Could not get schema files: %s", pcmk_strerror(rc));
+ rc = pcmk_legacy2rc(rc);
+
+ } else if (reply->children != NULL) {
+ /* The returned document looks something like this:
+ * <cib_command>
+ * <cib_calldata>
+ * <schemas>
+ * <schema version="pacemaker-1.1">
+ * <file path="foo-1.1">
+ * </file>
+ * <file path="bar-1.1">
+ * </file>
+ * ...
+ * </schema>
+ * <schema version="pacemaker-1.2">
+ * </schema>
+ * ...
+ * </schemas>
+ * </cib_calldata>
+ * </cib_command>
+ *
+ * All the <schemas> and <schema> tags are really just there for organizing
+ * the XML a little better. What we really care about are the <file> nodes,
+ * and specifically the path attributes and the CDATA children (not shown)
+ * of each. We can use an xpath query to reach down and get all the <file>
+ * nodes at once.
+ *
+ * If we already have the latest schema version, or we asked for one later
+ * than what the cluster supports, we'll get back an empty <schemas> node,
+ * so all this will continue to work. It just won't do anything.
+ */
+ crm_foreach_xpath_result(reply, "//" PCMK_XA_FILE,
+ write_extra_schema_file, NULL);
+ }
+
+ free_xml(reply);
+ cib__clean_up_connection(&cib);
+ _exit(pcmk_rc2exitc(rc));
+}
+
+/* Load any additional schema files when the child is finished fetching and
+ * saving them to disk.
+ */
+static void
+get_schema_files_complete(mainloop_child_t *p, pid_t pid, int core, int signo, int exitcode)
+{
+ const char *errmsg = "Could not load additional schema files";
+
+ if ((signo == 0) && (exitcode == 0)) {
+ const char *remote_schema_dir = pcmk__remote_schema_dir();
+
+ /* Don't just crm_schema_init here because that will load the base
+ * schemas again too. Instead just load the things we fetched.
+ */
+ pcmk__load_schemas_from_dir(remote_schema_dir);
+ pcmk__sort_schemas();
+ crm_info("Fetching extra schema files completed successfully");
+
+ } else {
+ if (signo == 0) {
+ crm_err("%s: process %d exited %d", errmsg, (int) pid, exitcode);
+
+ } else {
+ crm_err("%s: process %d terminated with signal %d (%s)%s",
+ errmsg, (int) pid, signo, strsignal(signo),
+ (core? " and dumped core" : ""));
+ }
+
+ /* Clean up any incomplete schema data we might have been downloading when
+ * the process timed out or crashed. We don't need to do any extra cleanup
+ * because we never loaded the extra schemas, and we don't need to call
+ * crm_schema_init because that was called in remoted_request_cib_schema_files
+ * before this function.
+ */
+ clean_up_extra_schema_files();
+ }
+}
+
+void
+remoted_request_cib_schema_files(void)
+{
+ pid_t pid;
+ int rc;
+
+ /* If a previous schema-fetch process is still running when we're called
+ * again, it's hung. Attempt to kill it before cleaning up the extra
+ * directory.
+ */
+ if (schema_fetch_pid != 0) {
+ if (mainloop_child_kill(schema_fetch_pid) == FALSE) {
+ crm_warn("Unable to kill pre-existing schema-fetch process");
+ return;
+ }
+
+ schema_fetch_pid = 0;
+ }
+
+ /* Clean up any extra schema files we downloaded from a previous cluster
+ * connection. After the files are gone, we need to wipe them from
+ * known_schemas, but there's no opposite operation for add_schema().
+ *
+ * Instead, unload all the schemas. This means we'll also forget about all
+ * installed schemas as well, which means that pcmk__highest_schema_name()
+ * would fail. So we need to load the base schemas right now.
+ */
+ clean_up_extra_schema_files();
+ crm_schema_cleanup();
+ crm_schema_init();
+
+ crm_info("Fetching extra schema files from cluster");
+ pid = fork();
+
+ switch (pid) {
+ case -1: {
+ rc = errno;
+ crm_warn("Could not spawn process to get schema files: %s", pcmk_rc_str(rc));
+ break;
+ }
+
+ case 0:
+ /* child */
+ get_schema_files();
+ break;
+
+ default:
+ /* parent */
+ schema_fetch_pid = pid;
+ mainloop_child_add_with_flags(pid, 5 * 60 * 1000, "schema-fetch", NULL,
+ mainloop_leave_pid_group,
+ get_schema_files_complete);
+ break;
+ }
+}
diff --git a/daemons/execd/remoted_tls.c b/daemons/execd/remoted_tls.c
index 23a2dcf..e98991f 100644
--- a/daemons/execd/remoted_tls.c
+++ b/daemons/execd/remoted_tls.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2023 the Pacemaker project contributors
+ * Copyright 2012-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
@@ -13,10 +13,8 @@
#include <unistd.h>
#include <crm/crm.h>
-#include <crm/msg_xml.h>
-#include <crm/crm.h>
-#include <crm/msg_xml.h>
#include <crm/common/mainloop.h>
+#include <crm/common/xml.h>
#include <crm/common/remote_internal.h>
#include <crm/lrmd_internal.h>
@@ -111,14 +109,11 @@ lrmd_remote_client_msg(gpointer data)
request = pcmk__remote_message_xml(client->remote);
while (request) {
- crm_element_value_int(request, F_LRMD_REMOTE_MSG_ID, &id);
+ crm_element_value_int(request, PCMK__XA_LRMD_REMOTE_MSG_ID, &id);
crm_trace("Processing remote client request %d", id);
if (!client->name) {
- const char *value = crm_element_value(request, F_LRMD_CLIENTNAME);
-
- if (value) {
- client->name = strdup(value);
- }
+ client->name = crm_element_value_copy(request,
+ PCMK__XA_LRMD_CLIENTNAME);
}
lrmd_call_id++;
@@ -126,9 +121,9 @@ lrmd_remote_client_msg(gpointer data)
lrmd_call_id = 1;
}
- crm_xml_add(request, F_LRMD_CLIENTID, client->id);
- crm_xml_add(request, F_LRMD_CLIENTNAME, client->name);
- crm_xml_add_int(request, F_LRMD_CALLID, lrmd_call_id);
+ crm_xml_add(request, PCMK__XA_LRMD_CLIENTID, client->id);
+ crm_xml_add(request, PCMK__XA_LRMD_CLIENTNAME, client->name);
+ crm_xml_add_int(request, PCMK__XA_LRMD_CALLID, lrmd_call_id);
process_lrmd_message(client, id, request);
free_xml(request);
@@ -175,6 +170,7 @@ lrmd_remote_client_destroy(gpointer user_data)
gnutls_bye(*client->remote->tls_session, GNUTLS_SHUT_RDWR);
gnutls_deinit(*client->remote->tls_session);
gnutls_free(client->remote->tls_session);
+ client->remote->tls_session = NULL;
close(csock);
}
@@ -229,7 +225,7 @@ lrmd_remote_listen(gpointer data)
}
new_client = pcmk__new_unauth_client(NULL);
- new_client->remote = calloc(1, sizeof(pcmk__remote_t));
+ new_client->remote = pcmk__assert_alloc(1, sizeof(pcmk__remote_t));
pcmk__set_client_flags(new_client, pcmk__client_tls);
new_client->remote->tls_session = session;