X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fmain.c;h=c825e58735af07a46aa5ab5d5d94778c7f716cb6;hb=446e0a75684131f2f2fec251775db9ee450003ec;hp=9586bb564f6cb88f579b82768304318ac1720292;hpb=b55efc33fb8df8b0518570b2584b6da9abb3221b;p=src%2Fapp-framework-binder.git diff --git a/src/main.c b/src/main.c index 9586bb56..c825e587 100644 --- a/src/main.c +++ b/src/main.c @@ -30,8 +30,7 @@ #include #include -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 @@ -61,6 +60,7 @@ static sigjmp_buf restartpoint; // context save for set/longjmp #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 @@ -88,9 +88,10 @@ static AFB_options cliOptions [] = { {KILL_PREV_REST ,0,"restart" , "Kill active process if any and restart"}, {SET_TCP_PORT ,1,"port" , "HTTP listening TCP port [default 1234]"}, - {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_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]"}, @@ -101,30 +102,22 @@ static AFB_options cliOptions [] = { {SET_CONFIG_SAVE ,0,"save" , "Save config on disk [default no]"}, {SET_CONFIG_EXIT ,0,"saveonly" , "Save config on disk and then exit"}, - {SET_SMACK ,1,"smack" , "Set Smack Label [default=demo"}, - {SET_PLUGINS ,1,"mods" , "Enable module [default=all"}, + {SET_SMACK ,1,"smack" , "Set Smack Label [default demo]"}, + {SET_PLUGINS ,1,"mods" , "Enable module [default all]"}, {DISPLAY_VERSION ,0,"version" , "Display version and copyright"}, {DISPLAY_HELP ,0,"help" , "Display this help"}, {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; @@ -133,9 +126,9 @@ void signalFail (int signum) { 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); } @@ -223,7 +216,6 @@ static void closeSession (AFB_session *session) { } - /*---------------------------------------------------------- | listenLoop | Main listening HTTP loop @@ -231,7 +223,7 @@ static void closeSession (AFB_session *session) { 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; } @@ -248,8 +240,7 @@ static void listenLoop (AFB_session *session) { fprintf (stderr, "hoops returned from infinite loop [report bug]\n"); } } - - + /*--------------------------------------------------------- | main | Parse option and launch action @@ -264,8 +255,10 @@ int main(int argc, char *argv[]) { 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; @@ -312,16 +305,32 @@ int main(int argc, char *argv[]) { 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: @@ -458,8 +467,8 @@ int main(int argc, char *argv[]) { 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); @@ -469,11 +478,7 @@ int main(int argc, char *argv[]) { // 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);