summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-24 22:09:58 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-24 22:09:58 +0000
commit50faca730337e5145c58b9a8852be735433c8d77 (patch)
treee4dab2a083c8836c0a5f1e1ce8f7b5e2e7c2255b /chrome/common
parent31f23a35436b79adee1c094f7aa37867496ebd07 (diff)
downloadchromium_src-50faca730337e5145c58b9a8852be735433c8d77.zip
chromium_src-50faca730337e5145c58b9a8852be735433c8d77.tar.gz
chromium_src-50faca730337e5145c58b9a8852be735433c8d77.tar.bz2
POSIX: Don't spawn zombies.
TEST=Navigate to several different sites and check that no Chrome zombies are roaming around. BUG=9401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/child_process_host.cc2
-rw-r--r--chrome/common/process_watcher_posix.cc79
-rw-r--r--chrome/common/process_watcher_win.cc (renamed from chrome/common/process_watcher.cc)0
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc5
4 files changed, 80 insertions, 6 deletions
diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc
index 7f934b0..e7a987f 100644
--- a/chrome/common/child_process_host.cc
+++ b/chrome/common/child_process_host.cc
@@ -117,7 +117,7 @@ void ChildProcessHost::OnWaitableEventSignaled(base::WaitableEvent *event) {
DCHECK(handle());
DCHECK_EQ(object, handle());
- bool did_crash = base::DidProcessCrash(object);
+ bool did_crash = base::DidProcessCrash(NULL, object);
if (did_crash) {
// Report that this child process crashed.
Notify(NotificationType::CHILD_PROCESS_CRASHED);
diff --git a/chrome/common/process_watcher_posix.cc b/chrome/common/process_watcher_posix.cc
new file mode 100644
index 0000000..09b2833
--- /dev/null
+++ b/chrome/common/process_watcher_posix.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/process_watcher.h"
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/signal.h>
+#include <sys/wait.h>
+
+#include "base/platform_thread.h"
+
+// Return true if the given child is dead. This will also reap the process.
+// Doesn't block.
+static bool IsChildDead(pid_t child) {
+ const int result = waitpid(child, NULL, WNOHANG);
+ if (result == -1) {
+ NOTREACHED();
+ } else if (result > 0) {
+ // The child has died.
+ return true;
+ }
+
+ return false;
+}
+
+// A thread class which waits for the given child to exit and reaps it.
+// If the child doesn't exit within a couple of seconds, kill it.
+class BackgroundReaper : public PlatformThread::Delegate {
+ public:
+ explicit BackgroundReaper(pid_t child)
+ : child_(child) {
+ }
+
+ void ThreadMain() {
+ WaitForChildToDie();
+ delete this;
+ }
+
+ void WaitForChildToDie() {
+ // There's no good way to wait for a specific child to exit in a timed
+ // fashion. (No kqueue on Linux), so we just loop and sleep.
+
+ // Waits 0.5 * 4 = 2 seconds.
+ for (unsigned i = 0; i < 4; ++i) {
+ PlatformThread::Sleep(500); // 0.5 seconds
+ if (IsChildDead(child_))
+ return;
+ }
+
+ if (kill(child_, SIGKILL) == 0) {
+ // SIGKILL is uncatchable. Since the signal was delivered, we can
+ // just wait for the process to die now in a blocking manner.
+ int result;
+ do {
+ result = waitpid(child_, NULL, 0);
+ } while (result == -1 && errno == EINTR);
+ } else {
+ LOG(ERROR) << "While waiting for " << child_ << " to terminate we"
+ << " failed to deliver a SIGKILL signal (" << errno << ").";
+ }
+ }
+
+ private:
+ const pid_t child_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundReaper);
+};
+
+// static
+void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) {
+ // If the child is already dead, then there's nothing to do
+ if (IsChildDead(process))
+ return;
+
+ BackgroundReaper* reaper = new BackgroundReaper(process);
+ PlatformThread::CreateNonJoinable(0, reaper);
+}
diff --git a/chrome/common/process_watcher.cc b/chrome/common/process_watcher_win.cc
index 1ee7edf..1ee7edf 100644
--- a/chrome/common/process_watcher.cc
+++ b/chrome/common/process_watcher_win.cc
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index 9aeb0cc..1245200 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -232,11 +232,6 @@ LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info,
return NULL;
}
-void ProcessWatcher::EnsureProcessTerminated(int) {
- NOTIMPLEMENTED();
-}
-
-
//--------------------------------------------------------------------------
namespace webkit_glue {