From dc9887834f0ca7d5e369096ceaa7aeb75ff308f7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 6 May 2014 16:37:52 +0200 Subject: add xsigaction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/util.c | 26 ++++++++++++++++++++++++++ src/libmdsserver/util.h | 13 +++++++++++++ 2 files changed, 39 insertions(+) (limited to 'src/libmdsserver') diff --git a/src/libmdsserver/util.c b/src/libmdsserver/util.c index c4606e8..81793ae 100644 --- a/src/libmdsserver/util.c +++ b/src/libmdsserver/util.c @@ -22,6 +22,7 @@ #include #include #include +#include /** @@ -80,3 +81,28 @@ void reexec_server(int argc, char** argv, int reexeced) execv(readlink_buf, reexec_args); } + +/** + * Set up a signal trap. + * This function should only be used for common mds + * signals, and this function may choose to add + * additional behaviour depending on the signal, such + * as blocking other signals. + * + * @param signo The signal to trap + * @param function The function to run when the signal is caught + * @return Zero on success, -1 on error + */ +int xsigaction(int signo, void (*function)(int signo)) +{ + struct sigaction action; + sigset_t sigset; + + sigemptyset(&sigset); + action.sa_handler = function; + action.sa_mask = sigset; + action.sa_flags = 0; + + return sigaction(signo, &action, NULL); +} + diff --git a/src/libmdsserver/util.h b/src/libmdsserver/util.h index 4f505db..8bfaa71 100644 --- a/src/libmdsserver/util.h +++ b/src/libmdsserver/util.h @@ -37,6 +37,19 @@ char* getenv_nonempty(const char* var); */ void reexec_server(int argc, char** argv, int reexeced); +/** + * Set up a signal trap. + * This function should only be used for common mds + * signals, and this function may choose to add + * additional behaviour depending on the signal, such + * as blocking other signals. + * + * @param signo The signal to trap + * @param function The function to run when the signal is caught + * @return Zero on success, -1 on error + */ +int xsigaction(int signo, void (*function)(int signo)); + #endif -- cgit v1.2.3-70-g09d2