From 97b1fb8034c883e3d66ac4c4e75928ae7e9b3cb7 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Mon, 4 Apr 2022 09:06:51 +0200 Subject: [PATCH 1/2] drivers/unix: improve the console output on dlsym() error It prints "Failed to load symbol" instead of a too much generic and misleading message "File not found". Signed-off-by: Dario Binacchi --- drivers/unix/unix.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/unix/unix.c b/drivers/unix/unix.c index b1653a39..1d7e2d94 100644 --- a/drivers/unix/unix.c +++ b/drivers/unix/unix.c @@ -34,8 +34,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define DLSYM(name)\ *(void **) (&name##_driver) = dlsym(handle, #name"_driver");\ - if ((error = dlerror()) != NULL) {\ - fprintf (stderr, "%s\n", error);\ + if (dlerror()) {\ + fprintf (stderr, "Failed to load `%s' symbol\n", \ + #name"_driver"); \ UnLoadCanDriver(handle);\ return NULL;\ } @@ -89,8 +90,6 @@ UNS8 UnLoadCanDriver(LIB_HANDLE handle) LIB_HANDLE LoadCanDriver(const char* driver_name) { LIB_HANDLE handle = NULL; - char *error; - if(handle==NULL) { From 8a58dd716610ebce4c6fbd86ffec2a6d87ac91a5 Mon Sep 17 00:00:00 2001 From: Dario Binacchi Date: Mon, 4 Apr 2022 15:05:27 +0200 Subject: [PATCH 2/2] drivers/unix: call dlerror() before calling dlsym() As reported by Linux man page: "In unusual cases the value of the symbol returned by dlsym() could be NULL. Therefore, a NULL return from dlsym() need not indicate an error. The correct way to distinguish an error from a symbol whose value is NULL is to call dlerror(3) to clear any old error conditions, then call dlsym(), and then call dlerror() again, saving its return value into a variable, and check whether this saved value is not NULL." Signed-off-by: Dario Binacchi --- drivers/unix/unix.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/unix/unix.c b/drivers/unix/unix.c index 1d7e2d94..cd35680f 100644 --- a/drivers/unix/unix.c +++ b/drivers/unix/unix.c @@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #define FCT_PTR_INIT =NULL #define DLSYM(name)\ + dlerror(); \ *(void **) (&name##_driver) = dlsym(handle, #name"_driver");\ if (dlerror()) {\ fprintf (stderr, "Failed to load `%s' symbol\n", \