The main function for a threadsafe-style death test child process. This function is called in a clone()-ed process and thus must avoid any potentially unsafe operations like malloc or libc functions.
| 8832 | // This function is called in a clone()-ed process and thus must avoid |
| 8833 | // any potentially unsafe operations like malloc or libc functions. |
| 8834 | static int ExecDeathTestChildMain(void* child_arg) { |
| 8835 | ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg); |
| 8836 | GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd)); |
| 8837 | |
| 8838 | // We need to execute the test program in the same environment where |
| 8839 | // it was originally invoked. Therefore we change to the original |
| 8840 | // working directory first. |
| 8841 | const char* const original_dir = |
| 8842 | UnitTest::GetInstance()->original_working_dir(); |
| 8843 | // We can safely call chdir() as it's a direct system call. |
| 8844 | if (chdir(original_dir) != 0) { |
| 8845 | DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " + |
| 8846 | GetLastErrnoDescription()); |
| 8847 | return EXIT_FAILURE; |
| 8848 | } |
| 8849 | |
| 8850 | // We can safely call execve() as it's a direct system call. We |
| 8851 | // cannot use execvp() as it's a libc function and thus potentially |
| 8852 | // unsafe. Since execve() doesn't search the PATH, the user must |
| 8853 | // invoke the test program via a valid path that contains at least |
| 8854 | // one path separator. |
| 8855 | execve(args->argv[0], args->argv, GetEnviron()); |
| 8856 | DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " + |
| 8857 | original_dir + " failed: " + |
| 8858 | GetLastErrnoDescription()); |
| 8859 | return EXIT_FAILURE; |
| 8860 | } |
| 8861 | # endif // !GTEST_OS_QNX |
| 8862 | |
| 8863 | # if GTEST_HAS_CLONE |
no test coverage detected