summaryrefslogtreecommitdiffstats
path: root/src/cryptsetup/cryptsetup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-11-25 11:51:39 +0100
committerLennart Poettering <lennart@poettering.net>2020-12-17 19:59:17 +0100
commit8414cd48e98b34731b9e5a99ede7fec6d1107dee (patch)
tree7af8602450e3e1283604ab34b0af020151badfd1 /src/cryptsetup/cryptsetup.c
parentcryptsetup-util: add helper for setting minimal PBKDF (diff)
downloadsystemd-8414cd48e98b34731b9e5a99ede7fec6d1107dee.tar.xz
systemd-8414cd48e98b34731b9e5a99ede7fec6d1107dee.zip
cryptsetup: split code that allocates udev security device monitor into its own function
Diffstat (limited to '')
-rw-r--r--src/cryptsetup/cryptsetup.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 9ff99d91a9..5d016143f5 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -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);