Blame SOURCES/004-systemd-metadata.patch

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