OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser/zygote_host_linux.h" | 5 #include "chrome/browser/zygote_host_linux.h" |
6 | 6 |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 DCHECK(init_); | 304 DCHECK(init_); |
305 Pickle pickle; | 305 Pickle pickle; |
306 | 306 |
307 pickle.WriteInt(kCmdReap); | 307 pickle.WriteInt(kCmdReap); |
308 pickle.WriteInt(process); | 308 pickle.WriteInt(process); |
309 | 309 |
310 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) | 310 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) |
311 PLOG(ERROR) << "write"; | 311 PLOG(ERROR) << "write"; |
312 } | 312 } |
313 | 313 |
314 bool ZygoteHost::DidProcessCrash(base::ProcessHandle handle, | 314 base::TerminationStatus ZygoteHost::GetTerminationStatus( |
315 bool* child_exited) { | 315 base::ProcessHandle handle, |
| 316 int* exit_code) { |
316 DCHECK(init_); | 317 DCHECK(init_); |
317 Pickle pickle; | 318 Pickle pickle; |
318 pickle.WriteInt(kCmdDidProcessCrash); | 319 pickle.WriteInt(kCmdGetTerminationStatus); |
319 pickle.WriteInt(handle); | 320 pickle.WriteInt(handle); |
320 | 321 |
| 322 // Set this now to handle the early termination cases. |
| 323 if (exit_code) |
| 324 *exit_code = base::EXIT_CODE_NORMAL_TERMINATION; |
| 325 |
321 static const unsigned kMaxMessageLength = 128; | 326 static const unsigned kMaxMessageLength = 128; |
322 char buf[kMaxMessageLength]; | 327 char buf[kMaxMessageLength]; |
323 ssize_t len; | 328 ssize_t len; |
324 { | 329 { |
325 AutoLock lock(control_lock_); | 330 AutoLock lock(control_lock_); |
326 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) | 331 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) |
327 PLOG(ERROR) << "write"; | 332 PLOG(ERROR) << "write"; |
328 | 333 |
329 len = ReadReply(buf, sizeof(buf)); | 334 len = ReadReply(buf, sizeof(buf)); |
330 } | 335 } |
331 | 336 |
332 if (len == -1) { | 337 if (len == -1) { |
333 LOG(WARNING) << "Error reading message from zygote: " << errno; | 338 LOG(WARNING) << "Error reading message from zygote: " << errno; |
334 return false; | 339 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
335 } else if (len == 0) { | 340 } else if (len == 0) { |
336 LOG(WARNING) << "Socket closed prematurely."; | 341 LOG(WARNING) << "Socket closed prematurely."; |
337 return false; | 342 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
338 } | 343 } |
339 | 344 |
340 Pickle read_pickle(buf, len); | 345 Pickle read_pickle(buf, len); |
341 bool did_crash, tmp_child_exited; | 346 int status, tmp_exit_code; |
342 void* iter = NULL; | 347 void* iter = NULL; |
343 if (!read_pickle.ReadBool(&iter, &did_crash) || | 348 if (!read_pickle.ReadInt(&iter, &status) || |
344 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { | 349 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
345 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; | 350 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
346 return false; | 351 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
347 } | 352 } |
348 | 353 |
349 if (child_exited) | 354 if (exit_code) |
350 *child_exited = tmp_child_exited; | 355 *exit_code = tmp_exit_code; |
351 | 356 |
352 return did_crash; | 357 return static_cast<base::TerminationStatus>(status); |
353 } | 358 } |
OLD | NEW |