From f990546f248a34c6f8c175db2025ce405ddab307 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 21 Jan 2013 11:36:48 +0100 Subject: [PATCH] src/plugin.c: Improve error messages in plugin_load(). Fixes Github issue #237. --- src/plugin.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 547b5eb5..478ec52c 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -826,8 +826,6 @@ int plugin_load (const char *type, uint32_t flags) struct dirent *de; int status; - DEBUG ("type = %s", type); - dir = plugin_get_dir (); ret = 1; @@ -836,7 +834,7 @@ int plugin_load (const char *type, uint32_t flags) status = ssnprintf (typename, sizeof (typename), "%s.so", type); if ((status < 0) || ((size_t) status >= sizeof (typename))) { - WARNING ("snprintf: truncated: `%s.so'", type); + WARNING ("plugin_load: Filename too long: \"%s.so\"", type); return (-1); } typename_len = strlen (typename); @@ -844,7 +842,7 @@ int plugin_load (const char *type, uint32_t flags) if ((dh = opendir (dir)) == NULL) { char errbuf[1024]; - ERROR ("opendir (%s): %s", dir, + ERROR ("plugin_load: opendir (%s) failed: %s", dir, sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } @@ -858,25 +856,29 @@ int plugin_load (const char *type, uint32_t flags) "%s/%s", dir, de->d_name); if ((status < 0) || ((size_t) status >= sizeof (filename))) { - WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name); + WARNING ("plugin_load: Filename too long: \"%s/%s\"", + dir, de->d_name); continue; } if (lstat (filename, &statbuf) == -1) { char errbuf[1024]; - WARNING ("stat %s: %s", filename, + WARNING ("plugin_load: stat (\"%s\") failed: %s", + filename, sstrerror (errno, errbuf, sizeof (errbuf))); continue; } else if (!S_ISREG (statbuf.st_mode)) { /* don't follow symlinks */ - WARNING ("stat %s: not a regular file", filename); + WARNING ("plugin_load: %s is not a regular file.", + filename); continue; } - if (plugin_load_file (filename, flags) == 0) + status = plugin_load_file (filename, flags); + if (status == 0) { /* success */ ret = 0; @@ -884,14 +886,16 @@ int plugin_load (const char *type, uint32_t flags) } else { - fprintf (stderr, "Unable to load plugin %s.\n", type); + ERROR ("plugin_load: Load plugin \"%s\" failed with " + "status %i.", type, status); } } closedir (dh); - if (filename[0] == '\0') - fprintf (stderr, "Could not find plugin %s.\n", type); + if (filename[0] == 0) + ERROR ("plugin_load: Could not find plugin \"%s\" in %s", + type, dir); return (ret); } -- 2.11.0