@@ -123,11 +123,15 @@ swift::ExecuteWithPipe(llvm::StringRef program,
123
123
posix_spawn_file_actions_t FileActions;
124
124
posix_spawn_file_actions_init (&FileActions);
125
125
126
+ // Redirect file descriptors...
126
127
posix_spawn_file_actions_adddup2 (&FileActions, p1.read , STDIN_FILENO);
127
- posix_spawn_file_actions_addclose (&FileActions, p1.write );
128
-
129
128
posix_spawn_file_actions_adddup2 (&FileActions, p2.write , STDOUT_FILENO);
129
+
130
+ // Close all file descriptors, not needed as we duped them to the stdio.
131
+ posix_spawn_file_actions_addclose (&FileActions, p1.read );
132
+ posix_spawn_file_actions_addclose (&FileActions, p1.write );
130
133
posix_spawn_file_actions_addclose (&FileActions, p2.read );
134
+ posix_spawn_file_actions_addclose (&FileActions, p2.write );
131
135
132
136
// Spawn the subtask.
133
137
int error = posix_spawn (&pid, progCStr, &FileActions, nullptr ,
@@ -156,13 +160,16 @@ swift::ExecuteWithPipe(llvm::StringRef program,
156
160
157
161
// Child process.
158
162
case 0 :
159
- close (p1.write );
160
- close (p2.read );
161
-
162
163
// Redirect file descriptors...
163
164
dup2 (p1.read , STDIN_FILENO);
164
165
dup2 (p2.write , STDOUT_FILENO);
165
166
167
+ // Close all file descriptors, not needed as we duped them to the stdio.
168
+ close (p1.read );
169
+ close (p1.write );
170
+ close (p2.read );
171
+ close (p2.write );
172
+
166
173
// Execute the program.
167
174
if (envp) {
168
175
execve (progCStr, const_cast <char **>(argv), const_cast <char **>(envp));
@@ -180,11 +187,12 @@ swift::ExecuteWithPipe(llvm::StringRef program,
180
187
181
188
// Parent process.
182
189
default :
190
+ close (p1.read );
191
+ close (p2.write );
183
192
break ;
184
193
}
185
194
#endif
186
- close (p1.read );
187
- close (p2.write );
195
+
188
196
llvm::sys::ProcessInfo proc;
189
197
proc.Pid = pid;
190
198
proc.Process = pid;
0 commit comments