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 "components/nacl/zygote/nacl_fork_delegate_linux.h" | 5 #include "components/nacl/zygote/nacl_fork_delegate_linux.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // nacl_helper_bootstrap from succeeding, with its large address space | 199 // nacl_helper_bootstrap from succeeding, with its large address space |
200 // reservation. | 200 // reservation. |
201 std::set<int> max_these_limits; | 201 std::set<int> max_these_limits; |
202 max_these_limits.insert(RLIMIT_AS); | 202 max_these_limits.insert(RLIMIT_AS); |
203 options.maximize_rlimits = &max_these_limits; | 203 options.maximize_rlimits = &max_these_limits; |
204 | 204 |
205 if (!base::LaunchProcess(argv_to_launch, options, NULL)) | 205 if (!base::LaunchProcess(argv_to_launch, options, NULL)) |
206 status_ = kNaClHelperLaunchFailed; | 206 status_ = kNaClHelperLaunchFailed; |
207 // parent and error cases are handled below | 207 // parent and error cases are handled below |
208 } | 208 } |
209 if (HANDLE_EINTR(close(fds[1])) != 0) | 209 if (IGNORE_EINTR(close(fds[1])) != 0) |
210 LOG(ERROR) << "close(fds[1]) failed"; | 210 LOG(ERROR) << "close(fds[1]) failed"; |
211 if (status_ == kNaClHelperUnused) { | 211 if (status_ == kNaClHelperUnused) { |
212 const ssize_t kExpectedLength = strlen(kNaClHelperStartupAck); | 212 const ssize_t kExpectedLength = strlen(kNaClHelperStartupAck); |
213 char buf[kExpectedLength]; | 213 char buf[kExpectedLength]; |
214 | 214 |
215 // Wait for ack from nacl_helper, indicating it is ready to help | 215 // Wait for ack from nacl_helper, indicating it is ready to help |
216 const ssize_t nread = HANDLE_EINTR(read(fds[0], buf, sizeof(buf))); | 216 const ssize_t nread = HANDLE_EINTR(read(fds[0], buf, sizeof(buf))); |
217 if (nread == kExpectedLength && | 217 if (nread == kExpectedLength && |
218 memcmp(buf, kNaClHelperStartupAck, nread) == 0) { | 218 memcmp(buf, kNaClHelperStartupAck, nread) == 0) { |
219 // all is well | 219 // all is well |
220 status_ = kNaClHelperSuccess; | 220 status_ = kNaClHelperSuccess; |
221 fd_ = fds[0]; | 221 fd_ = fds[0]; |
222 return; | 222 return; |
223 } | 223 } |
224 | 224 |
225 status_ = kNaClHelperAckFailed; | 225 status_ = kNaClHelperAckFailed; |
226 LOG(ERROR) << "Bad NaCl helper startup ack (" << nread << " bytes)"; | 226 LOG(ERROR) << "Bad NaCl helper startup ack (" << nread << " bytes)"; |
227 } | 227 } |
228 // TODO(bradchen): Make this LOG(ERROR) when the NaCl helper | 228 // TODO(bradchen): Make this LOG(ERROR) when the NaCl helper |
229 // becomes the default. | 229 // becomes the default. |
230 fd_ = -1; | 230 fd_ = -1; |
231 if (HANDLE_EINTR(close(fds[0])) != 0) | 231 if (IGNORE_EINTR(close(fds[0])) != 0) |
232 LOG(ERROR) << "close(fds[0]) failed"; | 232 LOG(ERROR) << "close(fds[0]) failed"; |
233 } | 233 } |
234 | 234 |
235 void NaClForkDelegate::InitialUMA(std::string* uma_name, | 235 void NaClForkDelegate::InitialUMA(std::string* uma_name, |
236 int* uma_sample, | 236 int* uma_sample, |
237 int* uma_boundary_value) { | 237 int* uma_boundary_value) { |
238 *uma_name = "NaCl.Client.Helper.InitState"; | 238 *uma_name = "NaCl.Client.Helper.InitState"; |
239 *uma_sample = status_; | 239 *uma_sample = status_; |
240 *uma_boundary_value = kNaClHelperStatusBoundary; | 240 *uma_boundary_value = kNaClHelperStatusBoundary; |
241 } | 241 } |
242 | 242 |
243 NaClForkDelegate::~NaClForkDelegate() { | 243 NaClForkDelegate::~NaClForkDelegate() { |
244 // side effect of close: delegate process will terminate | 244 // side effect of close: delegate process will terminate |
245 if (status_ == kNaClHelperSuccess) { | 245 if (status_ == kNaClHelperSuccess) { |
246 if (HANDLE_EINTR(close(fd_)) != 0) | 246 if (IGNORE_EINTR(close(fd_)) != 0) |
247 LOG(ERROR) << "close(fd_) failed"; | 247 LOG(ERROR) << "close(fd_) failed"; |
248 } | 248 } |
249 } | 249 } |
250 | 250 |
251 bool NaClForkDelegate::CanHelp(const std::string& process_type, | 251 bool NaClForkDelegate::CanHelp(const std::string& process_type, |
252 std::string* uma_name, | 252 std::string* uma_name, |
253 int* uma_sample, | 253 int* uma_sample, |
254 int* uma_boundary_value) { | 254 int* uma_boundary_value) { |
255 if (process_type != switches::kNaClLoaderProcess) | 255 if (process_type != switches::kNaClLoaderProcess) |
256 return false; | 256 return false; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 int remote_exit_code; | 342 int remote_exit_code; |
343 if (!iter.ReadInt(&remote_exit_code)) { | 343 if (!iter.ReadInt(&remote_exit_code)) { |
344 LOG(ERROR) << "GetTerminationStatus: pickle failed"; | 344 LOG(ERROR) << "GetTerminationStatus: pickle failed"; |
345 return false; | 345 return false; |
346 } | 346 } |
347 | 347 |
348 *status = static_cast<base::TerminationStatus>(termination_status); | 348 *status = static_cast<base::TerminationStatus>(termination_status); |
349 *exit_code = remote_exit_code; | 349 *exit_code = remote_exit_code; |
350 return true; | 350 return true; |
351 } | 351 } |
OLD | NEW |