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> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/eintr_wrapper.h" | 13 #include "base/eintr_wrapper.h" |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/linux_util.h" | 15 #include "base/linux_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/pickle.h" | 18 #include "base/pickle.h" |
19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/scoped_ptr.h" | 22 #include "base/scoped_ptr.h" |
23 #include "base/unix_domain_socket_posix.h" | 23 #include "base/unix_domain_socket_posix.h" |
24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
25 | 25 |
26 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 26 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
27 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/process_watcher.h" | 29 #include "chrome/common/process_watcher.h" |
| 30 #include "chrome/common/result_codes.h" |
30 | 31 |
31 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" | 32 #include "sandbox/linux/suid/suid_unsafe_environment_variables.h" |
32 | 33 |
33 static void SaveSUIDUnsafeEnvironmentVariables() { | 34 static void SaveSUIDUnsafeEnvironmentVariables() { |
34 // The ELF loader will clear many environment variables so we save them to | 35 // The ELF loader will clear many environment variables so we save them to |
35 // different names here so that the SUID sandbox can resolve them for the | 36 // different names here so that the SUID sandbox can resolve them for the |
36 // renderer. | 37 // renderer. |
37 | 38 |
38 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) { | 39 for (unsigned i = 0; kSUIDUnsafeEnvironmentVariables[i]; ++i) { |
39 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i]; | 40 const char* const envvar = kSUIDUnsafeEnvironmentVariables[i]; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 DCHECK(init_); | 310 DCHECK(init_); |
310 Pickle pickle; | 311 Pickle pickle; |
311 | 312 |
312 pickle.WriteInt(kCmdReap); | 313 pickle.WriteInt(kCmdReap); |
313 pickle.WriteInt(process); | 314 pickle.WriteInt(process); |
314 | 315 |
315 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) | 316 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) |
316 PLOG(ERROR) << "write"; | 317 PLOG(ERROR) << "write"; |
317 } | 318 } |
318 | 319 |
319 bool ZygoteHost::DidProcessCrash(base::ProcessHandle handle, | 320 base::TerminationStatus ZygoteHost::GetTerminationStatus( |
320 bool* child_exited) { | 321 base::ProcessHandle handle, |
| 322 int* exit_code) { |
321 DCHECK(init_); | 323 DCHECK(init_); |
322 Pickle pickle; | 324 Pickle pickle; |
323 pickle.WriteInt(kCmdDidProcessCrash); | 325 pickle.WriteInt(kCmdGetTerminationStatus); |
324 pickle.WriteInt(handle); | 326 pickle.WriteInt(handle); |
325 | 327 |
| 328 // Set this now to handle the early termination cases. |
| 329 if (exit_code) |
| 330 *exit_code = ResultCodes::NORMAL_EXIT; |
| 331 |
326 static const unsigned kMaxMessageLength = 128; | 332 static const unsigned kMaxMessageLength = 128; |
327 char buf[kMaxMessageLength]; | 333 char buf[kMaxMessageLength]; |
328 ssize_t len; | 334 ssize_t len; |
329 { | 335 { |
330 AutoLock lock(control_lock_); | 336 AutoLock lock(control_lock_); |
331 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) | 337 if (HANDLE_EINTR(write(control_fd_, pickle.data(), pickle.size())) < 0) |
332 PLOG(ERROR) << "write"; | 338 PLOG(ERROR) << "write"; |
333 | 339 |
334 len = ReadReply(buf, sizeof(buf)); | 340 len = ReadReply(buf, sizeof(buf)); |
335 } | 341 } |
336 | 342 |
337 if (len == -1) { | 343 if (len == -1) { |
338 LOG(WARNING) << "Error reading message from zygote: " << errno; | 344 LOG(WARNING) << "Error reading message from zygote: " << errno; |
339 return false; | 345 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
340 } else if (len == 0) { | 346 } else if (len == 0) { |
341 LOG(WARNING) << "Socket closed prematurely."; | 347 LOG(WARNING) << "Socket closed prematurely."; |
342 return false; | 348 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
343 } | 349 } |
344 | 350 |
345 Pickle read_pickle(buf, len); | 351 Pickle read_pickle(buf, len); |
346 bool did_crash, tmp_child_exited; | 352 int status, tmp_exit_code; |
347 void* iter = NULL; | 353 void* iter = NULL; |
348 if (!read_pickle.ReadBool(&iter, &did_crash) || | 354 if (!read_pickle.ReadInt(&iter, &status) || |
349 !read_pickle.ReadBool(&iter, &tmp_child_exited)) { | 355 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
350 LOG(WARNING) << "Error parsing DidProcessCrash response from zygote."; | 356 LOG(WARNING) << "Error parsing GetTerminationStatus response from zygote."; |
351 return false; | 357 return base::TERMINATION_STATUS_NORMAL_TERMINATION; |
352 } | 358 } |
353 | 359 |
354 if (child_exited) | 360 if (exit_code) |
355 *child_exited = tmp_child_exited; | 361 *exit_code = tmp_exit_code; |
356 | 362 |
357 return did_crash; | 363 return static_cast<base::TerminationStatus>(status); |
358 } | 364 } |
OLD | NEW |