]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: cleanup use of ERRNO_IS_NOT_SUPPORTED()
authorDmitry V. Levin <ldv@strace.io>
Fri, 14 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 28 Jul 2023 12:28:35 +0000 (12:28 +0000)
Given that ERRNO_IS_NOT_SUPPORTED() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the argument passed to ERRNO_IS_NOT_SUPPORTED() is the
value returned by remount_idmap() which is not expected to return
any positive values, but let's be consistent anyway and move the
ERRNO_IS_NOT_SUPPORTED() invocation to the branch where
the return value is known to be negative.

src/nspawn/nspawn.c

index e170958fc5cf259897a7d8b8813ee7e60b789e32..d5b0486543620daa1f23b011db86bb01e40d4282 100644 (file)
@@ -3825,19 +3825,20 @@ static int outer_child(
             arg_uid_shift != 0) {
 
                 r = remount_idmap(directory, arg_uid_shift, arg_uid_range, UID_INVALID, REMOUNT_IDMAPPING_HOST_ROOT);
-                if (r == -EINVAL || ERRNO_IS_NOT_SUPPORTED(r)) {
-                        /* This might fail because the kernel or file system doesn't support idmapping. We
-                         * can't really distinguish this nicely, nor do we have any guarantees about the
-                         * error codes we see, could be EOPNOTSUPP or EINVAL. */
-                        if (arg_userns_ownership != USER_NAMESPACE_OWNERSHIP_AUTO)
-                                return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                                                       "ID mapped mounts are apparently not available, sorry.");
-
-                        log_debug("ID mapped mounts are apparently not available on this kernel or for the selected file system, reverting to recursive chown()ing.");
-                        arg_userns_ownership = USER_NAMESPACE_OWNERSHIP_CHOWN;
-                } else if (r < 0)
-                        return log_error_errno(r, "Failed to set up ID mapped mounts: %m");
-                else {
+                if (r < 0) {
+                        if (r == -EINVAL || ERRNO_IS_NOT_SUPPORTED(r)) {
+                                /* This might fail because the kernel or file system doesn't support idmapping. We
+                                 * can't really distinguish this nicely, nor do we have any guarantees about the
+                                 * error codes we see, could be EOPNOTSUPP or EINVAL. */
+                                if (arg_userns_ownership != USER_NAMESPACE_OWNERSHIP_AUTO)
+                                        return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                                               "ID mapped mounts are apparently not available, sorry.");
+
+                                log_debug("ID mapped mounts are apparently not available on this kernel or for the selected file system, reverting to recursive chown()ing.");
+                                arg_userns_ownership = USER_NAMESPACE_OWNERSHIP_CHOWN;
+                        } else
+                                return log_error_errno(r, "Failed to set up ID mapped mounts: %m");
+                } else {
                         log_debug("ID mapped mounts available, making use of them.");
                         idmap = true;
                 }