X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.c;h=400a55c072039a4acb6f5e4676b7f4aa58431ea5;hb=520bbafb30ce49b94b7825ff553d8cb5bda6d612;hp=e9cddcb51a572ae2f1d127a9a6f0df477e208e79;hpb=80437693983321d32f20b6324128d441c5fccc49;p=src%2Fapp-framework-binder.git diff --git a/src/main.c b/src/main.c index e9cddcb5..400a55c0 100644 --- a/src/main.c +++ b/src/main.c @@ -21,10 +21,13 @@ #include #include #include +#include #include #include #include "local-def.h" +#include "afb-apis.h" +#include "session.h" #if !defined(PLUGIN_INSTALL_DIR) #error "you should define PLUGIN_INSTALL_DIR" @@ -414,6 +417,36 @@ void signalQuit (int signum) { } +/*---------------------------------------------------------- + | Error signals + | + +--------------------------------------------------------- */ +__thread sigjmp_buf *error_handler; +static void signalError(int signum) +{ + sigset_t sigset; + + // unlock signal to allow a new signal to come + sigemptyset(&sigset); + sigaddset(&sigset, signum); + sigprocmask(SIG_UNBLOCK, &sigset, 0); + if (error_handler != NULL) { + longjmp(*error_handler, signum); + } +} + +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) { + fprintf(stderr, "Signal handler error\n"); + exit(1); + } + } +} + /*---------------------------------------------------------- | listenLoop | Main listening HTTP loop @@ -513,9 +546,13 @@ int main(int argc, char *argv[]) { exit (1); } - initPlugins(session); + if (session->config->ldpaths) + afb_apis_add_pathset(session->config->ldpaths); + ctxStoreInit(CTX_NBCLIENTS); + install_error_handlers(); + // ------------------ Some useful default values ------------------------- if ((session->background == 0) && (session->foreground == 0)) session->foreground=1;