diff options
Diffstat (limited to 'lib/services')
-rw-r--r-- | lib/services/Makefile.am | 13 | ||||
-rw-r--r-- | lib/services/dbus.c | 2 | ||||
-rw-r--r-- | lib/services/services.c | 8 | ||||
-rw-r--r-- | lib/services/services_linux.c | 22 | ||||
-rw-r--r-- | lib/services/services_lsb.c | 5 | ||||
-rw-r--r-- | lib/services/services_nagios.c | 4 | ||||
-rw-r--r-- | lib/services/systemd.c | 26 | ||||
-rw-r--r-- | lib/services/upstart.c | 21 |
8 files changed, 57 insertions, 44 deletions
diff --git a/lib/services/Makefile.am b/lib/services/Makefile.am index a7e10c9..5a19003 100644 --- a/lib/services/Makefile.am +++ b/lib/services/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2012-2021 the Pacemaker project contributors +# Copyright 2012-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -12,19 +12,18 @@ MAINTAINERCLEANFILES = Makefile.in AM_CPPFLAGS = -I$(top_srcdir)/include lib_LTLIBRARIES = libcrmservice.la -noinst_HEADERS = pcmk-dbus.h upstart.h systemd.h \ - services_lsb.h services_nagios.h \ - services_ocf.h \ - services_private.h +noinst_HEADERS = $(wildcard *.h) -libcrmservice_la_LDFLAGS = -version-info 31:2:3 +libcrmservice_la_LDFLAGS = -version-info 32:0:4 libcrmservice_la_CFLAGS = libcrmservice_la_CFLAGS += $(CFLAGS_HARDENED_LIB) libcrmservice_la_LDFLAGS += $(LDFLAGS_HARDENED_LIB) -libcrmservice_la_LIBADD = $(top_builddir)/lib/common/libcrmcommon.la $(DBUS_LIBS) +libcrmservice_la_LIBADD = $(top_builddir)/lib/common/libcrmcommon.la \ + $(DBUS_LIBS) +## Library sources (*must* use += format for bumplibs) libcrmservice_la_SOURCES = services.c libcrmservice_la_SOURCES += services_linux.c libcrmservice_la_SOURCES += services_lsb.c diff --git a/lib/services/dbus.c b/lib/services/dbus.c index f052c0a..8a517d2 100644 --- a/lib/services/dbus.c +++ b/lib/services/dbus.c @@ -594,6 +594,8 @@ handle_query_result(DBusMessage *reply, struct property_query *data) DBusMessageIter variant_iter; DBusBasicValue value; + dbus_error_init(&error); + // First, check if the reply contains an error if (pcmk_dbus_find_error((void*)&error, reply, &error)) { crm_err("DBus query for %s property '%s' failed: %s", diff --git a/lib/services/services.c b/lib/services/services.c index b60d8bd..e438443 100644 --- a/lib/services/services.c +++ b/lib/services/services.c @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 the Pacemaker project contributors + * Copyright 2010-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -233,8 +233,8 @@ copy_action_arguments(svc_action_t *op, uint32_t ra_caps, const char *name, } if (pcmk_is_set(ra_caps, pcmk_ra_cap_status) - && pcmk__str_eq(action, "monitor", pcmk__str_casei)) { - action = "status"; + && pcmk__str_eq(action, PCMK_ACTION_MONITOR, pcmk__str_casei)) { + action = PCMK_ACTION_STATUS; } op->action = strdup(action); if (op->action == NULL) { @@ -1028,7 +1028,7 @@ services_action_sync(svc_action_t * op) op->synchronous = true; - if (pcmk__str_eq(op->action, "meta-data", pcmk__str_casei)) { + if (pcmk__str_eq(op->action, PCMK_ACTION_META_DATA, pcmk__str_casei)) { /* Synchronous meta-data operations are handled specially. Since most * resource classes don't provide any meta-data, it has to be * synthesized from available information about the agent. diff --git a/lib/services/services_linux.c b/lib/services/services_linux.c index fb12f73..c7792f0 100644 --- a/lib/services/services_linux.c +++ b/lib/services/services_linux.c @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 the Pacemaker project contributors + * Copyright 2010-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -725,7 +725,7 @@ services__generic_error(const svc_action_t *op) } if (pcmk__str_eq(op->standard, PCMK_RESOURCE_CLASS_LSB, pcmk__str_casei) - && pcmk__str_eq(op->action, "status", pcmk__str_casei)) { + && pcmk__str_eq(op->action, PCMK_ACTION_STATUS, pcmk__str_casei)) { return PCMK_LSB_STATUS_UNKNOWN; } @@ -760,7 +760,7 @@ services__not_installed_error(const svc_action_t *op) } if (pcmk__str_eq(op->standard, PCMK_RESOURCE_CLASS_LSB, pcmk__str_casei) - && pcmk__str_eq(op->action, "status", pcmk__str_casei)) { + && pcmk__str_eq(op->action, PCMK_ACTION_STATUS, pcmk__str_casei)) { return PCMK_LSB_STATUS_NOT_INSTALLED; } @@ -795,7 +795,7 @@ services__authorization_error(const svc_action_t *op) } if (pcmk__str_eq(op->standard, PCMK_RESOURCE_CLASS_LSB, pcmk__str_casei) - && pcmk__str_eq(op->action, "status", pcmk__str_casei)) { + && pcmk__str_eq(op->action, PCMK_ACTION_STATUS, pcmk__str_casei)) { return PCMK_LSB_STATUS_INSUFFICIENT_PRIV; } @@ -831,7 +831,7 @@ services__configuration_error(const svc_action_t *op, bool is_fatal) } if (pcmk__str_eq(op->standard, PCMK_RESOURCE_CLASS_LSB, pcmk__str_casei) - && pcmk__str_eq(op->action, "status", pcmk__str_casei)) { + && pcmk__str_eq(op->action, PCMK_ACTION_STATUS, pcmk__str_casei)) { return PCMK_LSB_NOT_CONFIGURED; } @@ -954,7 +954,7 @@ action_launch_child(svc_action_t *op) #if SUPPORT_CIBSECRETS rc = pcmk__substitute_secrets(op->rsc, op->params); if (rc != pcmk_rc_ok) { - if (pcmk__str_eq(op->action, "stop", pcmk__str_casei)) { + if (pcmk__str_eq(op->action, PCMK_ACTION_STOP, pcmk__str_casei)) { crm_info("Proceeding with stop operation for %s " "despite being unable to load CIB secrets (%s)", op->rsc, pcmk_rc_str(rc)); @@ -1178,7 +1178,7 @@ services__execute_file(svc_action_t *op) if (stat(op->opaque->exec, &st) != 0) { rc = errno; crm_info("Cannot execute '%s': %s " CRM_XS " stat rc=%d", - op->opaque->exec, pcmk_strerror(rc), rc); + op->opaque->exec, pcmk_rc_str(rc), rc); services__handle_exec_error(op, rc); goto done; } @@ -1186,7 +1186,7 @@ services__execute_file(svc_action_t *op) if (pipe(stdout_fd) < 0) { rc = errno; crm_info("Cannot execute '%s': %s " CRM_XS " pipe(stdout) rc=%d", - op->opaque->exec, pcmk_strerror(rc), rc); + op->opaque->exec, pcmk_rc_str(rc), rc); services__handle_exec_error(op, rc); goto done; } @@ -1197,7 +1197,7 @@ services__execute_file(svc_action_t *op) close_pipe(stdout_fd); crm_info("Cannot execute '%s': %s " CRM_XS " pipe(stderr) rc=%d", - op->opaque->exec, pcmk_strerror(rc), rc); + op->opaque->exec, pcmk_rc_str(rc), rc); services__handle_exec_error(op, rc); goto done; } @@ -1210,7 +1210,7 @@ services__execute_file(svc_action_t *op) close_pipe(stderr_fd); crm_info("Cannot execute '%s': %s " CRM_XS " pipe(stdin) rc=%d", - op->opaque->exec, pcmk_strerror(rc), rc); + op->opaque->exec, pcmk_rc_str(rc), rc); services__handle_exec_error(op, rc); goto done; } @@ -1235,7 +1235,7 @@ services__execute_file(svc_action_t *op) close_pipe(stderr_fd); crm_info("Cannot execute '%s': %s " CRM_XS " fork rc=%d", - op->opaque->exec, pcmk_strerror(rc), rc); + op->opaque->exec, pcmk_rc_str(rc), rc); services__handle_exec_error(op, rc); if (op->synchronous) { sigchld_cleanup(&data); diff --git a/lib/services/services_lsb.c b/lib/services/services_lsb.c index 134cc70..9ad7025 100644 --- a/lib/services/services_lsb.c +++ b/lib/services/services_lsb.c @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 the Pacemaker project contributors + * Copyright 2010-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -290,7 +290,8 @@ enum ocf_exitcode services__lsb2ocf(const char *action, int exit_status) { // For non-status actions, LSB and OCF share error codes <= 7 - if (!pcmk__str_any_of(action, "status", "monitor", NULL)) { + if (!pcmk__str_any_of(action, PCMK_ACTION_STATUS, PCMK_ACTION_MONITOR, + NULL)) { if ((exit_status < 0) || (exit_status > PCMK_LSB_NOT_RUNNING)) { return PCMK_OCF_UNKNOWN_ERROR; } diff --git a/lib/services/services_nagios.c b/lib/services/services_nagios.c index abddca8..10759b5 100644 --- a/lib/services/services_nagios.c +++ b/lib/services/services_nagios.c @@ -1,5 +1,5 @@ /* - * Copyright 2010-2022 the Pacemaker project contributors + * Copyright 2010-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -49,7 +49,7 @@ services__nagios_prepare(svc_action_t *op) return ENOMEM; } - if (pcmk__str_eq(op->action, "monitor", pcmk__str_casei) + if (pcmk__str_eq(op->action, PCMK_ACTION_MONITOR, pcmk__str_casei) && (op->interval_ms == 0)) { // Invoke --version for a nagios probe diff --git a/lib/services/systemd.c b/lib/services/systemd.c index 0c38ae0..ecac86c 100644 --- a/lib/services/systemd.c +++ b/lib/services/systemd.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the Pacemaker project contributors + * Copyright 2012-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -308,7 +308,7 @@ set_result_from_method_error(svc_action_t *op, const DBusError *error) || strstr(error->name, "org.freedesktop.systemd1.LoadFailed") || strstr(error->name, "org.freedesktop.systemd1.NoSuchUnit")) { - if (pcmk__str_eq(op->action, "stop", pcmk__str_casei)) { + if (pcmk__str_eq(op->action, PCMK_ACTION_STOP, pcmk__str_casei)) { crm_trace("Masking systemd stop failure (%s) for %s " "because unknown service can be considered stopped", error->name, pcmk__s(op->rsc, "unknown resource")); @@ -459,7 +459,11 @@ invoke_unit_by_name(const char *arg_name, svc_action_t *op, char **path) CRM_ASSERT(msg != NULL); // Add the (expanded) unit name as the argument - name = systemd_service_name(arg_name, op == NULL || pcmk__str_eq(op->action, "meta-data", pcmk__str_none)); + name = systemd_service_name(arg_name, + (op == NULL) + || pcmk__str_eq(op->action, + PCMK_ACTION_META_DATA, + pcmk__str_none)); CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)); free(name); @@ -717,6 +721,8 @@ process_unit_method_reply(DBusMessage *reply, svc_action_t *op) { DBusError error; + dbus_error_init(&error); + /* The first use of error here is not used other than as a non-NULL flag to * indicate that a request was indeed sent */ @@ -932,7 +938,8 @@ invoke_unit_by_path(svc_action_t *op, const char *unit) DBusMessage *msg = NULL; DBusMessage *reply = NULL; - if (pcmk__str_any_of(op->action, "monitor", "status", NULL)) { + if (pcmk__str_any_of(op->action, PCMK_ACTION_MONITOR, PCMK_ACTION_STATUS, + NULL)) { DBusPendingCall *pending = NULL; char *state; @@ -955,11 +962,11 @@ invoke_unit_by_path(svc_action_t *op, const char *unit) } return; - } else if (pcmk__str_eq(op->action, "start", pcmk__str_none)) { + } else if (pcmk__str_eq(op->action, PCMK_ACTION_START, pcmk__str_none)) { method = "StartUnit"; systemd_create_override(op->agent, op->timeout); - } else if (pcmk__str_eq(op->action, "stop", pcmk__str_none)) { + } else if (pcmk__str_eq(op->action, PCMK_ACTION_STOP, pcmk__str_none)) { method = "StopUnit"; systemd_remove_override(op->agent, op->timeout); @@ -988,7 +995,10 @@ invoke_unit_by_path(svc_action_t *op, const char *unit) /* (ss) */ { const char *replace_s = "replace"; - char *name = systemd_service_name(op->agent, pcmk__str_eq(op->action, "meta-data", pcmk__str_none)); + char *name = systemd_service_name(op->agent, + pcmk__str_eq(op->action, + PCMK_ACTION_META_DATA, + pcmk__str_none)); CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)); CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &replace_s, DBUS_TYPE_INVALID)); @@ -1072,7 +1082,7 @@ services__execute_systemd(svc_action_t *op) (op->synchronous? "" : "a"), op->action, op->agent, ((op->rsc == NULL)? "" : " for resource "), pcmk__s(op->rsc, "")); - if (pcmk__str_eq(op->action, "meta-data", pcmk__str_casei)) { + if (pcmk__str_eq(op->action, PCMK_ACTION_META_DATA, pcmk__str_casei)) { op->stdout_data = systemd_unit_metadata(op->agent, op->timeout); services__set_result(op, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); goto done; diff --git a/lib/services/upstart.c b/lib/services/upstart.c index 459b572..2306e73 100644 --- a/lib/services/upstart.c +++ b/lib/services/upstart.c @@ -1,7 +1,7 @@ /* * Original copyright 2010 Senko Rasic <senko.rasic@dobarkod.hr> * and Ante Karamatic <ivoks@init.hr> - * Later changes copyright 2012-2022 the Pacemaker project contributors + * Later changes copyright 2012-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -412,7 +412,7 @@ set_result_from_method_error(svc_action_t *op, const DBusError *error) if (strstr(error->name, UPSTART_06_API ".Error.UnknownInstance")) { - if (pcmk__str_eq(op->action, "stop", pcmk__str_casei)) { + if (pcmk__str_eq(op->action, PCMK_ACTION_STOP, pcmk__str_casei)) { crm_trace("Masking stop failure (%s) for %s " "because unknown service can be considered stopped", error->name, pcmk__s(op->rsc, "unknown resource")); @@ -423,7 +423,7 @@ set_result_from_method_error(svc_action_t *op, const DBusError *error) services__set_result(op, PCMK_OCF_NOT_INSTALLED, PCMK_EXEC_NOT_INSTALLED, "Upstart job not found"); - } else if (pcmk__str_eq(op->action, "start", pcmk__str_casei) + } else if (pcmk__str_eq(op->action, PCMK_ACTION_START, pcmk__str_casei) && strstr(error->name, UPSTART_06_API ".Error.AlreadyStarted")) { crm_trace("Masking start failure (%s) for %s " "because already started resource is OK", @@ -462,7 +462,7 @@ job_method_complete(DBusPendingCall *pending, void *user_data) set_result_from_method_error(op, &error); dbus_error_free(&error); - } else if (pcmk__str_eq(op->action, "stop", pcmk__str_none)) { + } else if (pcmk__str_eq(op->action, PCMK_ACTION_STOP, pcmk__str_none)) { // Call has no return value crm_debug("DBus request for stop of %s succeeded", pcmk__s(op->rsc, "unknown resource")); @@ -539,14 +539,14 @@ services__execute_upstart(svc_action_t *op) goto cleanup; } - if (pcmk__str_eq(op->action, "meta-data", pcmk__str_casei)) { + if (pcmk__str_eq(op->action, PCMK_ACTION_META_DATA, pcmk__str_casei)) { op->stdout_data = upstart_job_metadata(op->agent); services__set_result(op, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); goto cleanup; } if (!object_path_for_job(op->agent, &job, op->timeout)) { - if (pcmk__str_eq(action, "stop", pcmk__str_none)) { + if (pcmk__str_eq(action, PCMK_ACTION_STOP, pcmk__str_none)) { services__set_result(op, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); } else { services__set_result(op, PCMK_OCF_NOT_INSTALLED, @@ -563,7 +563,8 @@ services__execute_upstart(svc_action_t *op) goto cleanup; } - if (pcmk__strcase_any_of(op->action, "monitor", "status", NULL)) { + if (pcmk__strcase_any_of(op->action, PCMK_ACTION_MONITOR, + PCMK_ACTION_STATUS, NULL)) { DBusPendingCall *pending = NULL; char *state = NULL; char *path = get_first_instance(job, op->timeout); @@ -598,10 +599,10 @@ services__execute_upstart(svc_action_t *op) goto cleanup; - } else if (pcmk__str_eq(action, "start", pcmk__str_none)) { + } else if (pcmk__str_eq(action, PCMK_ACTION_START, pcmk__str_none)) { action = "Start"; - } else if (pcmk__str_eq(action, "stop", pcmk__str_none)) { + } else if (pcmk__str_eq(action, PCMK_ACTION_STOP, pcmk__str_none)) { action = "Stop"; } else if (pcmk__str_eq(action, "restart", pcmk__str_none)) { @@ -665,7 +666,7 @@ services__execute_upstart(svc_action_t *op) set_result_from_method_error(op, &error); dbus_error_free(&error); - } else if (pcmk__str_eq(op->action, "stop", pcmk__str_none)) { + } else if (pcmk__str_eq(op->action, PCMK_ACTION_STOP, pcmk__str_none)) { // DBus call does not return a value services__set_result(op, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); |