Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Unified Diff: base/process_util_linux.cc

Issue 100127: POSIX: Add code for shuffling file descriptors. (Closed)
Patch Set: ... Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util.h ('k') | base/process_util_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_linux.cc
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 686b04b5cf109cd29c3c5b0d4082af4b6f949799..f8e8a04765f1d8a5541c671362f6379aad00bd1b 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -31,30 +31,22 @@ namespace base {
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
bool wait, ProcessHandle* process_handle) {
- // Make sure we don't leak any FDs to the child process by marking all FDs
- // as close-on-exec.
- SetAllFDsToCloseOnExec();
-
pid_t pid = fork();
if (pid < 0)
return false;
if (pid == 0) {
- for (file_handle_mapping_vector::const_iterator it = fds_to_remap.begin();
- it != fds_to_remap.end();
- ++it) {
- int src_fd = it->first;
- int dest_fd = it->second;
- if (src_fd == dest_fd) {
- int flags = fcntl(src_fd, F_GETFD);
- if (flags != -1) {
- fcntl(src_fd, F_SETFD, flags & ~FD_CLOEXEC);
- }
- } else {
- dup2(src_fd, dest_fd);
- }
+ InjectiveMultimap fd_shuffle;
+ for (file_handle_mapping_vector::const_iterator
+ it = fds_to_remap.begin(); it != fds_to_remap.end(); ++it) {
+ fd_shuffle.push_back(InjectionArc(it->first, it->second, false));
}
+ if (!ShuffleFileDescriptors(fd_shuffle))
+ exit(127);
+
+ CloseSuperfluousFds(fd_shuffle);
+
scoped_array<char*> argv_cstr(new char*[argv.size() + 1]);
for (size_t i = 0; i < argv.size(); i++)
argv_cstr[i] = const_cast<char*>(argv[i].c_str());
« no previous file with comments | « base/process_util.h ('k') | base/process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698