Blame SOURCES/004-systemd-metadata.patch

97a979
From 09ef95a2eed48b4eb7488788a1b655d67eafe783 Mon Sep 17 00:00:00 2001
97a979
From: Chris Lumens <clumens@redhat.com>
97a979
Date: Tue, 30 Nov 2021 14:47:12 -0500
97a979
Subject: [PATCH] Low: libcrmservice: Handle systemd service templates.
97a979
97a979
These unit files (which have an @ sign at the end) expect to be
97a979
parameterized by an instance name.  Not providing an instance name
97a979
causes the dbus lookup to fail, and we fall back to assume this is an
97a979
LSB service.  If the user doesn't provide an instance name, just add a
97a979
fake one.  It doesn't seem to matter what name is given for the lookup.
97a979
97a979
See: rhbz#2003151
97a979
---
97a979
 lib/services/systemd.c | 22 ++++++++++++++++------
97a979
 1 file changed, 16 insertions(+), 6 deletions(-)
97a979
97a979
diff --git a/lib/services/systemd.c b/lib/services/systemd.c
97a979
index 8e9fff484..27a3b376d 100644
97a979
--- a/lib/services/systemd.c
97a979
+++ b/lib/services/systemd.c
97a979
@@ -206,17 +206,27 @@ systemd_unit_extension(const char *name)
97a979
 }
97a979
 
97a979
 static char *
97a979
-systemd_service_name(const char *name)
97a979
+systemd_service_name(const char *name, bool add_instance_name)
97a979
 {
97a979
-    if (name == NULL) {
97a979
+    if (pcmk__str_empty(name)) {
97a979
         return NULL;
97a979
     }
97a979
 
97a979
     if (systemd_unit_extension(name)) {
97a979
         return strdup(name);
97a979
-    }
97a979
 
97a979
-    return crm_strdup_printf("%s.service", name);
97a979
+    /* Services that end with an @ sign are systemd templates.  They expect an
97a979
+     * instance name to follow the service name.  If no instance name was
97a979
+     * provided, just add "x" to the string as the instance name.  It doesn't
97a979
+     * seem to matter for purposes of looking up whether a service exists or
97a979
+     * not.
97a979
+     */
97a979
+    } else if (add_instance_name && *(name+strlen(name)-1) == '@') {
97a979
+        return crm_strdup_printf("%sx.service", name);
97a979
+
97a979
+    } else {
97a979
+        return crm_strdup_printf("%s.service", name);
97a979
+    }
97a979
 }
97a979
 
97a979
 static void
97a979
@@ -427,7 +437,7 @@ invoke_unit_by_name(const char *arg_name, svc_action_t *op, char **path)
97a979
     CRM_ASSERT(msg != NULL);
97a979
 
97a979
     // Add the (expanded) unit name as the argument
97a979
-    name = systemd_service_name(arg_name);
97a979
+    name = systemd_service_name(arg_name, op == NULL || pcmk__str_eq(op->action, "meta-data", pcmk__str_none));
97a979
     CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
97a979
                                             DBUS_TYPE_INVALID));
97a979
     free(name);
97a979
@@ -944,7 +954,7 @@ invoke_unit_by_path(svc_action_t *op, const char *unit)
97a979
     /* (ss) */
97a979
     {
97a979
         const char *replace_s = "replace";
97a979
-        char *name = systemd_service_name(op->agent);
97a979
+        char *name = systemd_service_name(op->agent, pcmk__str_eq(op->action, "meta-data", pcmk__str_none));
97a979
 
97a979
         CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID));
97a979
         CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &replace_s, DBUS_TYPE_INVALID));
97a979
-- 
97a979
2.27.0
97a979