| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <unistd.h> | 5 #include <unistd.h> |
| 6 #include <sys/epoll.h> | 6 #include <sys/epoll.h> |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 #include <sys/signal.h> | 9 #include <sys/signal.h> |
| 10 #include <sys/prctl.h> | 10 #include <sys/prctl.h> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (len == 0) { | 70 if (len == 0) { |
| 71 // EOF from the browser. We should die. | 71 // EOF from the browser. We should die. |
| 72 _exit(0); | 72 _exit(0); |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 Pickle pickle(buf, len); | 76 Pickle pickle(buf, len); |
| 77 void* iter = NULL; | 77 void* iter = NULL; |
| 78 | 78 |
| 79 int kind; | 79 int kind; |
| 80 if (!pickle.ReadInt(&iter, &kind)) | 80 if (pickle.ReadInt(&iter, &kind)) { |
| 81 goto error; | 81 switch (kind) { |
| 82 | 82 case ZygoteHost::kCmdFork: |
| 83 if (kind == ZygoteHost::kCmdFork) { | 83 return HandleForkRequest(fd, pickle, iter, fds); |
| 84 return HandleForkRequest(fd, pickle, iter, fds); | 84 case ZygoteHost::kCmdReap: |
| 85 } else if (kind == ZygoteHost::kCmdReap) { | 85 if (!fds.empty()) |
| 86 if (fds.size()) | 86 break; |
| 87 goto error; | 87 return HandleReapRequest(fd, pickle, iter); |
| 88 return HandleReapRequest(fd, pickle, iter); | 88 case ZygoteHost::kCmdDidProcessCrash: |
| 89 if (!fds.empty()) |
| 90 break; |
| 91 return HandleDidProcessCrash(fd, pickle, iter); |
| 92 default: |
| 93 NOTREACHED(); |
| 94 break; |
| 95 } |
| 89 } | 96 } |
| 90 | 97 |
| 91 error: | |
| 92 LOG(WARNING) << "Error parsing message from browser"; | 98 LOG(WARNING) << "Error parsing message from browser"; |
| 93 for (std::vector<int>::const_iterator | 99 for (std::vector<int>::const_iterator |
| 94 i = fds.begin(); i != fds.end(); ++i) | 100 i = fds.begin(); i != fds.end(); ++i) |
| 95 close(*i); | 101 close(*i); |
| 96 return false; | 102 return false; |
| 97 } | 103 } |
| 98 | 104 |
| 99 bool HandleReapRequest(int fd, Pickle& pickle, void* iter) { | 105 bool HandleReapRequest(int fd, Pickle& pickle, void* iter) { |
| 100 pid_t child; | 106 pid_t child; |
| 101 | 107 |
| 102 if (!pickle.ReadInt(&iter, &child)) { | 108 if (!pickle.ReadInt(&iter, &child)) { |
| 103 LOG(WARNING) << "Error parsing reap request from browser"; | 109 LOG(WARNING) << "Error parsing reap request from browser"; |
| 104 return false; | 110 return false; |
| 105 } | 111 } |
| 106 | 112 |
| 107 ProcessWatcher::EnsureProcessTerminated(child); | 113 ProcessWatcher::EnsureProcessTerminated(child); |
| 108 | 114 |
| 109 return false; | 115 return false; |
| 110 } | 116 } |
| 111 | 117 |
| 118 bool HandleDidProcessCrash(int fd, Pickle& pickle, void* iter) { |
| 119 base::ProcessHandle child; |
| 120 |
| 121 if (!pickle.ReadInt(&iter, &child)) { |
| 122 LOG(WARNING) << "Error parsing DidProcessCrash request from browser"; |
| 123 return false; |
| 124 } |
| 125 |
| 126 bool child_exited; |
| 127 bool did_crash = base::DidProcessCrash(&child_exited, child); |
| 128 |
| 129 Pickle write_pickle; |
| 130 write_pickle.WriteBool(did_crash); |
| 131 write_pickle.WriteBool(child_exited); |
| 132 HANDLE_EINTR(write(fd, write_pickle.data(), write_pickle.size())); |
| 133 |
| 134 return false; |
| 135 } |
| 136 |
| 112 // Handle a 'fork' request from the browser: this means that the browser | 137 // Handle a 'fork' request from the browser: this means that the browser |
| 113 // wishes to start a new renderer. | 138 // wishes to start a new renderer. |
| 114 bool HandleForkRequest(int fd, Pickle& pickle, void* iter, | 139 bool HandleForkRequest(int fd, Pickle& pickle, void* iter, |
| 115 std::vector<int>& fds) { | 140 std::vector<int>& fds) { |
| 116 std::vector<std::string> args; | 141 std::vector<std::string> args; |
| 117 int argc, numfds; | 142 int argc, numfds; |
| 118 base::GlobalDescriptors::Mapping mapping; | 143 base::GlobalDescriptors::Mapping mapping; |
| 119 pid_t child; | 144 pid_t child; |
| 120 | 145 |
| 121 if (!pickle.ReadInt(&iter, &argc)) | 146 if (!pickle.ReadInt(&iter, &argc)) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 bool ZygoteMain(const MainFunctionParams& params) { | 237 bool ZygoteMain(const MainFunctionParams& params) { |
| 213 if (!MaybeEnterChroot()) { | 238 if (!MaybeEnterChroot()) { |
| 214 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " | 239 LOG(FATAL) << "Failed to enter sandbox. Fail safe abort. (errno: " |
| 215 << errno << ")"; | 240 << errno << ")"; |
| 216 return false; | 241 return false; |
| 217 } | 242 } |
| 218 | 243 |
| 219 Zygote zygote; | 244 Zygote zygote; |
| 220 return zygote.ProcessRequests(); | 245 return zygote.ProcessRequests(); |
| 221 } | 246 } |
| OLD | NEW |