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.
| 7436 | // This function is called in a clone()-ed process and thus must avoid |
| 7437 | // any potentially unsafe operations like malloc or libc functions. |
| 7438 | static int ExecDeathTestChildMain(void* child_arg) { |
| 7439 | ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg); |
| 7440 | GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd)); |
| 7441 | |
| 7442 | // We need to execute the test program in the same environment where |
| 7443 | // it was originally invoked. Therefore we change to the original |
| 7444 | // working directory first. |
| 7445 | const char* const original_dir = |
| 7446 | UnitTest::GetInstance()->original_working_dir(); |
| 7447 | // We can safely call chdir() as it's a direct system call. |
| 7448 | if (chdir(original_dir) != 0) { |
| 7449 | DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " + |
| 7450 | GetLastErrnoDescription()); |
| 7451 | return EXIT_FAILURE; |
| 7452 | } |
| 7453 | |
| 7454 | // We can safely call execve() as it's a direct system call. We |
| 7455 | // cannot use execvp() as it's a libc function and thus potentially |
| 7456 | // unsafe. Since execve() doesn't search the PATH, the user must |
| 7457 | // invoke the test program via a valid path that contains at least |
| 7458 | // one path separator. |
| 7459 | execve(args->argv[0], args->argv, GetEnviron()); |
| 7460 | DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " + |
| 7461 | original_dir + " failed: " + |
| 7462 | GetLastErrnoDescription()); |
| 7463 | return EXIT_FAILURE; |
| 7464 | } |
| 7465 | # endif // !GTEST_OS_QNX |
| 7466 | |
| 7467 | // Two utility routines that together determine the direction the stack |
no test coverage detected