]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
errno-util: add ERRNO_IS_IOCTL_NOT_SUPPORTED that checks EINVAL additionally
authorMike Yuan <me@yhndnzj.com>
Tue, 19 Nov 2024 22:59:00 +0000 (23:59 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 4 Jan 2025 16:07:58 +0000 (17:07 +0100)
src/basic/chattr-util.c
src/basic/errno-util.h
src/basic/terminal-util.c
src/libsystemd/sd-varlink/varlink-util.c
src/shared/install-file.c
src/shared/loop-util.c

index 4aabcc68183318d981b96c52439df2c50ea3167f..39fdf970a71721d20b570f588bdd92616fe1537b 100644 (file)
@@ -103,7 +103,7 @@ int chattr_full(
                         continue;
 
                 if (ioctl(fd, FS_IOC_SETFLAGS, &new_one) < 0) {
-                        if (errno != EINVAL && !ERRNO_IS_NOT_SUPPORTED(errno))
+                        if (!ERRNO_IS_IOCTL_NOT_SUPPORTED(errno))
                                 return -errno;
 
                         log_full_errno(FLAGS_SET(flags, CHATTR_WARN_UNSUPPORTED_FLAGS) ? LOG_WARNING : LOG_DEBUG,
index 48b76e4bf70dffac92ba6cadca9d85eb8de66515..02572e3bdcdf9a90614ebff392f9a70568147d1b 100644 (file)
@@ -158,7 +158,7 @@ static inline bool ERRNO_IS_NEG_RESOURCE(intmax_t r) {
 }
 _DEFINE_ABS_WRAPPER(RESOURCE);
 
-/* Seven different errors for "operation/system call/ioctl/socket feature not supported" */
+/* Seven different errors for "operation/system call/socket feature not supported" */
 static inline bool ERRNO_IS_NEG_NOT_SUPPORTED(intmax_t r) {
         return IN_SET(r,
                       -EOPNOTSUPP,
@@ -172,6 +172,12 @@ static inline bool ERRNO_IS_NEG_NOT_SUPPORTED(intmax_t r) {
 }
 _DEFINE_ABS_WRAPPER(NOT_SUPPORTED);
 
+/* ioctl() with unsupported command/arg might additionally return EINVAL */
+static inline bool ERRNO_IS_NEG_IOCTL_NOT_SUPPORTED(intmax_t r) {
+        return ERRNO_IS_NEG_NOT_SUPPORTED(r) || r == -EINVAL;
+}
+_DEFINE_ABS_WRAPPER(IOCTL_NOT_SUPPORTED);
+
 /* Two different errors for access problems */
 static inline bool ERRNO_IS_NEG_PRIVILEGE(intmax_t r) {
         return IN_SET(r,
index 725ccc2b87184938eda6a7073b707866550141d8..ab926a42142c0ba8798ef941d84dcaa0e00c30cf 100644 (file)
@@ -2334,7 +2334,7 @@ int pty_open_peer_racefree(int fd, int mode) {
                 if (peer_fd >= 0)
                         return peer_fd;
 
-                if (ERRNO_IS_NOT_SUPPORTED(errno) || errno == EINVAL) /* new ioctl() is not supported, return a clear error */
+                if (ERRNO_IS_IOCTL_NOT_SUPPORTED(errno)) /* new ioctl() is not supported, return a clear error */
                         return -EOPNOTSUPP;
 
                 if (errno != EIO)
index 765108515c47d9881ffb4a26d8b040dab411741e..22f1a94f0b566425046068dd65d308d1dac21c14 100644 (file)
@@ -19,7 +19,7 @@ int varlink_get_peer_pidref(sd_varlink *v, PidRef *ret) {
 
         int pidfd = sd_varlink_get_peer_pidfd(v);
         if (pidfd < 0) {
-                if (!ERRNO_IS_NEG_NOT_SUPPORTED(pidfd) && pidfd != -EINVAL)
+                if (!ERRNO_IS_NEG_IOCTL_NOT_SUPPORTED(pidfd))
                         return pidfd;
 
                 pid_t pid;
index ea2189fc9efe501c09ef2e29b719ba259be265f8..c0a220427676a35444865c512c7ab7cbc6f0e981 100644 (file)
@@ -44,8 +44,7 @@ static int fs_make_very_read_only(int fd) {
                         r = btrfs_subvol_set_read_only_fd(fd, true);
                         if (r >= 0)
                                 return 0;
-
-                        if (!ERRNO_IS_NOT_SUPPORTED(r) && r != -EINVAL)
+                        if (!ERRNO_IS_NEG_IOCTL_NOT_SUPPORTED(r))
                                 return r;
                 }
 
index d707d466abdfe199b4d91fc8bdf90aefe5bde628..9c105a6d13f54affe341d43ee7f42be9f4d9efed 100644 (file)
@@ -312,11 +312,8 @@ static int loop_configure(
 
         if (!loop_configure_broken) {
                 if (ioctl(fd, LOOP_CONFIGURE, c) < 0) {
-                        /* Do fallback only if LOOP_CONFIGURE is not supported, propagate all other
-                         * errors. Note that the kernel is weird: non-existing ioctls currently return EINVAL
-                         * rather than ENOTTY on loopback block devices. They should fix that in the kernel,
-                         * but in the meantime we accept both here. */
-                        if (!ERRNO_IS_NOT_SUPPORTED(errno) && errno != EINVAL)
+                        /* Do fallback only if LOOP_CONFIGURE is not supported, propagate all other errors. */
+                        if (!ERRNO_IS_IOCTL_NOT_SUPPORTED(errno))
                                 return log_device_debug_errno(dev, errno, "ioctl(LOOP_CONFIGURE) failed: %m");
 
                         loop_configure_broken = true;