#include <signal.h>
#include <getopt.h>
-static sigjmp_buf exitpoint; // context save for set/longjmp
-static sigjmp_buf restartpoint; // context save for set/longjmp
+static sigjmp_buf exitPoint; // context save for set/longjmp
/*----------------------------------------------------------
| printversion
#define SET_ROOT_DIR 121
#define SET_ROOT_BASE 122
#define SET_ROOT_API 123
+ #define SET_ROOT_ALIAS 124
#define SET_CACHE_TO 130
#define SET_cardid 131
#define SET_SMACK 140
#define SET_PLUGINS 141
+ #define SET_APITIMEOUT 142
#define DISPLAY_VERSION 150
#define DISPLAY_HELP 151
{SET_ROOT_DIR ,1,"rootdir" , "HTTP Root Directory [default $HOME/.AFB"},
{SET_ROOT_BASE ,1,"rootbase" , "Angular Base Root URL [default /opa"},
{SET_ROOT_API ,1,"rootapi" , "HTML Root API URL [default /api"},
+ {SET_ROOT_ALIAS ,1,"alias" , "Muliple url map outside of rootdir [eg: --alias=/icons:/usr/share/icons]"},
+ {SET_APITIMEOUT ,1,"apitimeout" , "Plugin API timeout in seconds [default 10]"},
{SET_CACHE_TO ,1,"cache-eol" , "Client cache end of live [default 3600s]"},
{SET_cardid ,1,"setuid" , "Change user id [default don't change]"},
{0, 0, 0}
};
-/*----------------------------------------------------------
- | signalQuit
- | return to intitial exitpoint on order to close backend
- | before exiting.
- +--------------------------------------------------------- */
-void signalQuit (int signum)
-{
- if (verbose) printf ("INF:signalQuit received signal to quit\n");
- longjmp (exitpoint, signum);
-}
+static AFB_aliasdir aliasdir[MAX_ALIAS];
+static int aliascount=0;
/*----------------------------------------------------------
| timeout signalQuit
|
+--------------------------------------------------------- */
-void signalFail (int signum) {
+void signalQuit (int signum) {
sigset_t sigset;
sigaddset (&sigset, SIGABRT);
sigprocmask (SIG_UNBLOCK, &sigset, 0);
- fprintf (stderr, "%s ERR:getAllBlock acquisition timeout\n",configTime());
- syslog (LOG_ERR, "Daemon fail and restart [please report bug]");
- longjmp (restartpoint, signum);
+ fprintf (stderr, "%s ERR:Received signal quit\n",configTime());
+ syslog (LOG_ERR, "Daemon got kill3 & quit [please report bug]");
+ longjmp (exitPoint, signum);
}
}
-
/*----------------------------------------------------------
| listenLoop
| Main listening HTTP loop
static void listenLoop (AFB_session *session) {
AFB_error err;
- if (signal (SIGABRT, signalFail) == SIG_ERR) {
+ if (signal (SIGABRT, signalQuit) == SIG_ERR) {
fprintf (stderr, "%s ERR: main fail to install Signal handler\n", configTime());
return;
}
AFB_config cliconfig; // temp structure to store CLI option before file config upload
// ------------- Build session handler & init config -------
- session = configInit ();
- memset (&cliconfig,0,sizeof(cliconfig));
+ session = configInit ();
+ memset(&cliconfig,0,sizeof(cliconfig));
+ memset(&aliasdir ,0,sizeof(aliasdir));
+ cliconfig.aliasdir = aliasdir;
// GNU CLI getopts nterface.
struct option ggcOption;
if (optarg == 0) goto needValueForOption;
if (!sscanf (optarg, "%d", &cliconfig.httpdPort)) goto notAnInteger;
break;
+
+ case SET_APITIMEOUT:
+ if (optarg == 0) goto needValueForOption;
+ if (!sscanf (optarg, "%d", &cliconfig.apiTimeout)) goto notAnInteger;
+ break;
case SET_ROOT_DIR:
if (optarg == 0) goto needValueForOption;
cliconfig.rootdir = optarg;
+ if (verbose) fprintf(stderr, "Forcing Rootdir=%s\n",cliconfig.rootdir);
break;
case SET_ROOT_BASE:
if (optarg == 0) goto needValueForOption;
cliconfig.rootbase = optarg;
+ if (verbose) fprintf(stderr, "Forcing Rootbase=%s\n",cliconfig.rootbase);
break;
case SET_ROOT_API:
if (optarg == 0) goto needValueForOption;
cliconfig.rootapi = optarg;
+ if (verbose) fprintf(stderr, "Forcing Rootapi=%s\n",cliconfig.rootapi);
+ break;
+
+ case SET_ROOT_ALIAS:
+ if (optarg == 0) goto needValueForOption;
+ if (aliascount < MAX_ALIAS) {
+ aliasdir[aliascount].url = strsep(&optarg,":");
+ aliasdir[aliascount].path = strsep(&optarg,":");
+ aliasdir[aliascount].len = strlen(aliasdir[aliascount].url);
+ if (verbose) fprintf(stderr, "Alias url=%s path=%s\n", aliasdir[aliascount].url, aliasdir[aliascount].path);
+ aliascount++;
+ } else {
+ fprintf(stderr, "Too many aliases [max:%s] %s ignored\n", optarg, MAX_ALIAS-1);
+ }
break;
case SET_SMACK:
return (-1);
}
- // save exitpoint context when returning from longjmp closeSession and exit
- status = setjmp (exitpoint); // return !+ when coming from longjmp
+ // save exitPoint context when returning from longjmp closeSession and exit
+ status = setjmp (exitPoint); // return !+ when coming from longjmp
if (status != 0) {
if (verbose) printf ("INF:main returning from longjump after signal [%d]\n", status);
closeSession (session);
// let's run this program with a low priority
status=nice (20);
-
// ------------------ Finaly Process Commands -----------------------------
-
-
-
// if --save then store config on disk upfront
if (session->configsave) configStoreFile (session);
if (session->forceexit) exit (0);