Inspired by: https://github.com/systemd/systemd/pull/22717#discussion_r834254495
EPERM);
}
-/* Three difference errors for "not enough disk space" */
+/* Three different errors for "not enough disk space" */
static inline bool ERRNO_IS_DISK_SPACE(int r) {
return IN_SET(abs(r),
ENOSPC,
EDQUOT,
EFBIG);
}
+
+/* Three different errors for "this device does not quite exist" */
+static inline bool ERRNO_IS_DEVICE_ABSENT(int r) {
+ return IN_SET(abs(r),
+ ENODEV,
+ ENXIO,
+ ENOENT);
+}
return r;
r = sym_crypt_init_by_name(&cd, setup->dm_name);
- if (IN_SET(r, -ENODEV, -EINVAL, -ENOENT) && graceful)
+ if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to initialize cryptsetup context for %s: %m", setup->dm_name);
cryptsetup_enable_logging(setup->crypt_device);
r = sym_crypt_deactivate_by_name(setup->crypt_device, setup->dm_name, 0);
- if (IN_SET(r, -ENODEV, -EINVAL, -ENOENT)) {
+ if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) {
log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node);
we_detached = false;
} else if (r < 0)
r = sd_device_new_from_subsystem_sysname(&device, "rfkill", sysname);
if (r < 0)
- return log_full_errno(IN_SET(r, -ENOENT, -ENXIO, -ENODEV) ? LOG_DEBUG : LOG_ERR, r,
+ return log_full_errno(ERRNO_IS_DEVICE_ABSENT(r) ? LOG_DEBUG : LOG_ERR, r,
"Failed to open device '%s': %m", sysname);
r = sd_device_get_sysattr_value(device, "name", &name);
#include <sys/ioctl.h>
#include "device-util.h"
+#include "errno-util.h"
#include "fd-util.h"
#include "string-util.h"
#include "strxcpyx.h"
fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
if (fd < 0) {
- if (IN_SET(errno, ENOENT, ENXIO, ENODEV)) {
+ if (ERRNO_IS_DEVICE_ABSENT(errno)) {
/* Driver not installed? Then we aren't ready. This is useful in initrds that lack
* btrfs.ko. After the host transition (where btrfs.ko will hopefully become
* available) the device can be retriggered and will then be considered ready. */