From 2e24f5f1b5a39d00939d55343e3daad72687031b Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Tue, 31 Oct 2017 21:39:15 +0100 Subject: scripting: report dlerror() output dlopen() and dlsym() can fail in various ways, and we can find out how it failed by calling dlerror(). This is particularly useful if you typo the filename of a script when explicitly passing it with --script, and dlopen actually tells you that the file doesn't exist instead of leading you down a rabbit hole of disassembling your shared object file to figure out why the thing won't load. --- player/scripting.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/player/scripting.c b/player/scripting.c index 4073da765d..28f8fdd038 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -254,7 +254,7 @@ typedef int (*mpv_open_cplugin)(mpv_handle *handle); static int load_cplugin(struct mpv_handle *client, const char *fname) { - int r = -1; + MPContext *ctx = mp_client_get_core(client); void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL); if (!lib) goto error; @@ -263,9 +263,12 @@ static int load_cplugin(struct mpv_handle *client, const char *fname) mpv_open_cplugin sym = (mpv_open_cplugin)dlsym(lib, MPV_DLOPEN_FN); if (!sym) goto error; - r = sym(client) ? -1 : 0; -error: - return r; + return sym(client) ? -1 : 0; +error: ; + char *err = dlerror(); + if (err) + MP_ERR(ctx, "C plugin error: '%s'\n", err); + return -1; } const struct mp_scripting mp_scripting_cplugin = { -- cgit v1.2.3