- Make geom commands handle multiple library paths in the GEOM_LIBRARY_PATH

environment variable using ':' as a separator.

Approved by:	pjd (mentor)
MFC after:	3 days
This commit is contained in:
Ulf Lilleengen 2008-02-04 12:17:02 +00:00
parent 499f0f956d
commit 2591e96ce2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=175967

View File

@ -485,22 +485,42 @@ library_path(void)
static void
load_library(void)
{
char path[MAXPATHLEN];
char *curpath, path[MAXPATHLEN], *totalpath;
uint32_t *lib_version;
void *dlh;
int ret;
snprintf(path, sizeof(path), "%s/geom_%s.so", library_path(),
class_name);
if (access(path, F_OK) == -1) {
if (errno == ENOENT) {
/*
* If we cannot find library, that's ok, standard
* commands can still be used.
*/
return;
ret = 0;
totalpath = strdup(library_path());
if (totalpath == NULL)
err(EXIT_FAILURE, "Not enough memory for library path");
if (strchr(totalpath, ':') != NULL)
curpath = strsep(&totalpath, ":");
else
curpath = totalpath;
/* Traverse the paths to find one that contains the library we want. */
while (curpath != NULL) {
snprintf(path, sizeof(path), "%s/geom_%s.so", curpath,
class_name);
ret = access(path, F_OK);
if (ret == -1) {
if (errno == ENOENT) {
/*
* If we cannot find library, try the next
* path.
*/
curpath = strsep(&totalpath, ":");
continue;
}
err(EXIT_FAILURE, "Cannot access library");
}
err(EXIT_FAILURE, "Cannot access library");
break;
}
free(totalpath);
/* No library was found, but standard commands can still be used */
if (ret == -1)
return;
dlh = dlopen(path, RTLD_NOW);
if (dlh == NULL)
errx(EXIT_FAILURE, "Cannot open library: %s.", dlerror());