| 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 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 ScopedProcess::ScopedProcess(const base::Closure& child_callback) | 37 ScopedProcess::ScopedProcess(const base::Closure& child_callback) |
| 38 : child_process_id_(-1), process_id_(getpid()) { | 38 : child_process_id_(-1), process_id_(getpid()) { |
| 39 PCHECK(0 == pipe(pipe_fds_)); | 39 PCHECK(0 == pipe(pipe_fds_)); |
| 40 #if !defined(THREAD_SANITIZER) | 40 #if !defined(THREAD_SANITIZER) |
| 41 // Make sure that we can safely fork(). | 41 // Make sure that we can safely fork(). |
| 42 CHECK(ThreadHelpers::IsSingleThreaded(-1)); | 42 CHECK(ThreadHelpers::IsSingleThreaded()); |
| 43 #endif | 43 #endif |
| 44 child_process_id_ = fork(); | 44 child_process_id_ = fork(); |
| 45 PCHECK(0 <= child_process_id_); | 45 PCHECK(0 <= child_process_id_); |
| 46 | 46 |
| 47 if (0 == child_process_id_) { | 47 if (0 == child_process_id_) { |
| 48 PCHECK(0 == IGNORE_EINTR(close(pipe_fds_[0]))); | 48 PCHECK(0 == IGNORE_EINTR(close(pipe_fds_[0]))); |
| 49 pipe_fds_[0] = -1; | 49 pipe_fds_[0] = -1; |
| 50 child_callback.Run(); | 50 child_callback.Run(); |
| 51 // Notify the parent that the closure has run. | 51 // Notify the parent that the closure has run. |
| 52 CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds_[1], kSynchronisationChar, 1))); | 52 CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds_[1], kSynchronisationChar, 1))); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // 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 |
| 112 // this object. | 112 // this object. |
| 113 // This method allows to assert it is not happening. | 113 // This method allows to assert it is not happening. |
| 114 bool ScopedProcess::IsOriginalProcess() { | 114 bool ScopedProcess::IsOriginalProcess() { |
| 115 // Make a direct syscall to bypass glibc caching of PIDs. | 115 // Make a direct syscall to bypass glibc caching of PIDs. |
| 116 pid_t pid = sys_getpid(); | 116 pid_t pid = sys_getpid(); |
| 117 return pid == process_id_; | 117 return pid == process_id_; |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace sandbox | 120 } // namespace sandbox |
| OLD | NEW |