Skip to content

Commit 5c06176

Browse files
authored
Merge pull request #81535 from rintaro/6.2-macros-wait-rdar150474701
[6.2][Macros] Mitigate plugin process 'wait' failure
2 parents 8299d7b + 2416b58 commit 5c06176

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/AST/PluginRegistry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ LoadedExecutablePlugin::PluginProcess::~PluginProcess() {
213213
#else
214214
close(input);
215215
close(output);
216+
kill(process.Pid, SIGTERM);
216217
#endif
217218

218219
// Set `SecondsToWait` non-zero so it waits for the timeout and kill it after

lib/Basic/Program.cpp

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

126+
// Redirect file descriptors...
126127
posix_spawn_file_actions_adddup2(&FileActions, p1.read, STDIN_FILENO);
127-
posix_spawn_file_actions_addclose(&FileActions, p1.write);
128-
129128
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);
130133
posix_spawn_file_actions_addclose(&FileActions, p2.read);
134+
posix_spawn_file_actions_addclose(&FileActions, p2.write);
131135

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

157161
// Child process.
158162
case 0:
159-
close(p1.write);
160-
close(p2.read);
161-
162163
// Redirect file descriptors...
163164
dup2(p1.read, STDIN_FILENO);
164165
dup2(p2.write, STDOUT_FILENO);
165166

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

181188
// Parent process.
182189
default:
190+
close(p1.read);
191+
close(p2.write);
183192
break;
184193
}
185194
#endif
186-
close(p1.read);
187-
close(p2.write);
195+
188196
llvm::sys::ProcessInfo proc;
189197
proc.Pid = pid;
190198
proc.Process = pid;

0 commit comments

Comments
 (0)