(The context handle must be ready when the on_declare()
callbacks are called, and it may happen that the callback
is executed before cfg_register_ctx() returns.)
/* creates a new config context that is an interface to the
* cfg variables with write permission
*/
/* 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;
{
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");
ctx = (cfg_ctx_t *)shm_malloc(sizeof(cfg_ctx_t));
if (!ctx) {
LOG(L_ERR, "ERROR: cfg_register_ctx(): not enough shm memory\n");
}
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);
}
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);
}
/* add the new ctx to the beginning of the list */
ctx->next = cfg_ctx_list;
cfg_ctx_list = ctx;
}
/* 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;
if (on_declare_cb) {
ctx->on_declare_cb = on_declare_cb;
}
/* free the memory allocated for the contexts */
}
/* free the memory allocated for the contexts */
/* creates a new config context that is an interface to the
* cfg variables with write permission */
/* 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);
/* free the memory allocated for the contexts */
void cfg_ctx_destroy(void);
static int mod_init(void)
{
static int mod_init(void)
{
- ctx = cfg_register_ctx(on_declare);
- if (!ctx) {
+ if (cfg_register_ctx(&ctx, on_declare)) {