#define SET_VERBOSE 1
#define SET_BACKGROUND 2
#define SET_FORGROUND 3
-#define SET_FAKE_MOD 4
#define SET_TCP_PORT 5
#define SET_ROOT_DIR 6
// load config from disk and merge with CLI option
static void config_set_default (AFB_session * session)
{
- static char cacheTimeout [10];
-
// default HTTP port
if (session->config->httpdPort == 0)
session->config->httpdPort = 1234;
strncpy (session->config->console, session->config->sessiondir, 512);
strncat (session->config->console, "/AFB-console.out",512);
}
-
- // cacheTimeout is an integer but HTTPd wants it as a string
- snprintf (cacheTimeout, sizeof (cacheTimeout),"%d", session->config->cacheTimeout);
- session->cacheTimeout = cacheTimeout; // httpd uses cacheTimeout string version
}
if (!sscanf (optarg, "%d", &session->config->cacheTimeout)) goto notAnInteger;
break;
- case SET_FAKE_MOD:
- if (optarg != 0) goto noValueForOption;
- session->fakemod = 1;
- break;
-
case SET_FORGROUND:
if (optarg != 0) goto noValueForOption;
- session->foreground = 1;
+ session->background = 0;
break;
case SET_BACKGROUND:
parse_arguments(argc, argv, 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->httpdPort <= 0) {
fprintf (stderr, "ERR: no port is defined\n");
exit (1);
install_error_handlers();
- // ------------------ Some useful default values -------------------------
- if ((session->background == 0) && (session->foreground == 0))
- session->foreground = 1;
-
// ------------------ clean exit on CTR-C signal ------------------------
if (signal (SIGINT, signalQuit) == SIG_ERR || signal (SIGABRT, signalQuit) == SIG_ERR) {
fprintf (stderr, "ERR: main fail to install Signal handler\n");
if (verbosity) fprintf (stderr, "AFB: notice Init config done\n");
- // ---- run in foreground mode --------------------
- if (session->foreground) {
-
- if (verbosity) fprintf (stderr,"AFB: notice Foreground mode\n");
-
- } // end foreground
-
- // --------- run in background mode -----------
+ // --------- run -----------
if (session->background) {
-
+ // --------- in background mode -----------
if (verbosity) printf ("AFB: Entering background mode\n");
-
daemonize(session);
+ } else {
+ // ---- in foreground mode --------------------
+ if (verbosity) fprintf (stderr,"AFB: notice Foreground mode\n");
- // if everything look OK then look forever
- syslog (LOG_ERR, "AFB: Entering infinite loop in background mode");
-
-
- } // end background-foreground
-
-
- // ------ Start httpd server
+ }
rc = afb_hsrv_start (session);
if (!rc)