| 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 "chromeos/process_proxy/process_proxy.h" | 5 #include "chromeos/process_proxy/process_proxy.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
| 10 | 10 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 if (pt_pair_[PT_SLAVE_FD] == -1) { | 198 if (pt_pair_[PT_SLAVE_FD] == -1) { |
| 199 CloseFdPair(pt_pair); | 199 CloseFdPair(pt_pair); |
| 200 return false; | 200 return false; |
| 201 } | 201 } |
| 202 | 202 |
| 203 return true; | 203 return true; |
| 204 } | 204 } |
| 205 | 205 |
| 206 int ProcessProxy::LaunchProcess(const std::string& command, int slave_fd) { | 206 int ProcessProxy::LaunchProcess(const std::string& command, int slave_fd) { |
| 207 base::LaunchOptions options; |
| 208 |
| 207 // Redirect crosh process' output and input so we can read it. | 209 // Redirect crosh process' output and input so we can read it. |
| 208 base::FileHandleMappingVector fds_mapping; | 210 options.fds_to_remap.push_back(std::make_pair(slave_fd, STDIN_FILENO)); |
| 209 fds_mapping.push_back(std::make_pair(slave_fd, STDIN_FILENO)); | 211 options.fds_to_remap.push_back(std::make_pair(slave_fd, STDOUT_FILENO)); |
| 210 fds_mapping.push_back(std::make_pair(slave_fd, STDOUT_FILENO)); | 212 options.fds_to_remap.push_back(std::make_pair(slave_fd, STDERR_FILENO)); |
| 211 fds_mapping.push_back(std::make_pair(slave_fd, STDERR_FILENO)); | |
| 212 base::LaunchOptions options; | |
| 213 // Do not set NO_NEW_PRIVS on processes if the system is in dev-mode. This | 213 // Do not set NO_NEW_PRIVS on processes if the system is in dev-mode. This |
| 214 // permits sudo in the crosh shell when in developer mode. | 214 // permits sudo in the crosh shell when in developer mode. |
| 215 options.allow_new_privs = base::CommandLine::ForCurrentProcess()-> | 215 options.allow_new_privs = base::CommandLine::ForCurrentProcess()-> |
| 216 HasSwitch(chromeos::switches::kSystemInDevMode); | 216 HasSwitch(chromeos::switches::kSystemInDevMode); |
| 217 options.fds_to_remap = &fds_mapping; | |
| 218 options.ctrl_terminal_fd = slave_fd; | 217 options.ctrl_terminal_fd = slave_fd; |
| 219 options.environ["TERM"] = "xterm"; | 218 options.environ["TERM"] = "xterm"; |
| 220 | 219 |
| 221 // Launch the process. | 220 // Launch the process. |
| 222 process_.reset(new base::Process(base::LaunchProcess( | 221 process_.reset(new base::Process(base::LaunchProcess( |
| 223 base::CommandLine(base::FilePath(command)), options))); | 222 base::CommandLine(base::FilePath(command)), options))); |
| 224 | 223 |
| 225 // TODO(rvargas) crbug/417532: This is somewhat wrong but the interface of | 224 // TODO(rvargas) crbug/417532: This is somewhat wrong but the interface of |
| 226 // Open vends pid_t* so ownership is quite vague anyway, and Process::Close | 225 // Open vends pid_t* so ownership is quite vague anyway, and Process::Close |
| 227 // doesn't do much in POSIX. | 226 // doesn't do much in POSIX. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 240 } | 239 } |
| 241 *fd = kInvalidFd; | 240 *fd = kInvalidFd; |
| 242 } | 241 } |
| 243 | 242 |
| 244 void ProcessProxy::ClearFdPair(int* pipe) { | 243 void ProcessProxy::ClearFdPair(int* pipe) { |
| 245 pipe[PT_MASTER_FD] = kInvalidFd; | 244 pipe[PT_MASTER_FD] = kInvalidFd; |
| 246 pipe[PT_SLAVE_FD] = kInvalidFd; | 245 pipe[PT_SLAVE_FD] = kInvalidFd; |
| 247 } | 246 } |
| 248 | 247 |
| 249 } // namespace chromeos | 248 } // namespace chromeos |
| OLD | NEW |