homework: cleanup use of ERRNO_IS_DEVICE_ABSENT()

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.
This commit is contained in:
Dmitry V. Levin
2023-07-28 12:28:35 +00:00
parent 1553f9b1bc
commit 0d16fab986
+10 -8
View 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;
}