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
This commit is contained in:
Pawel Jakub Dawidek 2005-08-14 21:55:18 +00:00
parent 96e5109430
commit a73148d28d

View File

@ -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",