File tree 3 files changed +31
-10
lines changed
3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -181,17 +181,23 @@ int run(
181
181
}
182
182
else /* fork() returns new pid to the parent process */
183
183
{
184
+ // must do before resuming signals to avoid race
185
+ register_child (childpid);
186
+
184
187
// resume signals
185
188
sigprocmask (SIG_SETMASK, &old_mask, nullptr );
186
189
187
190
int status; /* parent process: child's exit status */
188
191
189
192
/* wait for child to exit, and store its status */
190
193
while (waitpid (childpid, &status, 0 )==-1 )
194
+ {
191
195
if (errno==EINTR)
192
196
continue ; // try again
193
197
else
194
198
{
199
+ unregister_child ();
200
+
195
201
perror (" Waiting for child process failed" );
196
202
if (stdin_fd!=STDIN_FILENO)
197
203
close (stdin_fd);
@@ -201,6 +207,9 @@ int run(
201
207
close (stderr_fd);
202
208
return 1 ;
203
209
}
210
+ }
211
+
212
+ unregister_child ();
204
213
205
214
if (stdin_fd!=STDIN_FILENO)
206
215
close (stdin_fd);
Original file line number Diff line number Diff line change 11
11
#include " signal_catcher.h"
12
12
13
13
#if defined(_WIN32)
14
- #include < process.h>
15
14
#else
16
15
#include < cstdlib>
17
- #include < csignal>
18
16
#endif
19
17
20
- #include < vector>
21
-
22
18
// Here we have an instance of an ugly global object.
23
19
// 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'.
25
21
26
22
#ifdef _WIN32
27
23
#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
+ }
29
35
#endif
30
36
31
37
void install_signal_catcher ()
@@ -66,13 +72,13 @@ void signal_catcher(int sig)
66
72
#if defined(_WIN32)
67
73
#else
68
74
69
- #if 1
75
+ #if 0
70
76
// kill any children by killing group
71
77
killpg(0, sig);
72
78
#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);
76
82
#endif
77
83
78
84
exit (sig); // should contemplate something from sysexits.h
Original file line number Diff line number Diff line change @@ -14,4 +14,10 @@ void install_signal_catcher();
14
14
void remove_signal_catcher ();
15
15
void signal_catcher (int sig );
16
16
17
+ #ifndef _WIN32
18
+ #include <csignal>
19
+ void register_child (pid_t );
20
+ void unregister_child ();
21
+ #endif
22
+
17
23
#endif // CPROVER_UTIL_SIGNAL_CATCHER_H
You can’t perform that action at this time.
0 commit comments