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