Merge branch 'sigchld_handler' into develop
This commit is contained in:
@ -84,6 +84,7 @@
|
|||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
|
||||||
#include <ini.h>
|
#include <ini.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
/** for procname */
|
/** for procname */
|
||||||
#if !defined(_GNU_SOURCE)
|
#if !defined(_GNU_SOURCE)
|
||||||
@ -333,6 +334,41 @@ sigint_handler (int i)
|
|||||||
fprintf(stderr, "\n\nShutting down MaxScale\n\n");
|
fprintf(stderr, "\n\nShutting down MaxScale\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sigchld_handler (int i)
|
||||||
|
{
|
||||||
|
int exit_status = 0;
|
||||||
|
pid_t child = -1;
|
||||||
|
|
||||||
|
if((child = wait(&exit_status)) == -1)
|
||||||
|
{
|
||||||
|
char errbuf[512];
|
||||||
|
strerror_r(errno,errbuf,511);
|
||||||
|
errbuf[511] = '\0';
|
||||||
|
skygw_log_write_flush(LE,"Error: failed to wait child process: %d %s",errno,errbuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(WIFEXITED(exit_status))
|
||||||
|
{
|
||||||
|
skygw_log_write_flush(WEXITSTATUS(exit_status) != 0 ? LE : LT,
|
||||||
|
"Child process %d exited with status %d",
|
||||||
|
child,WEXITSTATUS(exit_status));
|
||||||
|
}
|
||||||
|
else if(WIFSIGNALED(exit_status))
|
||||||
|
{
|
||||||
|
skygw_log_write_flush((LE|LT),
|
||||||
|
"Child process %d was stopped by signal %d.",
|
||||||
|
child,WTERMSIG(exit_status));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
skygw_log_write_flush((LE|LT),
|
||||||
|
"Child process %d did not exit normally. Exit status: %d",
|
||||||
|
child,exit_status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int fatal_handling = 0;
|
int fatal_handling = 0;
|
||||||
|
|
||||||
@ -1433,6 +1469,14 @@ int main(int argc, char **argv)
|
|||||||
"SIGFPE. Exiting.");
|
"SIGFPE. Exiting.");
|
||||||
goto sigset_err;
|
goto sigset_err;
|
||||||
}
|
}
|
||||||
|
l = signal_set(SIGCHLD, sigchld_handler);
|
||||||
|
|
||||||
|
if (l != 0)
|
||||||
|
{
|
||||||
|
logerr = strdup("Failed to set signal handler for "
|
||||||
|
"SIGCHLD. Exiting.");
|
||||||
|
goto sigset_err;
|
||||||
|
}
|
||||||
#ifdef SIGBUS
|
#ifdef SIGBUS
|
||||||
l = signal_set(SIGBUS, sigfatal_handler);
|
l = signal_set(SIGBUS, sigfatal_handler);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user