X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.c;h=a602af9294d42144d14e62c3c34384528dd7f005;hb=1205c90cccd3144bab24b4b5fd8dcbf0d0e6b570;hp=fdf8a34bedf61c7d9a108bdc16f775f97258591c;hpb=2b1bd19ee26f4ee5b2010d830cdabed952a37be4;p=src%2Fapp-framework-binder.git diff --git a/src/main.c b/src/main.c index fdf8a34b..a602af92 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 @@ -503,8 +536,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 +546,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; @@ -532,11 +570,13 @@ int main(int argc, char *argv[]) { // let's not take the risk to run as ROOT //if (getuid() == 0) goto errorNoRoot; +#if defined(ALLOWS_SESSION_FILES) // check session dir and create if it does not exist if (sessionCheckdir (session) != AFB_SUCCESS) { fprintf (stderr,"\nERR: AFB-daemon cannot read/write session dir\n\n"); exit (1); } +#endif if (verbose) fprintf (stderr, "AFB: notice Init config done\n"); // ---- run in foreground mode --------------------