File tree 3 files changed +29
-6
lines changed
3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -181,6 +181,9 @@ 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
@@ -192,6 +195,8 @@ int run(
192
195
continue ; // try again
193
196
else
194
197
{
198
+ unregister_child ();
199
+
195
200
perror (" Waiting for child process failed" );
196
201
if (stdin_fd!=STDIN_FILENO)
197
202
close (stdin_fd);
@@ -202,6 +207,8 @@ int run(
202
207
return 1 ;
203
208
}
204
209
210
+ unregister_child ();
211
+
205
212
if (stdin_fd!=STDIN_FILENO)
206
213
close (stdin_fd);
207
214
if (stdout_fd!=STDOUT_FILENO)
Original file line number Diff line number Diff line change 21
21
22
22
// Here we have an instance of an ugly global object.
23
23
// 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'.
25
25
26
26
#ifdef _WIN32
27
27
#else
28
- std::vector< pid_t > pids_of_children ;
28
+ pid_t child_pid = 0 ;
29
29
#endif
30
30
31
+ void register_child (pid_t pid)
32
+ {
33
+ child_pid = pid;
34
+ }
35
+
36
+ void unregister_child ()
37
+ {
38
+ child_pid = 0 ;
39
+ }
40
+
31
41
void install_signal_catcher ()
32
42
{
33
43
#if defined(_WIN32)
@@ -66,13 +76,13 @@ void signal_catcher(int sig)
66
76
#if defined(_WIN32)
67
77
#else
68
78
69
- #if 1
79
+ #if 0
70
80
// kill any children by killing group
71
81
killpg(0, sig);
72
82
#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);
76
86
#endif
77
87
78
88
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