From a73148d28d77be970f72ed2162ba0a0249d1b7e2 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Sun, 14 Aug 2005 21:55:18 +0000 Subject: [PATCH] Unfortunately dlerror(3) returns string, so there is no clean way to ignore "no such file" errors only, which I wanted to do. Because of this I ignored all other errors on dlopen(3) failure as well, which isn't good. Fix this situation by calling access(2) on library file first and ignore only ENOENT error. This allows to report all the rest of dlopen(3) errors. MFC after: 3 days --- sbin/geom/core/geom.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index 17a4ad8287ff..3db7cf4dddc6 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -471,18 +471,19 @@ load_library(void) snprintf(path, sizeof(path), "%s/geom_%s.so", library_path(), class_name); - dlh = dlopen(path, RTLD_NOW); - if (dlh == NULL) { -#if 0 - fprintf(stderr, "Cannot open library %s, but continuing " - "anyway.\n", path); -#endif - /* - * Even if library cannot be loaded, standard commands are - * available, so don't panic! - */ - return; + if (access(path, F_OK) == -1) { + if (errno == ENOENT) { + /* + * If we cannot find library, that's ok, standard + * commands can still be used. + */ + return; + } + err(EXIT_FAILURE, "Cannot access library"); } + dlh = dlopen(path, RTLD_NOW); + if (dlh == NULL) + errx(EXIT_FAILURE, "Cannot open library: %s.", dlerror()); lib_version = dlsym(dlh, "lib_version"); if (lib_version == NULL) { fprintf(stderr, "Cannot find symbol %s: %s.\n", "lib_version",