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 "net/test/spawned_test_server/local_test_server.h" | 5 #include "net/test/spawned_test_server/local_test_server.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 int pipefd[2]; | 120 int pipefd[2]; |
121 if (pipe(pipefd) != 0) { | 121 if (pipe(pipefd) != 0) { |
122 PLOG(ERROR) << "Could not create pipe."; | 122 PLOG(ERROR) << "Could not create pipe."; |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 // Save the read half. The write half is sent to the child. | 126 // Save the read half. The write half is sent to the child. |
127 child_fd_.reset(pipefd[0]); | 127 child_fd_.reset(pipefd[0]); |
128 base::ScopedFD write_closer(pipefd[1]); | 128 base::ScopedFD write_closer(pipefd[1]); |
129 base::FileHandleMappingVector map_write_fd; | |
130 map_write_fd.push_back(std::make_pair(pipefd[1], pipefd[1])); | |
131 | 129 |
132 python_command.AppendArg("--startup-pipe=" + base::IntToString(pipefd[1])); | 130 python_command.AppendArg("--startup-pipe=" + base::IntToString(pipefd[1])); |
133 | 131 |
134 // Try to kill any orphaned testserver processes that may be running. | 132 // Try to kill any orphaned testserver processes that may be running. |
135 OrphanedTestServerFilter filter(testserver_path.value(), | 133 OrphanedTestServerFilter filter(testserver_path.value(), |
136 base::UintToString(GetPort())); | 134 base::UintToString(GetPort())); |
137 if (!base::KillProcesses("python", -1, &filter)) { | 135 if (!base::KillProcesses("python", -1, &filter)) { |
138 LOG(WARNING) << "Failed to clean up older orphaned testserver instances."; | 136 LOG(WARNING) << "Failed to clean up older orphaned testserver instances."; |
139 } | 137 } |
140 | 138 |
141 // Launch a new testserver process. | 139 // Launch a new testserver process. |
142 base::LaunchOptions options; | 140 base::LaunchOptions options; |
143 | 141 options.fds_to_remap.push_back(std::make_pair(pipefd[1], pipefd[1])); |
144 options.fds_to_remap = &map_write_fd; | |
145 process_ = base::LaunchProcess(python_command, options); | 142 process_ = base::LaunchProcess(python_command, options); |
146 if (!process_.IsValid()) { | 143 if (!process_.IsValid()) { |
147 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); | 144 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); |
148 return false; | 145 return false; |
149 } | 146 } |
150 | 147 |
151 return true; | 148 return true; |
152 } | 149 } |
153 | 150 |
154 bool LocalTestServer::WaitToStart() { | 151 bool LocalTestServer::WaitToStart() { |
(...skipping 18 matching lines...) Expand all Loading... |
173 | 170 |
174 if (!ParseServerData(server_data)) { | 171 if (!ParseServerData(server_data)) { |
175 LOG(ERROR) << "Could not parse server_data: " << server_data; | 172 LOG(ERROR) << "Could not parse server_data: " << server_data; |
176 return false; | 173 return false; |
177 } | 174 } |
178 | 175 |
179 return true; | 176 return true; |
180 } | 177 } |
181 | 178 |
182 } // namespace net | 179 } // namespace net |
OLD | NEW |