Skip to content

Commit 7c3ef54

Browse files
committed
Revert "[Macros] 'close' unnecessary file descriptors in plugin process"
This reverts commit 05948bc.
1 parent 066d393 commit 7c3ef54

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

lib/Basic/Program.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,11 @@ swift::ExecuteWithPipe(llvm::StringRef program,
123123
posix_spawn_file_actions_t FileActions;
124124
posix_spawn_file_actions_init(&FileActions);
125125

126-
// Redirect file descriptors...
127126
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);
132127
posix_spawn_file_actions_addclose(&FileActions, p1.write);
128+
129+
posix_spawn_file_actions_adddup2(&FileActions, p2.write, STDOUT_FILENO);
133130
posix_spawn_file_actions_addclose(&FileActions, p2.read);
134-
posix_spawn_file_actions_addclose(&FileActions, p2.write);
135131

136132
// Spawn the subtask.
137133
int error = posix_spawn(&pid, progCStr, &FileActions, nullptr,
@@ -160,16 +156,13 @@ swift::ExecuteWithPipe(llvm::StringRef program,
160156

161157
// Child process.
162158
case 0:
159+
close(p1.write);
160+
close(p2.read);
161+
163162
// Redirect file descriptors...
164163
dup2(p1.read, STDIN_FILENO);
165164
dup2(p2.write, STDOUT_FILENO);
166165

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-
173166
// Execute the program.
174167
if (envp) {
175168
execve(progCStr, const_cast<char **>(argv), const_cast<char **>(envp));
@@ -187,12 +180,11 @@ swift::ExecuteWithPipe(llvm::StringRef program,
187180

188181
// Parent process.
189182
default:
190-
close(p1.read);
191-
close(p2.write);
192183
break;
193184
}
194185
#endif
195-
186+
close(p1.read);
187+
close(p2.write);
196188
llvm::sys::ProcessInfo proc;
197189
proc.Pid = pid;
198190
proc.Process = pid;

0 commit comments

Comments
 (0)