]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: split code that allocates udev security device monitor into its own function
authorLennart Poettering <lennart@poettering.net>
Wed, 25 Nov 2020 10:51:39 +0000 (11:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 17 Dec 2020 18:59:17 +0000 (19:59 +0100)
src/cryptsetup/cryptsetup.c

index 9ff99d91a9a4b3f4ff8bc65854af880622bc869d..5d016143f56a68f29462885ad1744e69cf77115b 100644 (file)
@@ -560,6 +560,32 @@ static char *make_bindname(const char *volume) {
         return s;
 }
 
+static int make_security_device_monitor(sd_event *event, sd_device_monitor **ret) {
+        _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor = NULL;
+        int r;
+
+        assert(ret);
+
+        r = sd_device_monitor_new(&monitor);
+        if (r < 0)
+                return log_error_errno(r, "Failed to allocate device monitor: %m");
+
+        r = sd_device_monitor_filter_add_match_tag(monitor, "security-device");
+        if (r < 0)
+                return log_error_errno(r, "Failed to configure device monitor: %m");
+
+        r = sd_device_monitor_attach_event(monitor, event);
+        if (r < 0)
+                return log_error_errno(r, "Failed to attach device monitor: %m");
+
+        r = sd_device_monitor_start(monitor, NULL, NULL);
+        if (r < 0)
+                return log_error_errno(r, "Failed to start device monitor: %m");
+
+        *ret = TAKE_PTR(monitor);
+        return 0;
+}
+
 static int attach_luks_or_plain_or_bitlk(
                 struct crypt_device *cd,
                 const char *name,
@@ -668,21 +694,9 @@ static int attach_luks_or_plain_or_bitlk(
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to allocate event loop: %m");
 
-                                r = sd_device_monitor_new(&monitor);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to allocate device monitor: %m");
-
-                                r = sd_device_monitor_filter_add_match_tag(monitor, "security-device");
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to configure device monitor: %m");
-
-                                r = sd_device_monitor_attach_event(monitor, event);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to attach device monitor: %m");
-
-                                r = sd_device_monitor_start(monitor, NULL, NULL);
+                                r = make_security_device_monitor(event, &monitor);
                                 if (r < 0)
-                                        return log_error_errno(r, "Failed to start device monitor: %m");
+                                        return r;
 
                                 log_notice("Security token %s not present for unlocking volume %s, please plug it in.",
                                            arg_pkcs11_uri, friendly);