]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: cleanup use of ERRNO_IS_DEVICE_ABSENT()
authorDmitry V. Levin <ldv@strace.io>
Fri, 14 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 28 Jul 2023 12:28:35 +0000 (12:28 +0000)
Given that ERRNO_IS_DEVICE_ABSENT() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the arguments passed to ERRNO_IS_DEVICE_ABSENT()
are the values returned by external cryptsetup functions
sym_crypt_init_by_name() and sym_crypt_deactivate_by_name() which are
not expected to return any positive values, but let's be consistent
anyway and move ERRNO_IS_DEVICE_ABSENT() invocations to the branches
where the return values are known to be negative.

src/home/homework-luks.c

index 06e346e1e049e94a849207beeb94b477c1f61158..7946e6c120bd550f09dbf08f0b5a56e3395419a8 100644 (file)
@@ -498,10 +498,11 @@ static int acquire_open_luks_device(
                 return r;
 
         r = sym_crypt_init_by_name(&cd, setup->dm_name);
-        if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful)
-                return 0;
-        if (r < 0)
+        if (r < 0) {
+                if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful)
+                        return 0;
                 return log_error_errno(r, "Failed to initialize cryptsetup context for %s: %m", setup->dm_name);
+        }
 
         cryptsetup_enable_logging(cd);
 
@@ -1638,11 +1639,12 @@ int home_deactivate_luks(UserRecord *h, HomeSetup *setup) {
                 cryptsetup_enable_logging(setup->crypt_device);
 
                 r = sym_crypt_deactivate_by_name(setup->crypt_device, setup->dm_name, 0);
-                if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL)
-                        log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node);
-                else if (r < 0)
-                        return log_info_errno(r, "LUKS device %s couldn't be deactivated: %m", setup->dm_node);
-                else {
+                if (r < 0) {
+                        if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL)
+                                log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node);
+                        else
+                                return log_info_errno(r, "LUKS device %s couldn't be deactivated: %m", setup->dm_node);
+                } else {
                         log_info("LUKS device detaching completed.");
                         we_detached = true;
                 }