| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/linux/services/scoped_process.h" | 5 #include "sandbox/linux/services/scoped_process.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/syscall.h> | 10 #include <sys/syscall.h> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 int ScopedProcess::WaitForExit(bool* got_signaled) { | 78 int ScopedProcess::WaitForExit(bool* got_signaled) { |
| 79 DCHECK(got_signaled); | 79 DCHECK(got_signaled); |
| 80 CHECK(IsOriginalProcess()); | 80 CHECK(IsOriginalProcess()); |
| 81 siginfo_t process_info; | 81 siginfo_t process_info; |
| 82 // WNOWAIT to make sure that the destructor can wait on the child. | 82 // WNOWAIT to make sure that the destructor can wait on the child. |
| 83 int ret = HANDLE_EINTR( | 83 int ret = HANDLE_EINTR( |
| 84 waitid(P_PID, child_process_id_, &process_info, WEXITED | WNOWAIT)); | 84 waitid(P_PID, child_process_id_, &process_info, WEXITED | WNOWAIT)); |
| 85 PCHECK(0 == ret) << "Did something else wait on the child?"; | 85 // Did something else wait on the child? |
| 86 CHECK(0 == ret); |
| 86 | 87 |
| 87 if (process_info.si_code == CLD_EXITED) { | 88 if (process_info.si_code == CLD_EXITED) { |
| 88 *got_signaled = false; | 89 *got_signaled = false; |
| 89 } else if (process_info.si_code == CLD_KILLED || | 90 } else if (process_info.si_code == CLD_KILLED || |
| 90 process_info.si_code == CLD_DUMPED) { | 91 process_info.si_code == CLD_DUMPED) { |
| 91 *got_signaled = true; | 92 *got_signaled = true; |
| 92 } else { | 93 } else { |
| 93 CHECK(false) << "ScopedProcess needs to be extended for si_code " | 94 // ScopedProcess needs to be extended for si_code |process_info.si_code| |
| 94 << process_info.si_code; | 95 CHECK(false); |
| 95 } | 96 } |
| 96 return process_info.si_status; | 97 return process_info.si_status; |
| 97 } | 98 } |
| 98 | 99 |
| 99 bool ScopedProcess::WaitForClosureToRun() { | 100 bool ScopedProcess::WaitForClosureToRun() { |
| 100 char c = 0; | 101 char c = 0; |
| 101 int ret = HANDLE_EINTR(read(pipe_fds_[0], &c, 1)); | 102 int ret = HANDLE_EINTR(read(pipe_fds_[0], &c, 1)); |
| 102 PCHECK(ret >= 0); | 103 PCHECK(ret >= 0); |
| 103 if (0 == ret) | 104 if (0 == ret) |
| 104 return false; | 105 return false; |
| 105 | 106 |
| 106 CHECK_EQ(c, kSynchronisationChar[0]); | 107 CHECK_EQ(c, kSynchronisationChar[0]); |
| 107 return true; | 108 return true; |
| 108 } | 109 } |
| 109 | 110 |
| 110 // It would be problematic if after a fork(), another process would start using | 111 // It would be problematic if after a fork(), another process would start using |
| 111 // this object. | 112 // this object. |
| 112 // This method allows to assert it is not happening. | 113 // This method allows to assert it is not happening. |
| 113 bool ScopedProcess::IsOriginalProcess() { | 114 bool ScopedProcess::IsOriginalProcess() { |
| 114 // Make a direct syscall to bypass glibc caching of PIDs. | 115 // Make a direct syscall to bypass glibc caching of PIDs. |
| 115 pid_t pid = sys_getpid(); | 116 pid_t pid = sys_getpid(); |
| 116 return pid == process_id_; | 117 return pid == process_id_; |
| 117 } | 118 } |
| 118 | 119 |
| 119 } // namespace sandbox | 120 } // namespace sandbox |
| OLD | NEW |