Code

plugin: Log to stderr if no logger has been registered.
[sysdb.git] / src / core / plugin.c
index 929abaee8467cf4bc7f419c324cdd7c6b46a339f..188c7db1515859739efff2c456bd00c62f893f98 100644 (file)
@@ -292,22 +292,6 @@ static sdb_type_t ctx_type = {
        ctx_destroy
 };
 
-static ctx_t *
-ctx_create(const char *name)
-{
-       ctx_t *ctx;
-
-       ctx = CTX(sdb_object_create(name, ctx_type));
-       if (! ctx)
-               return NULL;
-
-       if (! plugin_ctx_key_initialized)
-               ctx_key_init();
-       sdb_object_ref(SDB_OBJ(ctx));
-       pthread_setspecific(plugin_ctx_key, ctx);
-       return ctx;
-} /* ctx_create */
-
 static ctx_t *
 ctx_get(void)
 {
@@ -333,6 +317,21 @@ ctx_set(ctx_t *new)
        return old;
 } /* ctx_set */
 
+static ctx_t *
+ctx_create(const char *name)
+{
+       ctx_t *ctx;
+
+       ctx = CTX(sdb_object_create(name, ctx_type));
+       if (! ctx)
+               return NULL;
+
+       if (! plugin_ctx_key_initialized)
+               ctx_key_init();
+       ctx_set(ctx);
+       return ctx;
+} /* ctx_create */
+
 static int
 plugin_cb_init(sdb_object_t *obj, va_list ap)
 {
@@ -960,7 +959,7 @@ sdb_plugin_log(int prio, const char *msg)
        if (! msg)
                return 0;
 
-       if (! log_list)
+       if (! sdb_llist_len(log_list))
                return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg);
 
        iter = sdb_llist_get_iter(log_list);