summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormdempsky@chromium.org <mdempsky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 00:07:33 +0000
committermdempsky@chromium.org <mdempsky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-18 00:07:33 +0000
commit3a1612420741cb7c84cb0a1d3b2fd2b6fcc68a34 (patch)
tree79b4266127a1a5aa620113d43467d9372c06b009
parent45214559b6f71458336f00f850e02e43d3cd8415 (diff)
downloadchromium_src-3a1612420741cb7c84cb0a1d3b2fd2b6fcc68a34.zip
chromium_src-3a1612420741cb7c84cb0a1d3b2fd2b6fcc68a34.tar.gz
chromium_src-3a1612420741cb7c84cb0a1d3b2fd2b6fcc68a34.tar.bz2
Clean up ZygoteForkDelegate API a little
We always pass channel_switch as "--channel=XYZ" and then the recipient pointlessly verifies that it still starts with "--channel=". So instead rename AckChild() parameter to channel_id and just pass the "XYZ" part to remove a possible failure case, and simplify the receiving code a little bit. BUG=357670 Review URL: https://codereview.chromium.org/239333009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264681 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--components/nacl/loader/nacl_helper_linux.cc16
-rw-r--r--components/nacl/zygote/nacl_fork_delegate_linux.cc9
-rw-r--r--components/nacl/zygote/nacl_fork_delegate_linux.h3
-rw-r--r--content/public/common/zygote_fork_delegate_linux.h4
-rw-r--r--content/zygote/zygote_linux.cc6
-rw-r--r--content/zygote/zygote_linux.h2
6 files changed, 16 insertions, 24 deletions
diff --git a/components/nacl/loader/nacl_helper_linux.cc b/components/nacl/loader/nacl_helper_linux.cc
index 1026feb..70de656 100644
--- a/components/nacl/loader/nacl_helper_linux.cc
+++ b/components/nacl/loader/nacl_helper_linux.cc
@@ -150,21 +150,15 @@ void ChildNaClLoaderInit(const std::vector<int>& child_fds,
// sandbox does) until then, because that can interfere with the
// parent's discovery of our PID.
const ssize_t nread = HANDLE_EINTR(read(parent_fd, buffer, kMaxReadSize));
- const std::string switch_prefix = std::string("--") +
- switches::kProcessChannelID + std::string("=");
- const size_t len = switch_prefix.length();
if (nread < 0) {
perror("read");
LOG(ERROR) << "read returned " << nread;
- } else if (static_cast<size_t>(nread) > len) {
- if (switch_prefix.compare(0, len, buffer, 0, len) == 0) {
- VLOG(1) << "NaCl loader is synchronised with Chrome zygote";
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kProcessChannelID,
- std::string(&buffer[len], nread - len));
- validack = true;
- }
+ } else if (nread > 0) {
+ VLOG(1) << "NaCl loader is synchronised with Chrome zygote";
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kProcessChannelID, std::string(buffer, nread));
+ validack = true;
}
if (IGNORE_EINTR(close(dummy_fd)) != 0)
LOG(ERROR) << "close(dummy_fd) failed";
diff --git a/components/nacl/zygote/nacl_fork_delegate_linux.cc b/components/nacl/zygote/nacl_fork_delegate_linux.cc
index 049d6f3..558344d 100644
--- a/components/nacl/zygote/nacl_fork_delegate_linux.cc
+++ b/components/nacl/zygote/nacl_fork_delegate_linux.cc
@@ -329,11 +329,10 @@ pid_t NaClForkDelegate::Fork(const std::string& process_type,
return nacl_child;
}
-bool NaClForkDelegate::AckChild(const int fd,
- const std::string& channel_switch) {
- int nwritten = HANDLE_EINTR(write(fd, channel_switch.c_str(),
- channel_switch.length()));
- if (nwritten != static_cast<int>(channel_switch.length())) {
+bool NaClForkDelegate::AckChild(const int fd, const std::string& channel_id) {
+ ssize_t nwritten =
+ HANDLE_EINTR(write(fd, channel_id.c_str(), channel_id.length()));
+ if (static_cast<size_t>(nwritten) != channel_id.length()) {
return false;
}
return true;
diff --git a/components/nacl/zygote/nacl_fork_delegate_linux.h b/components/nacl/zygote/nacl_fork_delegate_linux.h
index 4158a5a..a0860b69 100644
--- a/components/nacl/zygote/nacl_fork_delegate_linux.h
+++ b/components/nacl/zygote/nacl_fork_delegate_linux.h
@@ -30,8 +30,7 @@ class NaClForkDelegate : public content::ZygoteForkDelegate {
int* uma_sample, int* uma_boundary_value) OVERRIDE;
virtual pid_t Fork(const std::string& process_type,
const std::vector<int>& fds) OVERRIDE;
- virtual bool AckChild(int fd,
- const std::string& channel_switch) OVERRIDE;
+ virtual bool AckChild(int fd, const std::string& channel_id) OVERRIDE;
virtual bool GetTerminationStatus(pid_t pid, bool known_dead,
base::TerminationStatus* status,
int* exit_code) OVERRIDE;
diff --git a/content/public/common/zygote_fork_delegate_linux.h b/content/public/common/zygote_fork_delegate_linux.h
index f4c8e7b..999721c 100644
--- a/content/public/common/zygote_fork_delegate_linux.h
+++ b/content/public/common/zygote_fork_delegate_linux.h
@@ -66,8 +66,8 @@ class ZygoteForkDelegate {
// After a successful fork, signal the child to indicate that
// the child's PID has been received. Also communicate the
- // channel switch as a part of acknowledgement message.
- virtual bool AckChild(int fd, const std::string& channel_switch) = 0;
+ // channel ID as a part of acknowledgement message.
+ virtual bool AckChild(int fd, const std::string& channel_id) = 0;
// The fork delegate must also assume the role of waiting for its children
// since the caller will not be their parents and cannot do it. |pid| here
diff --git a/content/zygote/zygote_linux.cc b/content/zygote/zygote_linux.cc
index 8ea9714..04e9d83 100644
--- a/content/zygote/zygote_linux.cc
+++ b/content/zygote/zygote_linux.cc
@@ -296,7 +296,7 @@ void Zygote::HandleGetTerminationStatus(int fd,
int Zygote::ForkWithRealPid(const std::string& process_type,
const base::GlobalDescriptors::Mapping& fd_mapping,
- const std::string& channel_switch,
+ const std::string& channel_id,
std::string* uma_name,
int* uma_sample,
int* uma_boundary_value) {
@@ -411,7 +411,7 @@ int Zygote::ForkWithRealPid(const std::string& process_type,
process_info_map_[real_pid].started_from_helper = use_helper;
if (use_helper) {
- if (!helper_->AckChild(pipe_fds[1], channel_switch)) {
+ if (!helper_->AckChild(pipe_fds[1], channel_id)) {
LOG(ERROR) << "Failed to synchronise with zygote fork helper";
goto error;
}
@@ -467,7 +467,7 @@ base::ProcessId Zygote::ReadArgsAndFork(const Pickle& pickle,
return -1;
args.push_back(arg);
if (arg.compare(0, channel_id_prefix.length(), channel_id_prefix) == 0)
- channel_id = arg;
+ channel_id = arg.substr(channel_id_prefix.length());
}
if (!pickle.ReadInt(&iter, &numfds))
diff --git a/content/zygote/zygote_linux.h b/content/zygote/zygote_linux.h
index 37e89b5..140dfa67 100644
--- a/content/zygote/zygote_linux.h
+++ b/content/zygote/zygote_linux.h
@@ -79,7 +79,7 @@ class Zygote {
// UMA_HISTOGRAM_ENUMERATION.
int ForkWithRealPid(const std::string& process_type,
const base::GlobalDescriptors::Mapping& fd_mapping,
- const std::string& channel_switch,
+ const std::string& channel_id,
std::string* uma_name,
int* uma_sample,
int* uma_boundary_value);