| 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/process/launch.h" | 5 #include "base/process/launch.h" |
| 6 | 6 |
| 7 #include <crt_externs.h> | 7 #include <crt_externs.h> |
| 8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
| 9 #include <spawn.h> | 9 #include <spawn.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (null_stdin) { | 133 if (null_stdin) { |
| 134 file_actions.Open(STDIN_FILENO, "/dev/null", O_RDONLY); | 134 file_actions.Open(STDIN_FILENO, "/dev/null", O_RDONLY); |
| 135 } | 135 } |
| 136 if (inherit_stdout) { | 136 if (inherit_stdout) { |
| 137 file_actions.Inherit(STDOUT_FILENO); | 137 file_actions.Inherit(STDOUT_FILENO); |
| 138 } | 138 } |
| 139 if (inherit_stderr) { | 139 if (inherit_stderr) { |
| 140 file_actions.Inherit(STDERR_FILENO); | 140 file_actions.Inherit(STDERR_FILENO); |
| 141 } | 141 } |
| 142 | 142 |
| 143 std::unique_ptr<char* []> argv_cstr(new char*[argv.size() + 1]); | 143 std::vector<char*> argv_cstr; |
| 144 for (size_t i = 0; i < argv.size(); i++) { | 144 argv_cstr.reserve(argv.size() + 1); |
| 145 argv_cstr[i] = const_cast<char*>(argv[i].c_str()); | 145 for (const auto& arg : argv) |
| 146 } | 146 argv_cstr.push_back(const_cast<char*>(arg.c_str())); |
| 147 argv_cstr[argv.size()] = nullptr; | 147 argv_cstr.push_back(nullptr); |
| 148 | 148 |
| 149 std::unique_ptr<char* []> owned_environ; | 149 std::unique_ptr<char* []> owned_environ; |
| 150 char** new_environ = options.clear_environ ? nullptr : *_NSGetEnviron(); | 150 char** new_environ = options.clear_environ ? nullptr : *_NSGetEnviron(); |
| 151 if (!options.environ.empty()) { | 151 if (!options.environ.empty()) { |
| 152 owned_environ = AlterEnvironment(new_environ, options.environ); | 152 owned_environ = AlterEnvironment(new_environ, options.environ); |
| 153 new_environ = owned_environ.get(); | 153 new_environ = owned_environ.get(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 const char* executable_path = !options.real_path.empty() | 156 const char* executable_path = !options.real_path.empty() |
| 157 ? options.real_path.value().c_str() | 157 ? options.real_path.value().c_str() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 // finish is the sort of thing ThreadRestrictions is trying to prevent. | 173 // finish is the sort of thing ThreadRestrictions is trying to prevent. |
| 174 base::ThreadRestrictions::AssertIOAllowed(); | 174 base::ThreadRestrictions::AssertIOAllowed(); |
| 175 pid_t ret = HANDLE_EINTR(waitpid(pid, nullptr, 0)); | 175 pid_t ret = HANDLE_EINTR(waitpid(pid, nullptr, 0)); |
| 176 DPCHECK(ret > 0); | 176 DPCHECK(ret > 0); |
| 177 } | 177 } |
| 178 | 178 |
| 179 return Process(pid); | 179 return Process(pid); |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace base | 182 } // namespace base |
| OLD | NEW |