diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-02-07 11:25:37 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-02-09 17:26:05 +0100 |
commit | b947c93689b2b93a02cdc427e58805d79a323116 (patch) | |
tree | 0ec26de2c898af91e2eecef2a3a3d95a09ec4535 | |
parent | 3e95cd69de2d08d8175ec4fcbca73f37fcef1b30 (diff) |
afb-session: Return an initialization status
Avoid exiting anywhere
Change-Id: Ic24a2c7435645632d609fb16849d33b204062397
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-session.c | 16 | ||||
-rw-r--r-- | src/afb-session.h | 2 | ||||
-rw-r--r-- | src/main.c | 5 |
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); @@ -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; |