]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
veritysetup: automatically generate unit name, instead of hardcoding it
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Mar 2025 09:02:16 +0000 (10:02 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 19 Mar 2025 15:32:02 +0000 (16:32 +0100)
src/veritysetup/veritysetup-generator.c

index 8e35946ca6c2c7d2596c3c76200933d93bb9fa75..520cf097e54329f873a1d0bf60d7d2f71d4079f0 100644 (file)
@@ -22,9 +22,6 @@
 #include "string-util.h"
 #include "unit-name.h"
 
-#define SYSTEMD_VERITYSETUP_SERVICE_ROOT "systemd-veritysetup@root.service"
-#define SYSTEMD_VERITYSETUP_SERVICE_USR "systemd-veritysetup@usr.service"
-
 static const char *arg_dest = NULL;
 static bool arg_enabled = true;
 static bool arg_read_veritytab = true;
@@ -49,7 +46,6 @@ STATIC_DESTRUCTOR_REGISTER(arg_usr_options, freep);
 
 static int create_special_device(
                 const char *name,
-                const char *service,
                 const char *roothash,
                 const char *data_what,
                 const char *hash_what,
@@ -62,7 +58,6 @@ static int create_special_device(
         /* Creates a systemd-veritysetup@.service instance for the special kernel cmdline specified root + usr devices. */
 
         assert(name);
-        assert(service);
 
         /* If all three pieces of information are missing, then verity is turned off */
         if (!roothash && !data_what && !hash_what)
@@ -79,6 +74,11 @@ static int create_special_device(
         if (!roothash || !data_what || !hash_what)
                 return -EINVAL;
 
+        _cleanup_free_ char *service = NULL;
+        r = unit_name_build("systemd-veritysetup", name, ".service", &service);
+        if (r < 0)
+                return log_error_errno(r, "Failed to generate unit name: %m");
+
         log_debug("Using %s verity data device %s, hash device %s, options %s, and hash %s.", name, data_what, hash_what, options, roothash);
 
         u = fstab_node_to_udev_node(data_what);
@@ -126,11 +126,11 @@ static int create_special_device(
 }
 
 static int create_root_device(void) {
-        return create_special_device("root", SYSTEMD_VERITYSETUP_SERVICE_ROOT, arg_root_hash, arg_root_data_what, arg_root_hash_what, arg_root_options);
+        return create_special_device("root", arg_root_hash, arg_root_data_what, arg_root_hash_what, arg_root_options);
 }
 
 static int create_usr_device(void) {
-        return create_special_device("usr", SYSTEMD_VERITYSETUP_SERVICE_USR, arg_usr_hash, arg_usr_data_what, arg_usr_hash_what, arg_usr_options);
+        return create_special_device("usr", arg_usr_hash, arg_usr_data_what, arg_usr_hash_what, arg_usr_options);
 }
 
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {