MCPcopy Create free account
hub / github.com/git/git / cleanup_children

Function cleanup_children

run-command.c:41–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39static int installed_child_cleanup_handler;
40
41static void cleanup_children(int sig, int in_signal)
42{
43 struct child_to_clean *children_to_wait_for = NULL;
44
45 while (children_to_clean) {
46 struct child_to_clean *p = children_to_clean;
47 children_to_clean = p->next;
48
49 if (p->process && !in_signal) {
50 struct child_process *process = p->process;
51 if (process->clean_on_exit_handler) {
52 trace_printf(
53 "trace: run_command: running exit handler for pid %"
54 PRIuMAX, (uintmax_t)p->pid
55 );
56 process->clean_on_exit_handler(process);
57 }
58 }
59
60 kill(p->pid, sig);
61
62 if (p->process && p->process->wait_after_clean) {
63 p->next = children_to_wait_for;
64 children_to_wait_for = p;
65 } else {
66 if (!in_signal)
67 free(p);
68 }
69 }
70
71 while (children_to_wait_for) {
72 struct child_to_clean *p = children_to_wait_for;
73 children_to_wait_for = p->next;
74
75 while (waitpid(p->pid, NULL, 0) < 0 && errno == EINTR)
76 ; /* spin waiting for process exit or error */
77
78 if (!in_signal)
79 free(p);
80 }
81}
82
83static void cleanup_children_on_signal(int sig)
84{

Callers 2

cleanup_children_on_exitFunction · 0.85

Calls 1

waitpidFunction · 0.85

Tested by

no test coverage detected