diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 23:27:11 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-24 23:27:11 +0000 |
commit | 6466e2cedc3398c6bbf8227c5a2c8c1cb9253a75 (patch) | |
tree | 68fa3542f422b3298286829a69cf337a1e434d21 /chrome/common/process_watcher_posix.cc | |
parent | 1ef1023581b9f58105864d771cc4cdbe45a29532 (diff) | |
download | chromium_src-6466e2cedc3398c6bbf8227c5a2c8c1cb9253a75.zip chromium_src-6466e2cedc3398c6bbf8227c5a2c8c1cb9253a75.tar.gz chromium_src-6466e2cedc3398c6bbf8227c5a2c8c1cb9253a75.tar.bz2 |
Revert "POSIX: Don't spawn zombies." (r14488)
Something else is trying to reap children in the ui_tests and causing
a mess. Reverting since it's a Friday night.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/process_watcher_posix.cc')
-rw-r--r-- | chrome/common/process_watcher_posix.cc | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/chrome/common/process_watcher_posix.cc b/chrome/common/process_watcher_posix.cc deleted file mode 100644 index ef73521..0000000 --- a/chrome/common/process_watcher_posix.cc +++ /dev/null @@ -1,79 +0,0 @@ -// 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 <signal.h> -#include <sys/types.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); -} |