Commit bc9d5223 by Jamie Madill Committed by Angle LUCI CQ

Experimental fix for stdout freopen race.

Bug: chromium:1213184 Change-Id: I2e2741f4100b2a5516210f2250dc82511fafd05b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2933602 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 10f15011
...@@ -143,18 +143,42 @@ Java_com_android_angle_test_AngleNativeTest_nativeRunTests(JNIEnv *env, ...@@ -143,18 +143,42 @@ Java_com_android_angle_test_AngleNativeTest_nativeRunTests(JNIEnv *env,
// A few options, such "--gtest_list_tests", will just use printf directly // A few options, such "--gtest_list_tests", will just use printf directly
// Always redirect stdout to a known file. // Always redirect stdout to a known file.
if (freopen(stdoutFilePath.c_str(), "a+", stdout) == NULL) FILE *stdoutFile = fopen(stdoutFilePath.c_str(), "a+");
if (stdoutFile == NULL)
{ {
AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", AndroidLog(ANDROID_LOG_ERROR, "Failed to open stdout file: %s: %s\n",
stdoutFilePath.c_str(), strerror(errno)); stdoutFilePath.c_str(), strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int oldStdout = dup(STDOUT_FILENO);
if (oldStdout == -1)
{
AndroidLog(ANDROID_LOG_ERROR, "Failed to dup stdout: %d\n", errno);
fclose(stdoutFile);
exit(EXIT_FAILURE);
}
int retVal = dup2(fileno(stdoutFile), STDOUT_FILENO);
if (retVal == -1)
{
AndroidLog(ANDROID_LOG_ERROR, "Failed to dup2 stdout to file: %d\n", errno);
fclose(stdoutFile);
close(oldStdout);
exit(EXIT_FAILURE);
}
dup2(STDOUT_FILENO, STDERR_FILENO); dup2(STDOUT_FILENO, STDERR_FILENO);
std::vector<char *> argv; std::vector<char *> argv;
size_t argc = ArgsToArgv(args, &argv); size_t argc = ArgsToArgv(args, &argv);
ScopedMainEntryLogger scoped_main_entry_logger; {
main(static_cast<int>(argc), &argv[0]); ScopedMainEntryLogger scoped_main_entry_logger;
main(static_cast<int>(argc), &argv[0]);
}
fclose(stdoutFile);
dup2(oldStdout, STDOUT_FILENO);
close(oldStdout);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment