#include <signal.h>
#include <getopt.h>
#include <pwd.h>
+#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "local-def.h"
+#include "afb-apis.h"
#if !defined(PLUGIN_INSTALL_DIR)
#error "you should define PLUGIN_INSTALL_DIR"
}
+/*----------------------------------------------------------
+ | 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
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");
exit (1);
}
+ 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;