Skip to content

Commit ae3ce6e

Browse files
plugins: better plugin load failure logging
1 parent 73f589a commit ae3ce6e

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

src/plugins.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ plug_remove_plugin (void *p) {
870870
// d_name must be writable w/o sideeffects; contain valid .so name
871871
// l must be strlen(d_name)
872872
static int
873-
load_plugin (const char *plugdir, char *d_name, int l) {
873+
load_plugin (const char *plugdir, const char *d_name, int l) {
874874
// hack for osx to skip *.0.so files
875875
if (strstr (d_name, ".0.so")) {
876876
return -1;
@@ -911,30 +911,40 @@ load_plugin (const char *plugdir, char *d_name, int l) {
911911
}
912912
#endif
913913
}
914-
d_name[l-sizeof (PLUGINEXT)+1] = 0;
915-
strcat (d_name, "_load");
916-
#ifndef ANDROID
917-
DB_plugin_t *(*plug_load)(DB_functions_t *api) = dlsym (handle, d_name);
918-
#else
919-
DB_plugin_t *(*plug_load)(DB_functions_t *api) = dlsym (handle, d_name+3);
914+
915+
char *d_name_copy = calloc(strlen(d_name) + 20, 1);
916+
strcpy(d_name_copy, d_name);
917+
d_name_copy[l-sizeof (PLUGINEXT)+1] = 0;
918+
strcat (d_name_copy, "_load");
919+
920+
const char *load_name = d_name_copy;
921+
922+
#ifdef ANDROID
923+
load_name += 3;
920924
#endif
925+
926+
DB_plugin_t *(*plug_load)(DB_functions_t *api) = dlsym (handle, load_name);
921927
if (!plug_load) {
928+
int err = 0;
922929
int android = 0;
923930
#ifdef ANDROID
924931
android = 1;
925932
#endif
926-
dlclose (handle);
927933
// don't error after failing to load plugins starting with "lib",
928934
// e.g. attempting to load a plugin from "libmp4ff.so",
929935
// except android, where all plugins have lib prefix
930936
if (android || !has_lib_prefix) {
931-
trace ("dlsym error: %s (%s)\n", dlerror (), d_name + 3);
932-
return -1;
937+
trace ("dlsym error: %s (%s)\n", dlerror (), load_name);
938+
free (d_name_copy);
939+
d_name_copy = NULL;
940+
err = -1;
933941
}
934-
return 0;
942+
dlclose (handle);
943+
return err;
935944
}
945+
free (d_name_copy);
946+
d_name_copy = NULL;
936947
if (plug_init_plugin (plug_load, handle) < 0) {
937-
d_name[l-sizeof (PLUGINEXT)+1] = 0;
938948
dlclose (handle);
939949
return -1;
940950
}

0 commit comments

Comments
 (0)