summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2005-09-17 04:15:24 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2005-09-17 04:15:24 +0000
commitcb2ade75140bbbc90253e6cc7310fde032d19e77 (patch)
tree55e1fc5fbb199d1f195ec66aebc80b2f0fce15f1 /libexec
parent6861ce3b202c04ea2cc6fef4f4e6042751aefb5d (diff)
refactor this code, much more readable, no operational change.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ld.so/library_subr.c123
1 files changed, 54 insertions, 69 deletions
diff --git a/libexec/ld.so/library_subr.c b/libexec/ld.so/library_subr.c
index 1a4efb56eee..44227c75f8f 100644
--- a/libexec/ld.so/library_subr.c
+++ b/libexec/ld.so/library_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: library_subr.c,v 1.7 2005/09/17 02:52:43 drahn Exp $ */
+/* $OpenBSD: library_subr.c,v 1.8 2005/09/17 04:15:23 drahn Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
@@ -47,6 +47,9 @@
struct dlochld _dlopened_child_list;
+/* local functions */
+elf_object_t * _dl_load_shlib_hint(struct sod *sod, struct sod *req_sod,
+ int type, int flags, int use_hints, const char *libpath);
/*
* _dl_match_file()
@@ -227,6 +230,31 @@ nohints:
}
/*
+ * attempt to locate and load a library based on libpath, sod info and
+ * if it needs to respect hints,
+ * passing type and flags to perform open
+ */
+elf_object_t *
+_dl_load_shlib_hint(struct sod *sod, struct sod *req_sod, int type,
+ int flags, int use_hints, const char *libpath)
+{
+ elf_object_t *object = NULL;
+ char *hint;
+
+ hint = _dl_find_shlib(req_sod, libpath, use_hints);
+ if (hint != NULL) {
+ if (req_sod->sod_minor < sod->sod_minor)
+ _dl_printf("warning: lib%s.so.%d.%d: "
+ "minor version >= %d expected, "
+ "using it anyway\n",
+ sod->sod_name, sod->sod_major,
+ req_sod->sod_minor, sod->sod_minor);
+ object = _dl_tryload_shlib(hint, type, flags);
+ }
+ return object;
+}
+
+/*
* Load a shared object. Search order is:
* If the name contains a '/' use the name exactly as is. (only)
* try the LD_LIBRARY_PATH specification (if present)
@@ -243,13 +271,13 @@ nohints:
* by ldconfig or default to '/usr/lib'
*/
+
elf_object_t *
_dl_load_shlib(const char *libname, elf_object_t *parent, int type, int flags)
{
int try_any_minor, ignore_hints;
struct sod sod, req_sod;
- elf_object_t *object;
- char *hint;
+ elf_object_t *object = NULL;
try_any_minor = 0;
ignore_hints = 0;
@@ -263,79 +291,35 @@ _dl_load_shlib(const char *libname, elf_object_t *parent, int type, int flags)
req_sod = sod;
again:
- /*
- * No '/' in name. Scan the known places, LD_LIBRARY_PATH first.
- */
+ /* No '/' in name. Scan the known places, LD_LIBRARY_PATH first. */
if (_dl_libpath != NULL) {
- hint = _dl_find_shlib(&req_sod, _dl_libpath, ignore_hints);
- if (hint != NULL) {
- if (req_sod.sod_minor < sod.sod_minor)
- _dl_printf("warning: lib%s.so.%d.%d: "
- "minor version >= %d expected, "
- "using it anyway\n",
- sod.sod_name, sod.sod_major,
- req_sod.sod_minor, sod.sod_minor);
- object = _dl_tryload_shlib(hint, type, flags);
- if (object != NULL) {
- _dl_free((char *)sod.sod_name);
- return (object);
- }
- }
+ object = _dl_load_shlib_hint(&sod, &req_sod, type, flags,
+ ignore_hints, _dl_libpath);
+ if (object != NULL)
+ goto done;
}
- /*
- * Check DT_RPATH.
- */
+ /* Check DT_RPATH. */
if (parent->dyn.rpath != NULL) {
- hint = _dl_find_shlib(&req_sod, parent->dyn.rpath,
- ignore_hints);
- if (hint != NULL) {
- if (req_sod.sod_minor < sod.sod_minor)
- _dl_printf("warning: lib%s.so.%d.%d: "
- "minor version >= %d expected, "
- "using it anyway\n",
- sod.sod_name, sod.sod_major,
- req_sod.sod_minor, sod.sod_minor);
- object = _dl_tryload_shlib(hint, type, flags);
- if (object != NULL) {
- _dl_free((char *)sod.sod_name);
- return (object);
- }
- }
+ object = _dl_load_shlib_hint(&sod, &req_sod, type, flags,
+ ignore_hints, parent->dyn.rpath);
+ if (object != NULL)
+ goto done;
}
+
+ /* Check main program's DT_RPATH, if parent != main program */
if (parent != _dl_objects && _dl_objects->dyn.rpath != NULL) {
- hint = _dl_find_shlib(&req_sod, _dl_objects->dyn.rpath,
- ignore_hints);
- if (hint != NULL) {
- if (req_sod.sod_minor < sod.sod_minor)
- _dl_printf("warning: lib%s.so.%d.%d: "
- "minor version >= %d expected, "
- "using it anyway\n",
- sod.sod_name, sod.sod_major,
- req_sod.sod_minor, sod.sod_minor);
- object = _dl_tryload_shlib(hint, type, flags);
- if (object != NULL) {
- _dl_free((char *)sod.sod_name);
- return (object);
- }
- }
+ object = _dl_load_shlib_hint(&sod, &req_sod, type, flags,
+ ignore_hints, _dl_objects->dyn.rpath);
+ if (object != NULL)
+ goto done;
}
/* check 'standard' locations */
- hint = _dl_find_shlib(&req_sod, NULL, ignore_hints);
- if (hint != NULL) {
- if (req_sod.sod_minor < sod.sod_minor)
- _dl_printf("warning: lib%s.so.%d.%d: "
- "minor version >= %d expected, "
- "using it anyway\n",
- sod.sod_name, sod.sod_major,
- req_sod.sod_minor, sod.sod_minor);
- object = _dl_tryload_shlib(hint, type, flags);
- if (object != NULL) {
- _dl_free((char *)sod.sod_name);
- return(object);
- }
- }
+ object = _dl_load_shlib_hint(&sod, &req_sod, type, flags,
+ ignore_hints, NULL);
+ if (object != NULL)
+ goto done;
if (try_any_minor == 0) {
try_any_minor = 1;
@@ -343,9 +327,10 @@ again:
req_sod.sod_minor = -1;
goto again;
}
- _dl_free((char *)sod.sod_name);
_dl_errno = DL_NOT_FOUND;
- return(0);
+done:
+ _dl_free((char *)sod.sod_name);
+ return(object);
}