/* creates a new config context that is an interface to the
* cfg variables with write permission
*/
-cfg_ctx_t *cfg_register_ctx(cfg_on_declare on_declare_cb)
+int cfg_register_ctx(cfg_ctx_t **handle, cfg_on_declare on_declare_cb)
{
cfg_ctx_t *ctx;
cfg_group_t *group;
ctx = (cfg_ctx_t *)shm_malloc(sizeof(cfg_ctx_t));
if (!ctx) {
LOG(L_ERR, "ERROR: cfg_register_ctx(): not enough shm memory\n");
- return NULL;
+ return -1;
}
memset(ctx, 0, sizeof(cfg_ctx_t));
if (lock_init(&ctx->lock) == 0) {
LOG(L_ERR, "ERROR: cfg_register_ctx(): failed to init lock\n");
shm_free(ctx);
- return NULL;
+ return -1;
}
/* add the new ctx to the beginning of the list */
ctx->next = cfg_ctx_list;
cfg_ctx_list = ctx;
- /* let the driver know about the already registered groups */
+ /* let the driver know about the already registered groups
+ * The handle of the context must be set before calling the
+ * on_declare callbacks. */
+ *handle = ctx;
if (on_declare_cb) {
ctx->on_declare_cb = on_declare_cb;
}
}
- return ctx;
+ return 0;
}
/* free the memory allocated for the contexts */
/* creates a new config context that is an interface to the
* cfg variables with write permission */
-cfg_ctx_t *cfg_register_ctx(cfg_on_declare on_declare_cb);
+int cfg_register_ctx(cfg_ctx_t **handle, cfg_on_declare on_declare_cb);
/* free the memory allocated for the contexts */
void cfg_ctx_destroy(void);
static int mod_init(void)
{
- ctx = cfg_register_ctx(on_declare);
- if (!ctx) {
+ if (cfg_register_ctx(&ctx, on_declare)) {
/* error */
return -1;
}