From: Lennart Poettering Date: Wed, 19 Mar 2025 09:02:16 +0000 (+0100) Subject: veritysetup: automatically generate unit name, instead of hardcoding it X-Git-Tag: v258-rc1~1046^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ec1a83eeae18e658a55dca5f8f65ce2391f8ead;p=thirdparty%2Fsystemd.git veritysetup: automatically generate unit name, instead of hardcoding it --- diff --git a/src/veritysetup/veritysetup-generator.c b/src/veritysetup/veritysetup-generator.c index 8e35946ca6c..520cf097e54 100644 --- a/src/veritysetup/veritysetup-generator.c +++ b/src/veritysetup/veritysetup-generator.c @@ -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) {