X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.c;h=0c4e42f7771070eea41c89ec836e9223eeb48996;hb=36a165503297903204be32a07e0440ca56dac7f0;hp=81f891b362d39e2e971425ab0b198b3570eff9f9;hpb=3b0d4962f64f546474fa033ffa4e3d067194c888;p=src%2Fapp-framework-binder.git diff --git a/src/main.c b/src/main.c index 81f891b3..0c4e42f7 100644 --- a/src/main.c +++ b/src/main.c @@ -42,6 +42,7 @@ #include "afb-hsrv.h" #include "afb-context.h" #include "afb-hreq.h" +#include "afb-sig-handler.h" #include "session.h" #include "verbose.h" #include "afb-common.h" @@ -127,8 +128,6 @@ static AFB_options cliOptions [] = { {0, 0, NULL, NULL} }; - - /*---------------------------------------------------------- | printversion | print version and copyright @@ -428,49 +427,6 @@ static void closeSession (int status, void *data) { /* struct afb_config *config = data; */ } -/*---------------------------------------------------------- - | timeout signalQuit - +--------------------------------------------------------- */ -void signalQuit (int signum) -{ - ERROR("Terminating signal received %s", strsignal(signum)); - exit(1); -} - -/*---------------------------------------------------------- - | Error signals - | - +--------------------------------------------------------- */ -__thread sigjmp_buf *error_handler; -static void signalError(int signum) -{ - sigset_t sigset; - - // unlock signal to allow a new signal to come - if (error_handler != NULL) { - sigemptyset(&sigset); - sigaddset(&sigset, signum); - sigprocmask(SIG_UNBLOCK, &sigset, 0); - longjmp(*error_handler, signum); - } - if (signum == SIGALRM) - return; - ERROR("Unmonitored signal received %s", strsignal(signum)); - exit(2); -} - -static void install_error_handlers() -{ - int i, signals[] = { SIGALRM, SIGSEGV, SIGFPE, 0 }; - - for (i = 0; signals[i] != 0; i++) { - if (signal(signals[i], signalError) == SIG_ERR) { - ERROR("Signal handler error"); - exit(1); - } - } -} - /*---------------------------------------------------------- | daemonize | set the process in background @@ -647,11 +603,8 @@ int main(int argc, char *argv[]) { exit (1); } - install_error_handlers(); - - // ------------------ clean exit on CTR-C signal ------------------------ - if (signal (SIGINT, signalQuit) == SIG_ERR || signal (SIGABRT, signalQuit) == SIG_ERR) { - ERROR("main fail to install Signal handler"); + if (afb_sig_handler_init() < 0) { + ERROR("main fail to initialise signal handlers"); return 1; }