mirror of
https://github.com/systemd/systemd.git
synced 2025-02-02 13:47:27 +03:00
errno-util: add ERRNO_IS_DEVICE_ABSENT() macro
Inspired by: https://github.com/systemd/systemd/pull/22717#discussion_r834254495
This commit is contained in:
parent
4029328014
commit
3f2ada89f3
@ -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);
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ static int acquire_open_luks_device(
|
||||
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);
|
||||
@ -1631,7 +1631,7 @@ 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 (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)
|
||||
|
@ -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);
|
||||
|
@ -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. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user