1717#include "config.h"
1818#include "packfile.h"
1919#include "compat/nonblock.h"
20+ #include "cleanup.h"
2021
2122void child_process_init (struct child_process * child )
2223{
@@ -38,9 +39,15 @@ struct child_to_clean {
3839static struct child_to_clean * children_to_clean ;
3940static int installed_child_cleanup_handler ;
4041
41- static void cleanup_children (int sig , int in_signal )
42+ static void cleanup_children (int sig )
4243{
4344 struct child_to_clean * children_to_wait_for = NULL ;
45+ int in_signal = 0 ;
46+
47+ if (sig )
48+ in_signal = 1 ;
49+ else
50+ sig = SIGTERM ;
4451
4552 while (children_to_clean ) {
4653 struct child_to_clean * p = children_to_clean ;
@@ -80,18 +87,6 @@ static void cleanup_children(int sig, int in_signal)
8087 }
8188}
8289
83- static void cleanup_children_on_signal (int sig )
84- {
85- cleanup_children (sig , 1 );
86- sigchain_pop (sig );
87- raise (sig );
88- }
89-
90- static void cleanup_children_on_exit (void )
91- {
92- cleanup_children (SIGTERM , 0 );
93- }
94-
9590static void mark_child_for_cleanup (pid_t pid , struct child_process * process )
9691{
9792 struct child_to_clean * p = xmalloc (sizeof (* p ));
@@ -101,8 +96,7 @@ static void mark_child_for_cleanup(pid_t pid, struct child_process *process)
10196 children_to_clean = p ;
10297
10398 if (!installed_child_cleanup_handler ) {
104- atexit (cleanup_children_on_exit );
105- sigchain_push_common (cleanup_children_on_signal );
99+ cleanup_register (cleanup_children );
106100 installed_child_cleanup_handler = 1 ;
107101 }
108102}
0 commit comments