summaryrefslogtreecommitdiff
path: root/mysql-test/lib/My/SafeProcess
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2018-05-03 16:14:54 +0100
committerVladislav Vaintroub <wlad@mariadb.com>2018-05-03 16:14:54 +0100
commit1cb7c4bfc05b85f4384f4a719568d29b83abf1da (patch)
tree54e1a280d817af3a374b6eaee20799f1672778e9 /mysql-test/lib/My/SafeProcess
parenta411910dd677f161b301c095f36373f4f5da5555 (diff)
downloadmariadb-git-1cb7c4bfc05b85f4384f4a719568d29b83abf1da.tar.gz
MDEV-16084 Calling exit() from a signal handler is unsafe.
Call _exit() from signal handler. main() can just do return.
Diffstat (limited to 'mysql-test/lib/My/SafeProcess')
-rw-r--r--mysql-test/lib/My/SafeProcess/safe_process.cc14
1 files changed, 6 insertions, 8 deletions
diff --git a/mysql-test/lib/My/SafeProcess/safe_process.cc b/mysql-test/lib/My/SafeProcess/safe_process.cc
index feb3eb4df66..5f6544414e2 100644
--- a/mysql-test/lib/My/SafeProcess/safe_process.cc
+++ b/mysql-test/lib/My/SafeProcess/safe_process.cc
@@ -89,7 +89,7 @@ static void die(const char* fmt, ...)
}
-static void kill_child(bool was_killed)
+static int kill_child(bool was_killed)
{
int status= 0;
@@ -108,15 +108,15 @@ static void kill_child(bool was_killed)
exit_code= WEXITSTATUS(status);
message("Child exit: %d", exit_code);
// Exit with exit status of the child
- exit(exit_code);
+ return exit_code;
}
if (WIFSIGNALED(status))
message("Child killed by signal: %d", WTERMSIG(status));
- exit(exit_code);
+ return exit_code;
}
- exit(5);
+ return 5;
}
@@ -136,7 +136,7 @@ extern "C" void handle_signal(int sig)
terminated= 1;
if (child_pid > 0)
- kill_child(sig == SIGCHLD);
+ _exit(kill_child(sig == SIGCHLD));
// Ignore further signals
signal(SIGTERM, SIG_IGN);
@@ -292,8 +292,6 @@ int main(int argc, char* const argv[] )
/* Wait for parent or child to die */
sleep(1);
}
- kill_child(0);
-
- return 4;
+ return kill_child(0);
}