Skip to content

Commit 6965b72

Browse files
author
Daniel Kroening
committed
only selectively kill child, not entire process group
1 parent 2542d0d commit 6965b72

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/util/run.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ int run(
181181
}
182182
else /* fork() returns new pid to the parent process */
183183
{
184+
// must do before resuming signals to avoid race
185+
register_child(childpid);
186+
184187
// resume signals
185188
sigprocmask(SIG_SETMASK, &old_mask, nullptr);
186189

@@ -192,6 +195,8 @@ int run(
192195
continue; // try again
193196
else
194197
{
198+
unregister_child();
199+
195200
perror("Waiting for child process failed");
196201
if(stdin_fd!=STDIN_FILENO)
197202
close(stdin_fd);
@@ -202,6 +207,8 @@ int run(
202207
return 1;
203208
}
204209

210+
unregister_child();
211+
205212
if(stdin_fd!=STDIN_FILENO)
206213
close(stdin_fd);
207214
if(stdout_fd!=STDOUT_FILENO)

src/util/signal_catcher.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@ Author: Daniel Kroening, [email protected]
2121

2222
// Here we have an instance of an ugly global object.
2323
// It keeps track of any child processes that we'll kill
24-
// when we are told to terminate.
24+
// when we are told to terminate. "No child" is indicated by '0'.
2525

2626
#ifdef _WIN32
2727
#else
28-
std::vector<pid_t> pids_of_children;
28+
pid_t child_pid = 0;
29+
30+
void register_child(pid_t pid)
31+
{
32+
child_pid = pid;
33+
}
34+
35+
void unregister_child()
36+
{
37+
child_pid = 0;
38+
}
2939
#endif
3040

3141
void install_signal_catcher()
@@ -66,13 +76,13 @@ void signal_catcher(int sig)
6676
#if defined(_WIN32)
6777
#else
6878

69-
#if 1
79+
#if 0
7080
// kill any children by killing group
7181
killpg(0, sig);
7282
#else
73-
// pass on to any children
74-
for(const auto &pid : pids_of_children)
75-
kill(pid, sig);
83+
// pass on to our child, if any
84+
if(child_pid != 0)
85+
kill(child_pid, sig);
7686
#endif
7787

7888
exit(sig); // should contemplate something from sysexits.h

src/util/signal_catcher.h

+6
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ void install_signal_catcher();
1414
void remove_signal_catcher();
1515
void signal_catcher(int sig);
1616

17+
#ifndef _WIN32
18+
#include <csignal>
19+
void register_child(pid_t);
20+
void unregister_child();
21+
#endif
22+
1723
#endif // CPROVER_UTIL_SIGNAL_CATCHER_H

0 commit comments

Comments
 (0)