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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 if (result.empty()) | 44 if (result.empty()) |
45 *error_message = "Can't find native messaging host " + host_name; | 45 *error_message = "Can't find native messaging host " + host_name; |
46 | 46 |
47 return result; | 47 return result; |
48 } | 48 } |
49 | 49 |
50 // static | 50 // static |
51 bool NativeProcessLauncher::LaunchNativeProcess( | 51 bool NativeProcessLauncher::LaunchNativeProcess( |
52 const CommandLine& command_line, | 52 const CommandLine& command_line, |
53 base::Process* process, | 53 base::ProcessHandle* process_handle, |
54 base::File* read_file, | 54 base::File* read_file, |
55 base::File* write_file) { | 55 base::File* write_file) { |
56 base::FileHandleMappingVector fd_map; | 56 base::FileHandleMappingVector fd_map; |
57 | 57 |
58 int read_pipe_fds[2] = {0}; | 58 int read_pipe_fds[2] = {0}; |
59 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { | 59 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { |
60 LOG(ERROR) << "Bad read pipe"; | 60 LOG(ERROR) << "Bad read pipe"; |
61 return false; | 61 return false; |
62 } | 62 } |
63 base::ScopedFD read_pipe_read_fd(read_pipe_fds[0]); | 63 base::ScopedFD read_pipe_read_fd(read_pipe_fds[0]); |
(...skipping 10 matching lines...) Expand all Loading... |
74 fd_map.push_back(std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); | 74 fd_map.push_back(std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); |
75 | 75 |
76 base::LaunchOptions options; | 76 base::LaunchOptions options; |
77 options.fds_to_remap = &fd_map; | 77 options.fds_to_remap = &fd_map; |
78 | 78 |
79 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 79 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
80 // Don't use no_new_privs mode, e.g. in case the host needs to use sudo. | 80 // Don't use no_new_privs mode, e.g. in case the host needs to use sudo. |
81 options.allow_new_privs = true; | 81 options.allow_new_privs = true; |
82 #endif | 82 #endif |
83 | 83 |
84 base::ProcessHandle process_handle; | 84 if (!base::LaunchProcess(command_line, options, process_handle)) { |
85 if (!base::LaunchProcess(command_line, options, &process_handle)) { | |
86 LOG(ERROR) << "Error launching process"; | 85 LOG(ERROR) << "Error launching process"; |
87 return false; | 86 return false; |
88 } | 87 } |
89 | 88 |
90 // We will not be reading from the write pipe, nor writing from the read pipe. | 89 // We will not be reading from the write pipe, nor writing from the read pipe. |
91 write_pipe_read_fd.reset(); | 90 write_pipe_read_fd.reset(); |
92 read_pipe_write_fd.reset(); | 91 read_pipe_write_fd.reset(); |
93 | 92 |
94 *process = base::Process(process_handle); | |
95 *read_file = base::File(read_pipe_read_fd.release()); | 93 *read_file = base::File(read_pipe_read_fd.release()); |
96 *write_file = base::File(write_pipe_write_fd.release()); | 94 *write_file = base::File(write_pipe_write_fd.release()); |
97 | 95 |
98 return true; | 96 return true; |
99 } | 97 } |
100 | 98 |
101 } // namespace extensions | 99 } // namespace extensions |
OLD | NEW |