Index: content/zygote/zygote_linux.cc |
diff --git a/content/zygote/zygote_linux.cc b/content/zygote/zygote_linux.cc |
index 893002281218e863a33bfeca97cab5f949d23efe..b8c60d5c08f53de85d18f59b9cafe858045cb476 100644 |
--- a/content/zygote/zygote_linux.cc |
+++ b/content/zygote/zygote_linux.cc |
@@ -5,6 +5,7 @@ |
#include "content/zygote/zygote_linux.h" |
#include <fcntl.h> |
+#include <pthread.h> |
#include <string.h> |
#include <sys/socket.h> |
#include <sys/types.h> |
@@ -24,6 +25,7 @@ |
#include "content/common/set_process_title.h" |
#include "content/common/zygote_commands_linux.h" |
#include "content/public/common/content_descriptors.h" |
+#include "content/public/common/content_switches.h" |
#include "content/public/common/result_codes.h" |
#include "content/public/common/sandbox_linux.h" |
#include "content/public/common/zygote_fork_delegate_linux.h" |
@@ -110,7 +112,17 @@ bool Zygote::HandleRequestFromBrowser(int fd) { |
if (len == 0 || (len == -1 && errno == ECONNRESET)) { |
// EOF from the browser. We should die. |
- _exit(0); |
+ if (CommandLine::ForCurrentProcess()-> |
+ HasSwitch(switches::kChildCleanExit)) |
+ // Zygote children are reaped in a separate detached thread (see the |
+ // implementation of EnsureProcessGetsReaped()). If we _exit() or exit() |
+ // here, the reaping wait may not have completed. For this reason, we |
+ // only terminate this thread (instead of terminating the whole process). |
+ // The zygote will then exit only when all children have exited and have |
+ // been reaped. |
+ pthread_exit(NULL); |
+ else |
+ _exit(0); |
return false; |
} |
@@ -175,7 +187,10 @@ void Zygote::HandleReapRequest(int fd, |
actual_child = child; |
} |
- base::EnsureProcessTerminated(actual_child); |
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChildCleanExit)) |
+ base::EnsureProcessGetsReaped(actual_child); |
+ else |
+ base::EnsureProcessTerminated(actual_child); |
} |
void Zygote::HandleGetTerminationStatus(int fd, |