X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.c;h=95b5a653445c48a1002cf403cf37e7fe99e50c0b;hb=11d36a9f7e16aa9992835f8ce06f0e1e5297b131;hp=f73cfac0e939cc2bfb4c772d9042e2e09ff6ba28;hpb=fe79c7ba875a9203020e72e82fa3524fd2fb74d2;p=src%2Fapp-framework-binder.git diff --git a/src/main.c b/src/main.c index f73cfac0..95b5a653 100644 --- a/src/main.c +++ b/src/main.c @@ -16,15 +16,22 @@ * limitations under the License. */ -#include +#define _GNU_SOURCE +#include +#include +#include #include #include -#include -#include +#include +#include #include #include +#include "afb-plugin.h" + #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 +421,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 + if (error_handler != NULL) { + sigemptyset(&sigset); + sigaddset(&sigset, signum); + sigprocmask(SIG_UNBLOCK, &sigset, 0); + 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 @@ -503,8 +540,6 @@ int main(int argc, char *argv[]) { on_exit(closeSession, session); parse_arguments(argc, argv, session); - initPlugins(session); - // ------------------ sanity check ---------------------------------------- if ((session->background) && (session->foreground)) { fprintf (stderr, "ERR: cannot select foreground & background at the same time\n"); @@ -515,6 +550,13 @@ int main(int argc, char *argv[]) { exit (1); } + if (session->config->ldpaths) + afb_apis_add_pathset(session->config->ldpaths); + + ctxStoreInit(CTX_NBCLIENTS, session->config->cntxTimeout, afb_apis_count(), session->config->token); + + install_error_handlers(); + // ------------------ Some useful default values ------------------------- if ((session->background == 0) && (session->foreground == 0)) session->foreground=1;