From b8cbfff0d35ee41e9afd42ba1e4119f4b4bd6504 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Wed, 11 Mar 2015 13:59:46 -0400 Subject: [PATCH] test::Multiprocess: exit cleanly from children with _exit(). Child exits were using exit(), which caused crashes on 10.10 for Multiprocess-based tests that ran after HTTPTransport tests. The crashes occurred while running exit-time destructors. exit() was never correct in this situation, this should have used _exit() all along. TEST=crashpad_util_test BUG=crashpad:17 R=rsesek@chromium.org Review URL: https://codereview.chromium.org/1000653002 --- util/test/multiprocess.h | 11 ++++++++--- util/test/multiprocess_posix.cc | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/util/test/multiprocess.h b/util/test/multiprocess.h index e5d71dd5..0672b7aa 100644 --- a/util/test/multiprocess.h +++ b/util/test/multiprocess.h @@ -164,9 +164,9 @@ class Multiprocess { //! \brief Runs the child side of the test. //! //! This method establishes the child’s environment, calls - //! MultiprocessChild(), and exits cleanly. However, if any failure (via fatal - //! or nonfatal gtest assertion) is detected, the child will exit with a - //! failure status. + //! MultiprocessChild(), and exits cleanly by calling `_exit(0)`. However, if + //! any failure (via fatal or nonfatal gtest assertion) is detected, the child + //! will exit with a failure status. void RunChild(); //! \brief The subclass-provided parent routine. @@ -186,6 +186,11 @@ class Multiprocess { //! `FAIL()`, etc. //! //! Subclasses must implement this method to define how the child operates. + //! Subclasses may exit with a failure status by using `LOG(FATAL)`, + //! `abort()`, or similar. They may exit cleanly by returning from this method + //! or by calling `_exit(0)`. Under no circumstances may `exit()` be called + //! by the child without having the child process `exec()`. Use + //! MultiprocessExec if the child should call `exec()`. virtual void MultiprocessChild() = 0; internal::MultiprocessInfo* info_; diff --git a/util/test/multiprocess_posix.cc b/util/test/multiprocess_posix.cc index f50446b1..fbb39dfd 100644 --- a/util/test/multiprocess_posix.cc +++ b/util/test/multiprocess_posix.cc @@ -212,7 +212,8 @@ void Multiprocess::RunChild() { return; } - exit(0); + // In a forked child, exit() is unsafe. Use _exit() instead. + _exit(EXIT_SUCCESS); } } // namespace test