From 62ca7d3b38dbbfbffa0aa0d3746b6be2916530b5 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 23 Sep 2020 15:23:58 -0400 Subject: [PATCH 1/2] cryptsetup-generator: use "/proc/cmdline" as source when appropriate Right now, we always say `/etc/crypttab` even if the source was fully derived from the kargs. Let's match what `systemd-fstab-generator` does and use `/proc/cmdline` when that's the case. --- src/cryptsetup/cryptsetup-generator.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index dec4d20181..9a1ddf2094 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -274,7 +274,8 @@ static int create_disk( const char *device, const char *password, const char *keydev, - const char *options) { + const char *options, + const char *source) { _cleanup_free_ char *n = NULL, *d = NULL, *u = NULL, *e = NULL, *keydev_mount = NULL, *keyfile_timeout_value = NULL, @@ -343,7 +344,7 @@ static int create_disk( if (r < 0) return r; - r = generator_write_cryptsetup_unit_section(f, arg_crypttab); + r = generator_write_cryptsetup_unit_section(f, source); if (r < 0) return r; @@ -680,7 +681,7 @@ static int add_crypttab_devices(void) { if (r < 0) return r; - r = create_disk(name, device, keyfile, keydev, (d && d->options) ? d->options : options); + r = create_disk(name, device, keyfile, keydev, (d && d->options) ? d->options : options, arg_crypttab); if (r < 0) return r; @@ -715,7 +716,8 @@ static int add_proc_cmdline_devices(void) { device, d->keyfile ?: arg_default_keyfile, d->keydev, - d->options ?: arg_default_options); + d->options ?: arg_default_options, + "/proc/cmdline"); if (r < 0) return r; } From 263a79642bfc2d37debefc8a8e96eb6e9efe7fc3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 23 Sep 2020 15:25:41 -0400 Subject: [PATCH 2/2] cryptsetup-generator: avoid magic value in ternary `startswith` already returns the string with the prefix skipped, so we can simplify this further and avoid using a magic value. Noticed in passing. Co-authored-by: Lennart Poettering --- src/cryptsetup/cryptsetup-generator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 9a1ddf2094..3ff50f4b6b 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -541,7 +541,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - d = get_crypto_device(startswith(value, "luks-") ? value+5 : value); + d = get_crypto_device(startswith(value, "luks-") ?: value); if (!d) return log_oom();