From 74361f472d6d1a75a313cb3a6b4528cfeacfff0a Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 6 Apr 2009 17:53:46 +0200 Subject: [PATCH] Introduce para_sigaction(). This wrapper for sigaction() is public and may be used to setup a handler different from the generic handler that gets installed for the signal by para_install_sighandler(). --- signal.c | 27 ++++++++++++++++++++++----- signal.h | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/signal.c b/signal.c index 9a1dcfb0..84f73fc8 100644 --- a/signal.c +++ b/signal.c @@ -117,20 +117,22 @@ void para_reap_children(void) } /** - * Install the generic signal handler for the given signal number. + * Install the given handler for the given signal. * * \param sig The number of the signal to catch. + * \param handler to be installed, \p SIG_IGN, or \p SIG_DFL. * - * \return This function returns 1 on success and \p -E_SIGNAL_SIG_ERR on errors. + * \return This function returns 1 on success and \p -E_SIGNAL_SIG_ERR on + * errors. * - * \sa signal(2), sigaction(2). + * \sa sigaction(2). */ -int para_install_sighandler(int sig) +int para_sigaction(int sig, void (*handler)(int)) { struct sigaction act; PARA_DEBUG_LOG("catching signal %d\n", sig); - act.sa_handler = &generic_signal_handler; + act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; if (sig == SIGALRM) { @@ -147,6 +149,21 @@ int para_install_sighandler(int sig) return 1; } +/** + * Install the generic signal handler for the given signal number. + * + * \param sig The number of the signal to catch. + * + * \return This function returns 1 on success and \p -E_SIGNAL_SIG_ERR on + * errors. + * + * \sa signal(2), sigaction(2). + */ +int para_install_sighandler(int sig) +{ + return para_sigaction(sig, &generic_signal_handler); +} + /** * Return the number of next pending signal. * diff --git a/signal.h b/signal.h index 962e074a..610c4d89 100644 --- a/signal.h +++ b/signal.h @@ -19,6 +19,7 @@ struct signal_task { }; int para_signal_init(void); +int para_sigaction(int sig, void (*handler)(int)); int para_install_sighandler(int); void para_reap_children(void); int para_reap_child(pid_t *pid); -- 2.39.5