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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 int write_pipe_fds[2] = {0}; | 69 int write_pipe_fds[2] = {0}; |
70 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { | 70 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { |
71 LOG(ERROR) << "Bad write pipe"; | 71 LOG(ERROR) << "Bad write pipe"; |
72 return false; | 72 return false; |
73 } | 73 } |
74 base::ScopedFD write_pipe_read_fd(write_pipe_fds[0]); | 74 base::ScopedFD write_pipe_read_fd(write_pipe_fds[0]); |
75 base::ScopedFD write_pipe_write_fd(write_pipe_fds[1]); | 75 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)); | 76 fd_map.push_back(std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); |
77 | 77 |
78 base::LaunchOptions options; | 78 base::LaunchOptions options; |
| 79 options.current_directory = command_line.GetProgram().DirName(); |
79 options.fds_to_remap = &fd_map; | 80 options.fds_to_remap = &fd_map; |
80 | 81 |
81 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 82 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
82 // 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. |
83 options.allow_new_privs = true; | 84 options.allow_new_privs = true; |
84 #endif | 85 #endif |
85 | 86 |
86 base::Process local_process = base::LaunchProcess(command_line, options); | 87 base::Process local_process = base::LaunchProcess(command_line, options); |
87 if (!local_process.IsValid()) { | 88 if (!local_process.IsValid()) { |
88 LOG(ERROR) << "Error launching process"; | 89 LOG(ERROR) << "Error launching process"; |
89 return false; | 90 return false; |
90 } | 91 } |
91 | 92 |
92 // 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. |
93 write_pipe_read_fd.reset(); | 94 write_pipe_read_fd.reset(); |
94 read_pipe_write_fd.reset(); | 95 read_pipe_write_fd.reset(); |
95 | 96 |
96 *process = std::move(local_process); | 97 *process = std::move(local_process); |
97 *read_file = base::File(read_pipe_read_fd.release()); | 98 *read_file = base::File(read_pipe_read_fd.release()); |
98 *write_file = base::File(write_pipe_write_fd.release()); | 99 *write_file = base::File(write_pipe_write_fd.release()); |
99 | 100 |
100 return true; | 101 return true; |
101 } | 102 } |
102 | 103 |
103 } // namespace extensions | 104 } // namespace extensions |
OLD | NEW |