Skip to content

Commit c93180a

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

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/util/run.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,23 @@ 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

187190
int status; /* parent process: child's exit status */
188191

189192
/* wait for child to exit, and store its status */
190193
while(waitpid(childpid, &status, 0)==-1)
194+
{
191195
if(errno==EINTR)
192196
continue; // try again
193197
else
194198
{
199+
unregister_child();
200+
195201
perror("Waiting for child process failed");
196202
if(stdin_fd!=STDIN_FILENO)
197203
close(stdin_fd);
@@ -201,6 +207,9 @@ int run(
201207
close(stderr_fd);
202208
return 1;
203209
}
210+
}
211+
212+
unregister_child();
204213

205214
if(stdin_fd!=STDIN_FILENO)
206215
close(stdin_fd);

src/util/signal_catcher.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ Author: Daniel Kroening, [email protected]
1111
#include "signal_catcher.h"
1212

1313
#if defined(_WIN32)
14-
#include <process.h>
1514
#else
1615
#include <cstdlib>
17-
#include <csignal>
1816
#endif
1917

20-
#include <vector>
21-
2218
// Here we have an instance of an ugly global object.
2319
// It keeps track of any child processes that we'll kill
24-
// when we are told to terminate.
20+
// when we are told to terminate. "No child" is indicated by '0'.
2521

2622
#ifdef _WIN32
2723
#else
28-
std::vector<pid_t> pids_of_children;
24+
pid_t child_pid = 0;
25+
26+
void register_child(pid_t pid)
27+
{
28+
child_pid = pid;
29+
}
30+
31+
void unregister_child()
32+
{
33+
child_pid = 0;
34+
}
2935
#endif
3036

3137
void install_signal_catcher()
@@ -66,13 +72,13 @@ void signal_catcher(int sig)
6672
#if defined(_WIN32)
6773
#else
6874

69-
#if 1
75+
#if 0
7076
// kill any children by killing group
7177
killpg(0, sig);
7278
#else
73-
// pass on to any children
74-
for(const auto &pid : pids_of_children)
75-
kill(pid, sig);
79+
// pass on to our child, if any
80+
if(child_pid != 0)
81+
kill(child_pid, sig);
7682
#endif
7783

7884
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)