1 #define _GNU_SOURCE 2 #include <assert.h> 3 #include <errno.h> 4 #include <fcntl.h> 5 #include <linux/types.h> 6 #include <sched.h> 7 #include <signal.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <string.h> 11 #include <syscall.h> 12 #include <sys/wait.h> 13 14 #include "../kselftest.h" 15 #include "../kselftest_harness.h" 16 #include "../pidfd/pidfd.h" 17 18 /* 19 * Regression test for: 20 * 35f71bc0a09a ("fork: report pid reservation failure properly") 21 * b26ebfe12f34 ("pid: Fix error return value in some cases") 22 */ 23 TEST(regression_enomem) 24 { 25 pid_t pid; 26 27 if (geteuid()) 28 EXPECT_EQ(0, unshare(CLONE_NEWUSER)); 29 30 EXPECT_EQ(0, unshare(CLONE_NEWPID)); 31 32 pid = fork(); 33 ASSERT_GE(pid, 0); 34 35 if (pid == 0) 36 exit(EXIT_SUCCESS); 37 38 EXPECT_EQ(0, wait_for_pid(pid)); 39 40 pid = fork(); 41 ASSERT_LT(pid, 0); 42 ASSERT_EQ(errno, ENOMEM); 43 } 44 45 TEST_HARNESS_MAIN 46