| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/process_proxy/process_proxy.h" | 5 #include "chromeos/process_proxy/process_proxy.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <sys/ioctl.h> | 8 #include <sys/ioctl.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 return process_launched_; | 64 return process_launched_; |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool ProcessProxy::StartWatchingOnThread( | 67 bool ProcessProxy::StartWatchingOnThread( |
| 68 base::Thread* watch_thread, | 68 base::Thread* watch_thread, |
| 69 const ProcessOutputCallback& callback) { | 69 const ProcessOutputCallback& callback) { |
| 70 DCHECK(process_launched_); | 70 DCHECK(process_launched_); |
| 71 if (watcher_started_) | 71 if (watcher_started_) |
| 72 return false; | 72 return false; |
| 73 if (pipe(shutdown_pipe_)) | 73 if (pipe(shutdown_pipe_) || |
| 74 !ProcessOutputWatcher::VerifyFileDescriptor( |
| 75 shutdown_pipe_[PIPE_END_READ])) { |
| 74 return false; | 76 return false; |
| 77 } |
| 75 | 78 |
| 76 // We give ProcessOutputWatcher a copy of master to make life easier during | 79 // We give ProcessOutputWatcher a copy of master to make life easier during |
| 77 // tear down. | 80 // tear down. |
| 78 // TODO(tbarzic): improve fd managment. | 81 // TODO(tbarzic): improve fd managment. |
| 79 int master_copy = HANDLE_EINTR(dup(pt_pair_[PT_MASTER_FD])); | 82 int master_copy = HANDLE_EINTR(dup(pt_pair_[PT_MASTER_FD])); |
| 80 if (master_copy == -1) | 83 if (!ProcessOutputWatcher::VerifyFileDescriptor(master_copy)) |
| 81 return false; | 84 return false; |
| 82 | 85 |
| 83 callback_set_ = true; | 86 callback_set_ = true; |
| 84 callback_ = callback; | 87 callback_ = callback; |
| 85 callback_runner_ = base::MessageLoopProxy::current(); | 88 callback_runner_ = base::MessageLoopProxy::current(); |
| 86 | 89 |
| 87 // This object will delete itself once watching is stopped. | 90 // This object will delete itself once watching is stopped. |
| 88 // It also takes ownership of the passed fds. | 91 // It also takes ownership of the passed fds. |
| 89 ProcessOutputWatcher* output_watcher = | 92 ProcessOutputWatcher* output_watcher = |
| 90 new ProcessOutputWatcher(master_copy, | 93 new ProcessOutputWatcher(master_copy, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 ClearFdPair(pt_pair_); | 265 ClearFdPair(pt_pair_); |
| 263 ClearFdPair(shutdown_pipe_); | 266 ClearFdPair(shutdown_pipe_); |
| 264 } | 267 } |
| 265 | 268 |
| 266 void ProcessProxy::ClearFdPair(int* pipe) { | 269 void ProcessProxy::ClearFdPair(int* pipe) { |
| 267 pipe[PIPE_END_READ] = kInvalidFd; | 270 pipe[PIPE_END_READ] = kInvalidFd; |
| 268 pipe[PIPE_END_WRITE] = kInvalidFd; | 271 pipe[PIPE_END_WRITE] = kInvalidFd; |
| 269 } | 272 } |
| 270 | 273 |
| 271 } // namespace chromeos | 274 } // namespace chromeos |
| OLD | NEW |