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 "content/browser/zygote_host/zygote_host_impl_linux.h" | 5 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 return base::kNullProcessHandle; | 362 return base::kNullProcessHandle; |
363 } | 363 } |
364 | 364 |
365 // Read the reply, which pickles the PID and an optional UMA enumeration. | 365 // Read the reply, which pickles the PID and an optional UMA enumeration. |
366 static const unsigned kMaxReplyLength = 2048; | 366 static const unsigned kMaxReplyLength = 2048; |
367 char buf[kMaxReplyLength]; | 367 char buf[kMaxReplyLength]; |
368 const ssize_t len = ReadReply(buf, sizeof(buf)); | 368 const ssize_t len = ReadReply(buf, sizeof(buf)); |
369 | 369 |
370 Pickle reply_pickle(buf, len); | 370 Pickle reply_pickle(buf, len); |
371 PickleIterator iter(reply_pickle); | 371 PickleIterator iter(reply_pickle); |
372 if (len <= 0 || !iter.ReadInt(&pid)) | 372 if (len <= 0 || !reply_pickle.ReadInt(&iter, &pid)) |
373 return base::kNullProcessHandle; | 373 return base::kNullProcessHandle; |
374 | 374 |
375 // If there is a nonempty UMA name string, then there is a UMA | 375 // If there is a nonempty UMA name string, then there is a UMA |
376 // enumeration to record. | 376 // enumeration to record. |
377 std::string uma_name; | 377 std::string uma_name; |
378 int uma_sample; | 378 int uma_sample; |
379 int uma_boundary_value; | 379 int uma_boundary_value; |
380 if (iter.ReadString(&uma_name) && | 380 if (reply_pickle.ReadString(&iter, &uma_name) && |
381 !uma_name.empty() && | 381 !uma_name.empty() && |
382 iter.ReadInt(&uma_sample) && | 382 reply_pickle.ReadInt(&iter, &uma_sample) && |
383 iter.ReadInt(&uma_boundary_value)) { | 383 reply_pickle.ReadInt(&iter, &uma_boundary_value)) { |
384 // We cannot use the UMA_HISTOGRAM_ENUMERATION macro here, | 384 // We cannot use the UMA_HISTOGRAM_ENUMERATION macro here, |
385 // because that's only for when the name is the same every time. | 385 // because that's only for when the name is the same every time. |
386 // Here we're using whatever name we got from the other side. | 386 // Here we're using whatever name we got from the other side. |
387 // But since it's likely that the same one will be used repeatedly | 387 // But since it's likely that the same one will be used repeatedly |
388 // (even though it's not guaranteed), we cache it here. | 388 // (even though it's not guaranteed), we cache it here. |
389 static base::HistogramBase* uma_histogram; | 389 static base::HistogramBase* uma_histogram; |
390 if (!uma_histogram || uma_histogram->histogram_name() != uma_name) { | 390 if (!uma_histogram || uma_histogram->histogram_name() != uma_name) { |
391 uma_histogram = base::LinearHistogram::FactoryGet( | 391 uma_histogram = base::LinearHistogram::FactoryGet( |
392 uma_name, 1, | 392 uma_name, 1, |
393 uma_boundary_value, | 393 uma_boundary_value, |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 int status = base::TERMINATION_STATUS_NORMAL_TERMINATION; | 525 int status = base::TERMINATION_STATUS_NORMAL_TERMINATION; |
526 | 526 |
527 if (len == -1) { | 527 if (len == -1) { |
528 LOG(WARNING) << "Error reading message from zygote: " << errno; | 528 LOG(WARNING) << "Error reading message from zygote: " << errno; |
529 } else if (len == 0) { | 529 } else if (len == 0) { |
530 LOG(WARNING) << "Socket closed prematurely."; | 530 LOG(WARNING) << "Socket closed prematurely."; |
531 } else { | 531 } else { |
532 Pickle read_pickle(buf, len); | 532 Pickle read_pickle(buf, len); |
533 int tmp_status, tmp_exit_code; | 533 int tmp_status, tmp_exit_code; |
534 PickleIterator iter(read_pickle); | 534 PickleIterator iter(read_pickle); |
535 if (!iter.ReadInt(&tmp_status) || !iter.ReadInt(&tmp_exit_code)) { | 535 if (!read_pickle.ReadInt(&iter, &tmp_status) || |
| 536 !read_pickle.ReadInt(&iter, &tmp_exit_code)) { |
536 LOG(WARNING) | 537 LOG(WARNING) |
537 << "Error parsing GetTerminationStatus response from zygote."; | 538 << "Error parsing GetTerminationStatus response from zygote."; |
538 } else { | 539 } else { |
539 if (exit_code) | 540 if (exit_code) |
540 *exit_code = tmp_exit_code; | 541 *exit_code = tmp_exit_code; |
541 status = tmp_status; | 542 status = tmp_status; |
542 } | 543 } |
543 } | 544 } |
544 | 545 |
545 if (status != base::TERMINATION_STATUS_STILL_RUNNING) { | 546 if (status != base::TERMINATION_STATUS_STILL_RUNNING) { |
546 ZygoteChildDied(handle); | 547 ZygoteChildDied(handle); |
547 } | 548 } |
548 return static_cast<base::TerminationStatus>(status); | 549 return static_cast<base::TerminationStatus>(status); |
549 } | 550 } |
550 | 551 |
551 pid_t ZygoteHostImpl::GetPid() const { | 552 pid_t ZygoteHostImpl::GetPid() const { |
552 return pid_; | 553 return pid_; |
553 } | 554 } |
554 | 555 |
555 int ZygoteHostImpl::GetSandboxStatus() const { | 556 int ZygoteHostImpl::GetSandboxStatus() const { |
556 if (have_read_sandbox_status_word_) | 557 if (have_read_sandbox_status_word_) |
557 return sandbox_status_; | 558 return sandbox_status_; |
558 return 0; | 559 return 0; |
559 } | 560 } |
560 | 561 |
561 } // namespace content | 562 } // namespace content |
OLD | NEW |