| 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 "chrome/browser/extensions/api/messaging/native_process_launcher.h" | 5 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 return result; | 49 return result; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 bool NativeProcessLauncher::LaunchNativeProcess( | 53 bool NativeProcessLauncher::LaunchNativeProcess( |
| 54 const base::CommandLine& command_line, | 54 const base::CommandLine& command_line, |
| 55 base::Process* process, | 55 base::Process* process, |
| 56 base::File* read_file, | 56 base::File* read_file, |
| 57 base::File* write_file) { | 57 base::File* write_file) { |
| 58 base::FileHandleMappingVector fd_map; | 58 base::LaunchOptions options; |
| 59 | 59 |
| 60 int read_pipe_fds[2] = {0}; | 60 int read_pipe_fds[2] = {0}; |
| 61 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { | 61 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { |
| 62 LOG(ERROR) << "Bad read pipe"; | 62 LOG(ERROR) << "Bad read pipe"; |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| 65 base::ScopedFD read_pipe_read_fd(read_pipe_fds[0]); | 65 base::ScopedFD read_pipe_read_fd(read_pipe_fds[0]); |
| 66 base::ScopedFD read_pipe_write_fd(read_pipe_fds[1]); | 66 base::ScopedFD read_pipe_write_fd(read_pipe_fds[1]); |
| 67 fd_map.push_back(std::make_pair(read_pipe_write_fd.get(), STDOUT_FILENO)); | 67 options.fds_to_remap.push_back( |
| 68 std::make_pair(read_pipe_write_fd.get(), STDOUT_FILENO)); |
| 68 | 69 |
| 69 int write_pipe_fds[2] = {0}; | 70 int write_pipe_fds[2] = {0}; |
| 70 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { | 71 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { |
| 71 LOG(ERROR) << "Bad write pipe"; | 72 LOG(ERROR) << "Bad write pipe"; |
| 72 return false; | 73 return false; |
| 73 } | 74 } |
| 74 base::ScopedFD write_pipe_read_fd(write_pipe_fds[0]); | 75 base::ScopedFD write_pipe_read_fd(write_pipe_fds[0]); |
| 75 base::ScopedFD write_pipe_write_fd(write_pipe_fds[1]); | 76 base::ScopedFD write_pipe_write_fd(write_pipe_fds[1]); |
| 76 fd_map.push_back(std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); | 77 options.fds_to_remap.push_back( |
| 78 std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); |
| 77 | 79 |
| 78 base::LaunchOptions options; | |
| 79 options.current_directory = command_line.GetProgram().DirName(); | 80 options.current_directory = command_line.GetProgram().DirName(); |
| 80 options.fds_to_remap = &fd_map; | |
| 81 | 81 |
| 82 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 82 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 83 // Don't use no_new_privs mode, e.g. in case the host needs to use sudo. | 83 // Don't use no_new_privs mode, e.g. in case the host needs to use sudo. |
| 84 options.allow_new_privs = true; | 84 options.allow_new_privs = true; |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 base::Process local_process = base::LaunchProcess(command_line, options); | 87 base::Process local_process = base::LaunchProcess(command_line, options); |
| 88 if (!local_process.IsValid()) { | 88 if (!local_process.IsValid()) { |
| 89 LOG(ERROR) << "Error launching process"; | 89 LOG(ERROR) << "Error launching process"; |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 | 92 |
| 93 // We will not be reading from the write pipe, nor writing from the read pipe. | 93 // We will not be reading from the write pipe, nor writing from the read pipe. |
| 94 write_pipe_read_fd.reset(); | 94 write_pipe_read_fd.reset(); |
| 95 read_pipe_write_fd.reset(); | 95 read_pipe_write_fd.reset(); |
| 96 | 96 |
| 97 *process = std::move(local_process); | 97 *process = std::move(local_process); |
| 98 *read_file = base::File(read_pipe_read_fd.release()); | 98 *read_file = base::File(read_pipe_read_fd.release()); |
| 99 *write_file = base::File(write_pipe_write_fd.release()); | 99 *write_file = base::File(write_pipe_write_fd.release()); |
| 100 | 100 |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace extensions | 104 } // namespace extensions |
| OLD | NEW |