X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcore%2Fplugin.c;h=b3d5973178dffed19411af5d5acea45a99b718e3;hb=e2f0b2814ab337b9f975b16162f73dbbc7fdf717;hp=eb9797fb40f8ba694f687acec082792877d115fd;hpb=201fe7106cb2514f1d4f10c94a9f823b632184b3;p=sysdb.git diff --git a/src/core/plugin.c b/src/core/plugin.c index eb9797f..b3d5973 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -442,7 +442,8 @@ module_init(const char *name, lt_dlhandle lh, sdb_plugin_info_t *info) } /* module_init */ static int -module_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) +module_load(const char *basedir, const char *name, + const sdb_plugin_ctx_t *plugin_ctx) { char base_name[name ? strlen(name) + 1 : 1]; const char *name_ptr; @@ -467,8 +468,10 @@ module_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) } strcat(base_name, name_ptr); - snprintf(filename, sizeof(filename), "%s/%s.so", - PKGLIBDIR, base_name); + if (! basedir) + basedir = PKGLIBDIR; + + snprintf(filename, sizeof(filename), "%s/%s.so", basedir, base_name); filename[sizeof(filename) - 1] = '\0'; if (access(filename, R_OK)) { @@ -575,7 +578,8 @@ plugin_add_callback(sdb_llist_t **list, const char *type, */ int -sdb_plugin_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) +sdb_plugin_load(const char *basedir, const char *name, + const sdb_plugin_ctx_t *plugin_ctx) { ctx_t *ctx; @@ -612,7 +616,7 @@ sdb_plugin_load(const char *name, const sdb_plugin_ctx_t *plugin_ctx) return 0; } - return module_load(name, plugin_ctx); + return module_load(basedir, name, plugin_ctx); } /* sdb_plugin_load */ int @@ -1109,12 +1113,11 @@ sdb_plugin_log(int prio, const char *msg) sdb_llist_iter_t *iter; int ret = -1; + _Bool logged = 0; + if (! msg) return 0; - 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); while (sdb_llist_iter_has_next(iter)) { sdb_plugin_log_cb callback; @@ -1127,8 +1130,15 @@ sdb_plugin_log(int prio, const char *msg) tmp = callback(prio, msg, SDB_PLUGIN_CB(obj)->cb_user_data); if (tmp > ret) ret = tmp; + + if (SDB_PLUGIN_CB(obj)->cb_ctx) + logged = 1; + /* else: this is an internally registered callback */ } sdb_llist_iter_destroy(iter); + + if (! logged) + return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg); return ret; } /* sdb_plugin_log */