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 | 14 |
15 // 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. |
16 // Doesn't block. | 16 // Doesn't block. |
17 static bool IsChildDead(pid_t child) { | 17 static bool IsChildDead(pid_t child) { |
18 const int result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); | 18 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, WNOHANG)); |
19 if (result == -1) { | 19 if (result == -1) { |
20 NOTREACHED(); | 20 NOTREACHED(); |
21 } else if (result > 0) { | 21 } else if (result > 0) { |
22 // The child has died. | 22 // The child has died. |
23 return true; | 23 return true; |
24 } | 24 } |
25 | 25 |
26 return false; | 26 return false; |
27 } | 27 } |
28 | 28 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 // static | 94 // static |
95 void ProcessWatcher::EnsureProcessGetsReaped(base::ProcessHandle process) { | 95 void ProcessWatcher::EnsureProcessGetsReaped(base::ProcessHandle process) { |
96 // If the child is already dead, then there's nothing to do | 96 // If the child is already dead, then there's nothing to do |
97 if (IsChildDead(process)) | 97 if (IsChildDead(process)) |
98 return; | 98 return; |
99 | 99 |
100 BackgroundReaper* reaper = new BackgroundReaper(process, 0); | 100 BackgroundReaper* reaper = new BackgroundReaper(process, 0); |
101 PlatformThread::CreateNonJoinable(0, reaper); | 101 PlatformThread::CreateNonJoinable(0, reaper); |
102 } | 102 } |
OLD | NEW |