From: Sebastian Harl Date: Mon, 21 Apr 2014 16:18:56 +0000 (+0200) Subject: plugin: Do not expect all callbacks to have a plugin context assigned. X-Git-Tag: sysdb-0.1.0~112 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=eb3175b2d1f8bbad5da0e6f02467f3f76d7c4c8b;p=sysdb.git plugin: Do not expect all callbacks to have a plugin context assigned. For callbacks not registered from a plugin, we don't have a context. For example, the frontend's connection logger callback does not have a context. --- diff --git a/src/core/plugin.c b/src/core/plugin.c index fe8844a..687ed36 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -196,7 +196,13 @@ plugin_lookup_by_name(const sdb_object_t *obj, const void *id) const sdb_plugin_cb_t *cb = SDB_CONST_PLUGIN_CB(obj); const char *name = id; - assert(cb && id && cb->cb_ctx); + assert(cb && id); + + /* when a plugin was registered from outside a plugin (e.g. the core), + * we don't have a plugin context */ + if (! cb->cb_ctx) + return 1; + if (!strcasecmp(cb->cb_ctx->info.plugin_name, name)) return 0; return 1; @@ -232,6 +238,8 @@ plugin_unregister_by_name(const char *plugin_name) if (! cb) break; + assert(cb->cb_ctx); + sdb_log(SDB_LOG_INFO, "core: Unregistering " "%s callback '%s' (module %s)", type, cb->super.name, cb->cb_ctx->info.plugin_name); @@ -351,6 +359,8 @@ plugin_cb_init(sdb_object_t *obj, va_list ap) return -1; } + /* cb_ctx may be NULL if the plugin was not registered by a plugin */ + SDB_PLUGIN_CB(obj)->cb_callback = callback; SDB_PLUGIN_CB(obj)->cb_ctx = ctx_get(); sdb_object_ref(SDB_OBJ(SDB_PLUGIN_CB(obj)->cb_ctx));