]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-process-util: Ignore EINVAL from setresuid() and setresgid() 34486/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 19 Sep 2024 10:21:55 +0000 (12:21 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 19 Sep 2024 11:42:05 +0000 (13:42 +0200)
If we're running in a user namespace with a single user and without
the nobody user, we'll get EINVAL from these system calls so make
sure we handle those gracefully.

src/test/test-process-util.c

index bf4d94e8c059d0436697e5c909496194d4ab19f3..e6ba6fea707f87f14819378e0537c00a2601f228 100644 (file)
@@ -729,11 +729,13 @@ TEST(setpriority_closest) {
                         /* However, if the hard limit was above 30, setrlimit would succeed unprivileged, so
                          * check if the UID/GID can be changed before enabling the full test. */
                         if (setresgid(GID_NOBODY, GID_NOBODY, GID_NOBODY) < 0) {
-                                if (!ERRNO_IS_PRIVILEGE(errno))
+                                /* If the nobody user does not exist (user namespace) we get EINVAL. */
+                                if (!ERRNO_IS_PRIVILEGE(errno) && errno != EINVAL)
                                         ASSERT_OK_ERRNO(-1);
                                 full_test = false;
                         } else if (setresuid(UID_NOBODY, UID_NOBODY, UID_NOBODY) < 0) {
-                                if (!ERRNO_IS_PRIVILEGE(errno))
+                                /* If the nobody user does not exist (user namespace) we get EINVAL. */
+                                if (!ERRNO_IS_PRIVILEGE(errno) && errno != EINVAL)
                                         ASSERT_OK_ERRNO(-1);
                                 full_test = false;
                         } else