Test that a child in different namespace(s) can setns back to the root namespace. We must fork a child to test this because setns doesn't support multi-threaded processes (which gtest is).
| 56 | // root namespace. We must fork a child to test this because setns |
| 57 | // doesn't support multi-threaded processes (which gtest is). |
| 58 | TEST(NsTest, ROOT_setns) |
| 59 | { |
| 60 | // Clone then exec the setns-test-helper into a new namespace for |
| 61 | // each available namespace. |
| 62 | int flags = 0; |
| 63 | |
| 64 | foreach (int nsType, ns::nstypes()) { |
| 65 | // Skip 'user' namespace because it causes 'clone' to change us |
| 66 | // from being user 'root' to user 'nobody', but these tests |
| 67 | // require root. See MESOS-3083. |
| 68 | if (nsType == CLONE_NEWUSER) { |
| 69 | continue; |
| 70 | } |
| 71 | |
| 72 | flags |= nsType; |
| 73 | } |
| 74 | |
| 75 | ASSERT_NE(0, flags); |
| 76 | |
| 77 | vector<string> argv; |
| 78 | argv.push_back("test-helper"); |
| 79 | argv.push_back(SetnsTestHelper::NAME); |
| 80 | |
| 81 | Try<Subprocess> s = subprocess( |
| 82 | getTestHelperPath("test-helper"), |
| 83 | argv, |
| 84 | Subprocess::FD(STDIN_FILENO), |
| 85 | Subprocess::FD(STDOUT_FILENO), |
| 86 | Subprocess::FD(STDERR_FILENO), |
| 87 | nullptr, |
| 88 | None(), |
| 89 | [=](const lambda::function<int()>& child) { |
| 90 | return os::clone(child, flags | SIGCHLD); |
| 91 | }); |
| 92 | |
| 93 | // Continue in parent. |
| 94 | ASSERT_SOME(s); |
| 95 | |
| 96 | // The child should exit 0. |
| 97 | AWAIT_EXPECT_WEXITSTATUS_EQ(0, s->status()); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | // Test the ns::supported() API. |
nothing calls this directly
no test coverage detected