Code

plugin: Do not expect all callbacks to have a plugin context assigned.
authorSebastian Harl <sh@tokkee.org>
Mon, 21 Apr 2014 16:18:56 +0000 (18:18 +0200)
committerSebastian Harl <sh@tokkee.org>
Mon, 21 Apr 2014 16:26:58 +0000 (18:26 +0200)
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.

src/core/plugin.c

index fe8844a505d061e1df09ec9a720d95c2f30fb9c9..687ed36e39aa4c18b59fdca83ecd92a26ec4448b 100644 (file)
@@ -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));