/** \brief initialize the configuration
* \warning Not thread safe */
-static void THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
+static int THashInitConfig(THashTableContext *ctx, const char *cnf_prefix)
{
char varname[256];
SCLogError(SC_ERR_SIZE_PARSE, "Error parsing %s "
"from conf file - %s. Killing engine",
varname, conf_val);
- exit(EXIT_FAILURE);
+ return -1;
}
}
GET_VAR(cnf_prefix, "hash-size");
"total hash size by multiplying \"hash-size\" with %"PRIuMAX", "
"which is the hash bucket size.", ctx->config.memcap, hash_size,
(uintmax_t)sizeof(THashHashRow));
- exit(EXIT_FAILURE);
+ return -1;
}
ctx->array = SCMallocAligned(ctx->config.hash_size * sizeof(THashHashRow), CLS);
if (unlikely(ctx->array == NULL)) {
- FatalError(SC_ERR_FATAL,
- "Fatal error encountered in THashInitConfig. Exiting...");
+ SCLogError(SC_ERR_THASH_INIT, "Fatal error encountered in THashInitConfig. Exiting...");
+ return -1;
}
memset(ctx->array, 0, ctx->config.hash_size * sizeof(THashHashRow));
"max thash memcap reached. Memcap %"PRIu64", "
"Memuse %"PRIu64".", ctx->config.memcap,
((uint64_t)SC_ATOMIC_GET(ctx->memuse) + THASH_DATA_SIZE(ctx)));
- exit(EXIT_FAILURE);
+ return -1;
}
THashData *h = THashDataAlloc(ctx);
if (h == NULL) {
SCLogError(SC_ERR_THASH_INIT, "preallocating data failed: %s", strerror(errno));
- exit(EXIT_FAILURE);
+ return -1;
}
THashDataEnqueue(&ctx->spare_q,h);
}
- return;
+ return 0;
}
THashTableContext *THashInit(const char *cnf_prefix, size_t data_size,
SC_ATOMIC_INIT(ctx->prune_idx);
THashDataQueueInit(&ctx->spare_q);
- THashInitConfig(ctx, cnf_prefix);
+ if (THashInitConfig(ctx, cnf_prefix) < 0) {
+ THashShutdown(ctx);
+ ctx = NULL;
+ }
return ctx;
}