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