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

Side by Side Diff: base/process/launch_mac.cc

Issue 2950153002: Improve process launch handle sharing API. (Closed)
Patch Set: Fix Created 3 years, 5 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 unified diff | Download patch
OLDNEW
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 "base/process/launch.h" 5 #include "base/process/launch.h"
6 6
7 #include <crt_externs.h> 7 #include <crt_externs.h>
8 #include <mach/mach.h> 8 #include <mach/mach.h>
9 #include <spawn.h> 9 #include <spawn.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 DPSXCHECK(posix_spawnattr_setpgroup(attr.get(), 0)); 105 DPSXCHECK(posix_spawnattr_setpgroup(attr.get(), 0));
106 } 106 }
107 DPSXCHECK(posix_spawnattr_setflags(attr.get(), flags)); 107 DPSXCHECK(posix_spawnattr_setflags(attr.get(), flags));
108 108
109 PosixSpawnFileActions file_actions; 109 PosixSpawnFileActions file_actions;
110 110
111 // Process file descriptors for the child. By default, LaunchProcess will 111 // Process file descriptors for the child. By default, LaunchProcess will
112 // open stdin to /dev/null and inherit stdout and stderr. 112 // open stdin to /dev/null and inherit stdout and stderr.
113 bool inherit_stdout = true, inherit_stderr = true; 113 bool inherit_stdout = true, inherit_stderr = true;
114 bool null_stdin = true; 114 bool null_stdin = true;
115 if (options.fds_to_remap) { 115 for (const auto& dup2_pair : options.fds_to_remap) {
116 for (const auto& dup2_pair : *options.fds_to_remap) { 116 if (dup2_pair.second == STDIN_FILENO) {
117 if (dup2_pair.second == STDIN_FILENO) { 117 null_stdin = false;
118 null_stdin = false; 118 } else if (dup2_pair.second == STDOUT_FILENO) {
119 } else if (dup2_pair.second == STDOUT_FILENO) { 119 inherit_stdout = false;
120 inherit_stdout = false; 120 } else if (dup2_pair.second == STDERR_FILENO) {
121 } else if (dup2_pair.second == STDERR_FILENO) { 121 inherit_stderr = false;
122 inherit_stderr = false; 122 }
123 }
124 123
125 if (dup2_pair.first == dup2_pair.second) { 124 if (dup2_pair.first == dup2_pair.second) {
126 file_actions.Inherit(dup2_pair.second); 125 file_actions.Inherit(dup2_pair.second);
127 } else { 126 } else {
128 file_actions.Dup2(dup2_pair.first, dup2_pair.second); 127 file_actions.Dup2(dup2_pair.first, dup2_pair.second);
129 }
130 } 128 }
131 } 129 }
132 130
133 if (null_stdin) { 131 if (null_stdin) {
134 file_actions.Open(STDIN_FILENO, "/dev/null", O_RDONLY); 132 file_actions.Open(STDIN_FILENO, "/dev/null", O_RDONLY);
135 } 133 }
136 if (inherit_stdout) { 134 if (inherit_stdout) {
137 file_actions.Inherit(STDOUT_FILENO); 135 file_actions.Inherit(STDOUT_FILENO);
138 } 136 }
139 if (inherit_stderr) { 137 if (inherit_stderr) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // finish is the sort of thing ThreadRestrictions is trying to prevent. 171 // finish is the sort of thing ThreadRestrictions is trying to prevent.
174 base::ThreadRestrictions::AssertIOAllowed(); 172 base::ThreadRestrictions::AssertIOAllowed();
175 pid_t ret = HANDLE_EINTR(waitpid(pid, nullptr, 0)); 173 pid_t ret = HANDLE_EINTR(waitpid(pid, nullptr, 0));
176 DPCHECK(ret > 0); 174 DPCHECK(ret > 0);
177 } 175 }
178 176
179 return Process(pid); 177 return Process(pid);
180 } 178 }
181 179
182 } // namespace base 180 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698