summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorlulf <lulf@FreeBSD.org>2008-02-04 12:17:02 +0000
committerlulf <lulf@FreeBSD.org>2008-02-04 12:17:02 +0000
commitce24cd825a8e9934cab77ec673e88f417d5afab1 (patch)
tree727db7c7b196330c496cba8f6db57089d5923a62 /sbin
parentb3d2d57ef4bd26b2bc0a7b7b464ab23b8a4eac68 (diff)
downloadFreeBSD-src-ce24cd825a8e9934cab77ec673e88f417d5afab1.zip
FreeBSD-src-ce24cd825a8e9934cab77ec673e88f417d5afab1.tar.gz
- 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
Diffstat (limited to 'sbin')
-rw-r--r--sbin/geom/core/geom.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c
index 2345be3..91fb2f2 100644
--- a/sbin/geom/core/geom.c
+++ b/sbin/geom/core/geom.c
@@ -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());
OpenPOWER on IntegriCloud