X Tutup
Skip to content

Commit 3f2ada8

Browse files
committed
errno-util: add ERRNO_IS_DEVICE_ABSENT() macro
Inspired by: systemd#22717 (comment)
1 parent 4029328 commit 3f2ada8

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/basic/errno-util.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,18 @@ static inline bool ERRNO_IS_PRIVILEGE(int r) {
138138
EPERM);
139139
}
140140

141-
/* Three difference errors for "not enough disk space" */
141+
/* Three different errors for "not enough disk space" */
142142
static inline bool ERRNO_IS_DISK_SPACE(int r) {
143143
return IN_SET(abs(r),
144144
ENOSPC,
145145
EDQUOT,
146146
EFBIG);
147147
}
148+
149+
/* Three different errors for "this device does not quite exist" */
150+
static inline bool ERRNO_IS_DEVICE_ABSENT(int r) {
151+
return IN_SET(abs(r),
152+
ENODEV,
153+
ENXIO,
154+
ENOENT);
155+
}

src/home/homework-luks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static int acquire_open_luks_device(
495495
return r;
496496

497497
r = sym_crypt_init_by_name(&cd, setup->dm_name);
498-
if (IN_SET(r, -ENODEV, -EINVAL, -ENOENT) && graceful)
498+
if ((ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) && graceful)
499499
return 0;
500500
if (r < 0)
501501
return log_error_errno(r, "Failed to initialize cryptsetup context for %s: %m", setup->dm_name);
@@ -1631,7 +1631,7 @@ int home_deactivate_luks(UserRecord *h, HomeSetup *setup) {
16311631
cryptsetup_enable_logging(setup->crypt_device);
16321632

16331633
r = sym_crypt_deactivate_by_name(setup->crypt_device, setup->dm_name, 0);
1634-
if (IN_SET(r, -ENODEV, -EINVAL, -ENOENT)) {
1634+
if (ERRNO_IS_DEVICE_ABSENT(r) || r == -EINVAL) {
16351635
log_debug_errno(r, "LUKS device %s is already detached.", setup->dm_node);
16361636
we_detached = false;
16371637
} else if (r < 0)

src/rfkill/rfkill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static int find_device(
8080

8181
r = sd_device_new_from_subsystem_sysname(&device, "rfkill", sysname);
8282
if (r < 0)
83-
return log_full_errno(IN_SET(r, -ENOENT, -ENXIO, -ENODEV) ? LOG_DEBUG : LOG_ERR, r,
83+
return log_full_errno(ERRNO_IS_DEVICE_ABSENT(r) ? LOG_DEBUG : LOG_ERR, r,
8484
"Failed to open device '%s': %m", sysname);
8585

8686
r = sd_device_get_sysattr_value(device, "name", &name);

src/udev/udev-builtin-btrfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <sys/ioctl.h>
77

88
#include "device-util.h"
9+
#include "errno-util.h"
910
#include "fd-util.h"
1011
#include "string-util.h"
1112
#include "strxcpyx.h"
@@ -22,7 +23,7 @@ static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv
2223

2324
fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC);
2425
if (fd < 0) {
25-
if (IN_SET(errno, ENOENT, ENXIO, ENODEV)) {
26+
if (ERRNO_IS_DEVICE_ABSENT(errno)) {
2627
/* Driver not installed? Then we aren't ready. This is useful in initrds that lack
2728
* btrfs.ko. After the host transition (where btrfs.ko will hopefully become
2829
* available) the device can be retriggered and will then be considered ready. */

0 commit comments

Comments
 (0)
X Tutup