| 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 <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <pthread.h> | 7 #include <pthread.h> |
| 8 #include <sys/epoll.h> | 8 #include <sys/epoll.h> |
| 9 #include <sys/prctl.h> | 9 #include <sys/prctl.h> |
| 10 #include <sys/signal.h> | 10 #include <sys/signal.h> |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (pickle.ReadInt(&iter, &kind)) { | 160 if (pickle.ReadInt(&iter, &kind)) { |
| 161 switch (kind) { | 161 switch (kind) { |
| 162 case ZygoteHost::kCmdFork: | 162 case ZygoteHost::kCmdFork: |
| 163 // This function call can return multiple times, once per fork(). | 163 // This function call can return multiple times, once per fork(). |
| 164 return HandleForkRequest(fd, pickle, iter, fds); | 164 return HandleForkRequest(fd, pickle, iter, fds); |
| 165 case ZygoteHost::kCmdReap: | 165 case ZygoteHost::kCmdReap: |
| 166 if (!fds.empty()) | 166 if (!fds.empty()) |
| 167 break; | 167 break; |
| 168 HandleReapRequest(fd, pickle, iter); | 168 HandleReapRequest(fd, pickle, iter); |
| 169 return false; | 169 return false; |
| 170 case ZygoteHost::kCmdDidProcessCrash: | 170 case ZygoteHost::kCmdGetTerminationStatus: |
| 171 if (!fds.empty()) | 171 if (!fds.empty()) |
| 172 break; | 172 break; |
| 173 HandleDidProcessCrash(fd, pickle, iter); | 173 HandleGetTerminationStatus(fd, pickle, iter); |
| 174 return false; | 174 return false; |
| 175 case ZygoteHost::kCmdGetSandboxStatus: | 175 case ZygoteHost::kCmdGetSandboxStatus: |
| 176 HandleGetSandboxStatus(fd, pickle, iter); | 176 HandleGetSandboxStatus(fd, pickle, iter); |
| 177 return false; | 177 return false; |
| 178 default: | 178 default: |
| 179 NOTREACHED(); | 179 NOTREACHED(); |
| 180 break; | 180 break; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 202 if (!actual_child) | 202 if (!actual_child) |
| 203 return; | 203 return; |
| 204 real_pids_to_sandbox_pids.erase(child); | 204 real_pids_to_sandbox_pids.erase(child); |
| 205 } else { | 205 } else { |
| 206 actual_child = child; | 206 actual_child = child; |
| 207 } | 207 } |
| 208 | 208 |
| 209 ProcessWatcher::EnsureProcessTerminated(actual_child); | 209 ProcessWatcher::EnsureProcessTerminated(actual_child); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void HandleDidProcessCrash(int fd, const Pickle& pickle, void* iter) { | 212 void HandleGetTerminationStatus(int fd, const Pickle& pickle, void* iter) { |
| 213 base::ProcessHandle child; | 213 base::ProcessHandle child; |
| 214 | 214 |
| 215 if (!pickle.ReadInt(&iter, &child)) { | 215 if (!pickle.ReadInt(&iter, &child)) { |
| 216 LOG(WARNING) << "Error parsing DidProcessCrash request from browser"; | 216 LOG(WARNING) << "Error parsing GetTerminationStatus request " |
| 217 << "from browser"; |
| 217 return; | 218 return; |
| 218 } | 219 } |
| 219 | 220 |
| 220 bool child_exited; | 221 base::TerminationStatus status; |
| 221 bool did_crash; | 222 int exit_code; |
| 222 if (g_suid_sandbox_active) | 223 if (g_suid_sandbox_active) |
| 223 child = real_pids_to_sandbox_pids[child]; | 224 child = real_pids_to_sandbox_pids[child]; |
| 224 if (child) | 225 if (child) { |
| 225 did_crash = base::DidProcessCrash(&child_exited, child); | 226 status = base::GetTerminationStatus(child, &exit_code); |
| 226 else | 227 } else { |
| 227 did_crash = child_exited = false; | 228 // Assume that if we can't find the child in the sandbox, then |
| 229 // it terminated normally. |
| 230 status = base::TERMINATION_STATUS_NORMAL_TERMINATION; |
| 231 exit_code = base::EXIT_CODE_NORMAL_TERMINATION; |
| 232 } |
| 228 | 233 |
| 229 Pickle write_pickle; | 234 Pickle write_pickle; |
| 230 write_pickle.WriteBool(did_crash); | 235 write_pickle.WriteInt(static_cast<int>(status)); |
| 231 write_pickle.WriteBool(child_exited); | 236 write_pickle.WriteInt(exit_code); |
| 232 if (HANDLE_EINTR(write(fd, write_pickle.data(), write_pickle.size())) != | 237 if (HANDLE_EINTR(write(fd, write_pickle.data(), write_pickle.size())) != |
| 233 write_pickle.size()) { | 238 write_pickle.size()) { |
| 234 PLOG(ERROR) << "write"; | 239 PLOG(ERROR) << "write"; |
| 235 } | 240 } |
| 236 } | 241 } |
| 237 | 242 |
| 238 // This is equivalent to fork(), except that, when using the SUID | 243 // This is equivalent to fork(), except that, when using the SUID |
| 239 // sandbox, it returns the real PID of the child process as it | 244 // sandbox, it returns the real PID of the child process as it |
| 240 // appears outside the sandbox, rather than returning the PID inside | 245 // appears outside the sandbox, rather than returning the PID inside |
| 241 // the sandbox. | 246 // the sandbox. |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 VLOG(1) << "Enabling experimental Seccomp sandbox."; | 744 VLOG(1) << "Enabling experimental Seccomp sandbox."; |
| 740 sandbox_flags |= ZygoteHost::kSandboxSeccomp; | 745 sandbox_flags |= ZygoteHost::kSandboxSeccomp; |
| 741 } | 746 } |
| 742 } | 747 } |
| 743 #endif // SECCOMP_SANDBOX | 748 #endif // SECCOMP_SANDBOX |
| 744 | 749 |
| 745 Zygote zygote(sandbox_flags); | 750 Zygote zygote(sandbox_flags); |
| 746 // This function call can return multiple times, once per fork(). | 751 // This function call can return multiple times, once per fork(). |
| 747 return zygote.ProcessRequests(); | 752 return zygote.ProcessRequests(); |
| 748 } | 753 } |
| OLD | NEW |