| 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 "base/test/multiprocess_test.h" | 5 #include "base/test/multiprocess_test.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 // Create a communication channel between the parent and child launch helper. | 137 // Create a communication channel between the parent and child launch helper. |
| 138 // fd[0] belongs to the parent, fd[1] belongs to the child. | 138 // fd[0] belongs to the parent, fd[1] belongs to the child. |
| 139 int fds[2] = {-1, -1}; | 139 int fds[2] = {-1, -1}; |
| 140 int rv = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds); | 140 int rv = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds); |
| 141 PCHECK(rv == 0); | 141 PCHECK(rv == 0); |
| 142 CHECK_NE(-1, fds[0]); | 142 CHECK_NE(-1, fds[0]); |
| 143 CHECK_NE(-1, fds[1]); | 143 CHECK_NE(-1, fds[1]); |
| 144 | 144 |
| 145 pid_t pid = fork(); | 145 pid_t pid = fork(); |
| 146 PCHECK(pid >= 0) << "Fork failed"; | 146 // Fork failed |
| 147 CHECK(pid >= 0); |
| 147 if (pid) { | 148 if (pid) { |
| 148 // Parent. | 149 // Parent. |
| 149 rv = close(fds[1]); | 150 rv = close(fds[1]); |
| 150 PCHECK(rv == 0); | 151 PCHECK(rv == 0); |
| 151 DoParent(fds[0]); | 152 DoParent(fds[0]); |
| 152 } else { | 153 } else { |
| 153 // Helper. | 154 // Helper. |
| 154 rv = close(fds[0]); | 155 rv = close(fds[0]); |
| 155 PCHECK(rv == 0); | 156 PCHECK(rv == 0); |
| 156 DoHelper(fds[1]); | 157 DoHelper(fds[1]); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 default: | 234 default: |
| 234 LOG(FATAL) << "Unsupported message type: " | 235 LOG(FATAL) << "Unsupported message type: " |
| 235 << static_cast<uint32_t>(header->type); | 236 << static_cast<uint32_t>(header->type); |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 void LaunchHelper::StartProcessInHelper(const StartProcessRequest* request, | 241 void LaunchHelper::StartProcessInHelper(const StartProcessRequest* request, |
| 241 std::vector<ScopedFD> fds) { | 242 std::vector<ScopedFD> fds) { |
| 242 pid_t pid = fork(); | 243 pid_t pid = fork(); |
| 243 PCHECK(pid >= 0) << "Fork failed"; | 244 // Fork failed |
| 245 CHECK(pid >= 0); |
| 244 if (pid) { | 246 if (pid) { |
| 245 // Helper. | 247 // Helper. |
| 246 StartProcessResponse resp; | 248 StartProcessResponse resp; |
| 247 resp.child_pid = pid; | 249 resp.child_pid = pid; |
| 248 Send(parent_fd_, reinterpret_cast<const MessageHeader*>(&resp), | 250 Send(parent_fd_, reinterpret_cast<const MessageHeader*>(&resp), |
| 249 std::vector<int>()); | 251 std::vector<int>()); |
| 250 } else { | 252 } else { |
| 251 // Child. | 253 // Child. |
| 252 PCHECK(close(parent_fd_) == 0); | 254 PCHECK(close(parent_fd_) == 0); |
| 253 parent_fd_ = -1; | 255 parent_fd_ = -1; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 447 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 446 command_line->InitFromArgv(base_command_line.argv()); | 448 command_line->InitFromArgv(base_command_line.argv()); |
| 447 if (!command_line->HasSwitch(switches::kTestChildProcess)) | 449 if (!command_line->HasSwitch(switches::kTestChildProcess)) |
| 448 command_line->AppendSwitchASCII(switches::kTestChildProcess, procname); | 450 command_line->AppendSwitchASCII(switches::kTestChildProcess, procname); |
| 449 | 451 |
| 450 _exit(multi_process_function_list::InvokeChildProcessTest(procname)); | 452 _exit(multi_process_function_list::InvokeChildProcessTest(procname)); |
| 451 return Process(); | 453 return Process(); |
| 452 } | 454 } |
| 453 | 455 |
| 454 } // namespace base | 456 } // namespace base |
| OLD | NEW |