76 lines
3.0 KiB
Diff
76 lines
3.0 KiB
Diff
From 3f2ada89f3a277625390bf6789ccd4e7aba08743 Mon Sep 17 00:00:00 2001
|
|
From: Lennart Poettering <lennart@poettering.net>
|
|
Date: Thu, 24 Mar 2022 13:50:50 +0100
|
|
Subject: [PATCH] errno-util: add ERRNO_IS_DEVICE_ABSENT() macro
|
|
|
|
Inspired by: https://github.com/systemd/systemd/pull/22717#discussion_r834254495
|
|
|
|
Reference:https://github.com/systemd/systemd/commit/3f2ada89f3a277625390bf6789ccd4e7aba08743
|
|
Conflict:discard change on homework-luks.c
|
|
|
|
---
|
|
src/basic/errno-util.h | 10 +++++++++-
|
|
src/rfkill/rfkill.c | 2 +-
|
|
src/udev/udev-builtin-btrfs.c | 3 ++-
|
|
3 files changed, 12 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h
|
|
index 09abf0b7512d..648de50eb497 100644
|
|
--- a/src/basic/errno-util.h
|
|
+++ b/src/basic/errno-util.h
|
|
@@ -138,10 +138,18 @@ static inline bool ERRNO_IS_PRIVILEGE(int r) {
|
|
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);
|
|
+}
|
|
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
|
|
index 656afa06ac8b..a833771d97f2 100644
|
|
--- a/src/rfkill/rfkill.c
|
|
+++ b/src/rfkill/rfkill.c
|
|
@@ -80,7 +80,7 @@ static int find_device(
|
|
|
|
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);
|
|
diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c
|
|
index a0093cb42347..f9d4f1dd4ef4 100644
|
|
--- a/src/udev/udev-builtin-btrfs.c
|
|
+++ b/src/udev/udev-builtin-btrfs.c
|
|
@@ -6,6 +6,7 @@
|
|
#include <sys/ioctl.h>
|
|
|
|
#include "device-util.h"
|
|
+#include "errno-util.h"
|
|
#include "fd-util.h"
|
|
#include "string-util.h"
|
|
#include "strxcpyx.h"
|
|
@@ -22,7 +23,7 @@ static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv
|
|
|
|
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. */
|
|
|