summaryrefslogtreecommitdiff
path: root/core/systemd/0001-cryptsetup-generator-auto-add-deps-for-device-as-pas.patch
blob: dd8c9ff748ea49cf21ba74b2a130e46196183968 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 66a5dbdf282435403f947c2caadd04bb0cdec752 Mon Sep 17 00:00:00 2001
From: Dave Reisner <dreisner@archlinux.org>
Date: Sat, 8 Feb 2014 12:54:58 -0500
Subject: [PATCH] cryptsetup-generator: auto add deps for device as password

If the password is a device file, we can add Requires/After dependencies
on the device rather than requiring the user to do so.
---
 src/cryptsetup/cryptsetup-generator.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 9c98f0b..46ad9b8 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -130,11 +130,21 @@ static int create_disk(
                     streq(password, "/dev/random") ||
                     streq(password, "/dev/hw_random"))
                         fputs("After=systemd-random-seed.service\n", f);
-                else if (!streq(password, "-") &&
-                         !streq(password, "none"))
-                        fprintf(f,
-                                "RequiresMountsFor=%s\n",
-                                password);
+
+                else if (!streq(password, "-") && !streq(password, "none")) {
+                        _cleanup_free_ char *uu = fstab_node_to_udev_node(password);
+                        if (uu == NULL)
+                                return log_oom();
+
+                        if (is_device_path(uu)) {
+                                _cleanup_free_ char *dd = unit_name_from_path(uu, ".device");
+                                if (dd == NULL)
+                                        return log_oom();
+
+                                fprintf(f, "After=%1$s\nRequires=%1$s\n", dd);
+                        } else
+                                fprintf(f, "RequiresMountsFor=%s\n", password);
+                }
         }
 
         if (is_device_path(u))
-- 
1.8.5.4