aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afb-session.c16
-rw-r--r--src/afb-session.h2
-rw-r--r--src/main.c5
3 files changed, 18 insertions, 5 deletions
diff --git a/src/afb-session.c b/src/afb-session.c
index fd8e3885..f0cf0744 100644
--- a/src/afb-session.c
+++ b/src/afb-session.c
@@ -124,8 +124,16 @@ static int pearson4(const char *text)
return r; // % HEADCOUNT;
}
-// Create a new store in RAM, not that is too small it will be automatically extended
-void afb_session_init (int max_session_count, int timeout, const char *initok)
+/**
+ * Initialize the session manager with a 'max_session_count',
+ * an initial common 'timeout' and an initial common token 'initok'.
+ *
+ * @param max_session_count maximum allowed session count in the same time
+ * @param timeout the initial default timeout of sessions
+ * @param initok the initial default token of sessions
+ *
+ */
+int afb_session_init (int max_session_count, int timeout, const char *initok)
{
pthread_mutex_init(&sessions.mutex, NULL);
sessions.max = max_session_count;
@@ -137,8 +145,10 @@ void afb_session_init (int max_session_count, int timeout, const char *initok)
strcpy(sessions.initok, initok);
else {
ERROR("initial token '%s' too long (max length %d)", initok, ((int)(sizeof sessions.initok)) - 1);
- exit(1);
+ errno = EINVAL;
+ return -1;
}
+ return 0;
}
const char *afb_session_initial_token()
diff --git a/src/afb-session.h b/src/afb-session.h
index d79ec414..9e3705b8 100644
--- a/src/afb-session.h
+++ b/src/afb-session.h
@@ -23,7 +23,7 @@ struct afb_session;
#define AFB_SESSION_TIMEOUT_DEFAULT -2
#define AFB_SESSION_TIMEOUT_IS_VALID(x) ((x) >= AFB_SESSION_TIMEOUT_DEFAULT)
-extern void afb_session_init(int max_session_count, int timeout, const char *initok);
+extern int afb_session_init(int max_session_count, int timeout, const char *initok);
extern const char *afb_session_initial_token();
extern struct afb_session *afb_session_create (int timeout);
diff --git a/src/main.c b/src/main.c
index 952b4868..64325400 100644
--- a/src/main.c
+++ b/src/main.c
@@ -564,7 +564,10 @@ static void start(int signum, void *arg)
}
/* configure the daemon */
- afb_session_init(config->nbSessionMax, config->cntxTimeout, config->token);
+ if (afb_session_init(config->nbSessionMax, config->cntxTimeout, config->token)) {
+ ERROR("initialisation of session manager failed");
+ goto error;
+ }
if (!afb_hreq_init_cookie(config->httpdPort, config->rootapi, config->cntxTimeout)) {
ERROR("initialisation of cookies failed");
goto error;