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