| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/process_watcher.h" | 5 #include "chrome/common/process_watcher.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <sys/wait.h> | 10 #include <sys/wait.h> |
| 11 | 11 |
| 12 #include "base/eintr_wrapper.h" | 12 #include "base/eintr_wrapper.h" |
| 13 #include "base/platform_thread.h" | 13 #include "base/platform_thread.h" |
| 14 #include "base/zygote_manager.h" | |
| 15 | 14 |
| 16 // Return true if the given child is dead. This will also reap the process. | 15 // Return true if the given child is dead. This will also reap the process. |
| 17 // Doesn't block. | 16 // Doesn't block. |
| 18 static bool IsChildDead(pid_t child) { | 17 static bool IsChildDead(pid_t child) { |
| 19 const int result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 18 const int result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
| 20 if (result == -1) { | 19 if (result == -1) { |
| 21 NOTREACHED(); | 20 NOTREACHED(); |
| 22 } else if (result > 0) { | 21 } else if (result > 0) { |
| 23 // The child has died. | 22 // The child has died. |
| 24 return true; | 23 return true; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 62 |
| 64 private: | 63 private: |
| 65 const pid_t child_; | 64 const pid_t child_; |
| 66 | 65 |
| 67 DISALLOW_COPY_AND_ASSIGN(BackgroundReaper); | 66 DISALLOW_COPY_AND_ASSIGN(BackgroundReaper); |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 // static | 69 // static |
| 71 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { | 70 void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { |
| 72 // If the child is already dead, then there's nothing to do | 71 // If the child is already dead, then there's nothing to do |
| 73 const int result = HANDLE_EINTR(waitpid(process, NULL, WNOHANG)); | 72 if (IsChildDead(process)) |
| 74 if (result > 0) | |
| 75 return; | 73 return; |
| 76 if (result == -1) { | |
| 77 #if defined(OS_LINUX) | |
| 78 // If it wasn't our child, maybe it was the zygote manager's child | |
| 79 base::ZygoteManager* zm = base::ZygoteManager::Get(); | |
| 80 if (zm) { | |
| 81 zm->EnsureProcessTerminated(process); | |
| 82 return; | |
| 83 } | |
| 84 #endif // defined(OS_LINUX) | |
| 85 NOTREACHED(); | |
| 86 } | |
| 87 | 74 |
| 88 BackgroundReaper* reaper = new BackgroundReaper(process); | 75 BackgroundReaper* reaper = new BackgroundReaper(process); |
| 89 PlatformThread::CreateNonJoinable(0, reaper); | 76 PlatformThread::CreateNonJoinable(0, reaper); |
| 90 } | 77 } |
| OLD | NEW |