Skip to content

Commit 12d87c3

Browse files
committed
MDEV-7659 buildbot may leave stale mysqld
safe_process puts its children (mysqld, in this case) into a separate process group, to be able to kill it all at once. buildslave kills mtr's process group when it loses connection to the master. result? buildslave kills mtr and safe_process, but leaves stale mysqld processes in their own process groups. fix: put safe_process itself into a separate process group, then buildslave won't kill it and safe_process will kill mysqld'd and itself when it will notice that the parent mtr no longer exists.
1 parent 206b111 commit 12d87c3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

mysql-test/lib/My/SafeProcess/safe_process.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ extern "C" void handle_abort(int sig)
125125
message("Got signal %d, child_pid: %d, sending ABRT", sig, child_pid);
126126

127127
if (child_pid > 0) {
128-
kill (-child_pid, SIGABRT); // Don't wait for it to terminate
128+
kill(-child_pid, SIGABRT); // Don't wait for it to terminate
129129
}
130130
}
131131

@@ -226,6 +226,18 @@ int main(int argc, char* const argv[] )
226226
sleep(1);
227227
}
228228

229+
/*
230+
Child: Make this process it's own process group to be able to kill
231+
it and any its children that hasn't changed a group themselves)
232+
233+
Parent: Detach from the parent's process group, so that killing a parent
234+
group wouldn't kill us (if we're killed, there's no one to kill our child
235+
processes that run in their own process group). There's a loop below
236+
that monitors the parent, it's enough.
237+
*/
238+
setpgid(0, 0);
239+
240+
229241
if (child_pid == 0)
230242
{
231243
close(pfd[0]); // Close unused read end
@@ -236,10 +248,6 @@ int main(int argc, char* const argv[] )
236248
signal(SIGHUP, SIG_DFL);
237249
signal(SIGCHLD, SIG_DFL);
238250

239-
// Make this process it's own process group to be able to kill
240-
// it and any childs(that hasn't changed group themself)
241-
setpgid(0, 0);
242-
243251
if (nocore)
244252
{
245253
struct rlimit corelim = { 0, 0 };

0 commit comments

Comments
 (0)