signal handler updated

This commit is contained in:
Sukchan Lee 2017-02-26 13:09:40 +09:00
parent 7005969056
commit f7d116ef40
7 changed files with 96 additions and 48 deletions

View File

@ -25,13 +25,17 @@ AC_CONFIG_SRCDIR([main.c])
AC_CANONICAL_HOST
case $host in
*linux*)
OSDIR="unix"
OSCFLAGS="-DLINUX=1"
;;
*)
OSDIR="unix"
;;
*linux*)
OSDIR="unix"
OSCPPFLAGS="-DLINUX=1"
;;
*-apple-darwin*)
OSDIR="unix"
OSPPCFLAGS="-DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK"
;;
*)
OSDIR="unix"
;;
esac
AC_SUBST(OSCFLAGS)
AC_SUBST(OSDIR)

View File

@ -18,7 +18,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/lib/core/include
AM_CFLAGS = \
-Wall -Werror @OSCFLAGS@
-Wall -Werror @OSCPPFLAGS@
MAINTAINERCLEANFILES = Makefile.in
MOSTLYCLEANFILES = core *.stackdump

View File

@ -1,6 +1,17 @@
#include "core.h"
#include "core_signal.h"
#if defined(__NetBSD__) || defined(DARWIN)
static void avoid_zombies(int signo)
{
int exit_status;
while (waitpid(-1, &exit_status, WNOHANG) > 0) {
/* do nothing */
}
}
#endif /* DARWIN */
/*
* Replace standard signal() with the more reliable sigaction equivalent
* from W. Richard Stevens' "Advanced Programming in the UNIX Environment"
@ -183,7 +194,7 @@ status_t signal_init(void)
* No thread should ever block synchronous signals.
* See the Solaris man page for pthread_sigmask() for
* some information. Solaris chooses to knock out such
* processes when a blocked synchronous signal is
* processes when a blocked synchronous signal is
* delivered, skipping any registered signal handler.
* AIX doesn't call a signal handler either. At least
* one level of linux+glibc does call the handler even
@ -192,16 +203,23 @@ status_t signal_init(void)
sigfillset(&sig_mask);
remove_sync_sigs(&sig_mask);
if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0)
{
#if defined(SIGPROCMASK_SETS_THREAD_MASK) || ! APR_HAS_THREADS
if ((rv = sigprocmask(SIG_SETMASK, &sig_mask, NULL)) != 0) {
rv = errno;
}
#else
if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) {
#ifdef HAVE_ZOS_PTHREADS
rv = errno;
#endif
}
#endif
return rv;
}
status_t signal_block(int signum)
{
#if HAVE_SIGACTION
#if APR_HAVE_SIGACTION
sigset_t sig_mask;
int rv;
@ -209,19 +227,26 @@ status_t signal_block(int signum)
sigaddset(&sig_mask, signum);
if ((rv = pthread_sigmask(SIG_BLOCK, &sig_mask, NULL)) != 0)
{
#if defined(SIGPROCMASK_SETS_THREAD_MASK)
if ((rv = sigprocmask(SIG_BLOCK, &sig_mask, NULL)) != 0) {
rv = errno;
}
#else
if ((rv = pthread_sigmask(SIG_BLOCK, &sig_mask, NULL)) != 0) {
#ifdef HAVE_ZOS_PTHREADS
rv = errno;
#endif
}
#endif
return rv;
#else
return ENOTIMPL;
return CORE_ENOTIMPL;
#endif
}
status_t signal_unblock(int signum)
{
#if HAVE_SIGACTION
#if APR_HAVE_SIGACTION
sigset_t sig_mask;
int rv;
@ -229,11 +254,19 @@ status_t signal_unblock(int signum)
sigaddset(&sig_mask, signum);
if ((rv = pthread_sigmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) {
#if defined(SIGPROCMASK_SETS_THREAD_MASK)
if ((rv = sigprocmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) {
rv = errno;
}
#else
if ((rv = pthread_sigmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) {
#ifdef HAVE_ZOS_PTHREADS
rv = errno;
#endif
}
#endif
return rv;
#else
return ENOTIMPL;
return CORE_ENOTIMPL;
#endif
}

View File

@ -17,7 +17,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/lib/core/include
AM_CFLAGS = \
-Wall -Werror @OSCFLAGS@ \
-Wall -Werror @OSCPPFLAGS@ \
-Wno-unused-function
TESTS = testcore

40
main.c
View File

@ -101,6 +101,22 @@ void logger_signal(int signum)
}
}
void test_signal(int signum)
{
fprintf(stderr, "asdfsadfsadfsdafasdfsadf = %d\n", signum);
switch (signum)
{
case SIGTERM:
case SIGINT:
s6a_thread_stop();
break;
case SIGHUP:
break;
default:
break;
}
}
int main(int argc, char *argv[])
{
int opt;
@ -175,7 +191,6 @@ int main(int argc, char *argv[])
if (pid == 0)
{
/* Child */
setsid();
umask(027);
core_signal(SIGINT, logger_signal);
@ -189,6 +204,29 @@ int main(int argc, char *argv[])
/* Parent */
}
{
pid_t pid;
pid = fork();
d_assert(pid != -1, return EXIT_FAILURE, "fork() failed");
if (pid == 0)
{
/* Child */
umask(027);
core_signal(SIGINT, test_signal);
core_signal(SIGTERM, test_signal);
core_signal(SIGHUP, test_signal);
s6a_thread_start(1);
fd_core_wait_shutdown_complete();
return EXIT_SUCCESS;
}
/* Parent */
}
{
extern int _mme_sm;
extern int _enb_s1_sm;

View File

@ -110,37 +110,10 @@ void threads_start()
rv = thread_create(&mme_net_thread, NULL, mme_net_main, NULL);
d_assert(rv == CORE_OK, return,
"MME Network socket recv thread creation failed");
{
status_t rv;
pid_t pid;
pid = fork();
d_assert(pid != -1, return, "fork() failed");
if (pid == 0)
{
/* Child */
setsid();
umask(027);
rv = s6a_thread_start(1);
d_assert(rv == CORE_OK, return,
"HSS thread creation failed");
return;
}
/* Parent */
rv = s6a_thread_start(0);
d_assert(rv == CORE_OK, return,
"HSS thread creation failed");
}
}
void threads_stop()
{
s6a_thread_stop();
thread_delete(mme_net_thread);
thread_delete(mme_sm_thread);
}

View File

@ -21,7 +21,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src
AM_CFLAGS = \
-Wall -Werror @OSCFLAGS@ \
-Wall -Werror \
-Wno-unused-function -Wno-unused-variable
TESTS = testcellwire