summaryrefslogtreecommitdiff
path: root/libexec/ld.so/ldconfig
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-05-13 16:33:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-05-13 16:33:41 +0000
commit434854ab7618ebead2b645af66407e0ce9e06d58 (patch)
tree06afe950a15c63bc17a21e0a8ce624f0bc6c7571 /libexec/ld.so/ldconfig
parent84074750d095c6c7ad8744b774c9df7a9f472dd4 (diff)
some knf and delinting; ok drahn
Diffstat (limited to 'libexec/ld.so/ldconfig')
-rw-r--r--libexec/ld.so/ldconfig/ldconfig.c38
-rw-r--r--libexec/ld.so/ldconfig/library.c28
-rw-r--r--libexec/ld.so/ldconfig/prebind.c7
-rw-r--r--libexec/ld.so/ldconfig/prebind_delete.c4
-rw-r--r--libexec/ld.so/ldconfig/shlib.c112
5 files changed, 44 insertions, 145 deletions
diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c
index fa1fe87151d..9022349a0dc 100644
--- a/libexec/ld.so/ldconfig/ldconfig.c
+++ b/libexec/ld.so/ldconfig/ldconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldconfig.c,v 1.20 2006/05/12 23:20:52 deraadt Exp $ */
+/* $OpenBSD: ldconfig.c,v 1.21 2006/05/13 16:33:40 deraadt Exp $ */
/*
* Copyright (c) 1993,1995 Paul Kranenburg
@@ -207,7 +207,7 @@ dodir(char *dir, int silent)
}
while ((dp = readdir(dd)) != NULL) {
- int n;
+ size_t n;
char *cp;
/* Check for `lib' prefix */
@@ -317,11 +317,12 @@ hinthash(char *cp, int vmajor, int vminor)
int
buildhints(void)
{
- int strtab_sz = 0, nhints = 0, fd, i, n, ret = -1, str_index = 0;
+ int strtab_sz = 0, nhints = 0, fd, i, ret = -1, str_index = 0;
struct hints_bucket *blist;
struct hints_header hdr;
struct shlib_list *shp;
- char *strtab, *tmpfile;
+ char *strtab, *tmpfilenam;
+ size_t n;
for (shp = shlib_head; shp; shp = shp->next) {
strtab_sz += 1 + strlen(shp->name);
@@ -347,12 +348,12 @@ buildhints(void)
/* Allocate buckets and string table */
blist = (struct hints_bucket *)xmalloc(n);
- bzero((char *)blist, n);
+ bzero(blist, n);
for (i = 0; i < hdr.hh_nbucket; i++)
/* Empty all buckets */
blist[i].hi_next = -1;
- strtab = (char *)xmalloc(strtab_sz);
+ strtab = xmalloc(strtab_sz);
/* Enter all */
for (shp = shlib_head; shp; shp = shp->next) {
@@ -362,20 +363,20 @@ buildhints(void)
hdr.hh_nbucket);
if (bp->hi_pathx) {
- int i;
+ int j;
- for (i = 0; i < hdr.hh_nbucket; i++) {
- if (blist[i].hi_pathx == 0)
+ for (j = 0; j < hdr.hh_nbucket; j++) {
+ if (blist[j].hi_pathx == 0)
break;
}
- if (i == hdr.hh_nbucket) {
+ if (j == hdr.hh_nbucket) {
warnx("Bummer!");
goto out;
}
while (bp->hi_next != -1)
bp = &blist[bp->hi_next];
- bp->hi_next = i;
- bp = blist + i;
+ bp->hi_next = j;
+ bp = blist + j;
}
/* Insert strings in string table */
@@ -397,13 +398,12 @@ buildhints(void)
str_index += 1 + strlen(dir_list);
/* Sanity check */
- if (str_index != strtab_sz) {
+ if (str_index != strtab_sz)
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
- }
- tmpfile = concat(_PATH_LD_HINTS, ".XXXXXXXXXX", "");
- if ((fd = mkstemp(tmpfile)) == -1) {
- warn("%s", tmpfile);
+ tmpfilenam = concat(_PATH_LD_HINTS, ".XXXXXXXXXX", "");
+ if ((fd = mkstemp(tmpfilenam)) == -1) {
+ warn("%s", tmpfilenam);
goto out;
}
fchmod(fd, 0444);
@@ -433,7 +433,7 @@ buildhints(void)
goto out;
}
- if (rename(tmpfile, _PATH_LD_HINTS) != 0) {
+ if (rename(tmpfilenam, _PATH_LD_HINTS) != 0) {
warn("%s", _PATH_LD_HINTS);
goto out;
}
@@ -467,7 +467,7 @@ readhints(void)
return -1;
}
- msize = (long)sb.st_size;
+ msize = (long)sb.st_size;
addr = mmap(0, msize, PROT_READ, MAP_PRIVATE, fd, 0);
if (addr == MAP_FAILED) {
diff --git a/libexec/ld.so/ldconfig/library.c b/libexec/ld.so/ldconfig/library.c
index cc4baa72df9..73745fd50b4 100644
--- a/libexec/ld.so/ldconfig/library.c
+++ b/libexec/ld.so/ldconfig/library.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: library.c,v 1.1 2006/05/12 23:20:52 deraadt Exp $ */
+/* $OpenBSD: library.c,v 1.2 2006/05/13 16:33:40 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
@@ -47,8 +47,7 @@ int
load_lib(const char *name, struct elf_object *parent)
{
struct sod sod, req_sod;
- int ignore_hints;
- int try_any_minor = 0;
+ int ignore_hints, try_any_minor = 0;
struct elf_object *object = NULL;
#if 0
@@ -58,6 +57,7 @@ load_lib(const char *name, struct elf_object *parent)
if(strchr(name, '/')) {
char *lpath, *lname;
+
lpath = strdup(name);
lname = strrchr(lpath, '/');
if (lname == NULL || lname[1] == '\0') {
@@ -74,7 +74,7 @@ load_lib(const char *name, struct elf_object *parent)
fullpathagain:
object = elf_load_shlib_hint(&sod, &req_sod,
ignore_hints, lpath);
- if (object != NULL)
+ if (object != NULL)
goto fullpathdone;
if (try_any_minor == 0) {
@@ -97,7 +97,7 @@ fullpathdone:
again:
if (parent->dyn.rpath != NULL) {
object = elf_load_shlib_hint(&sod, &req_sod,
- ignore_hints, parent->dyn.rpath);
+ ignore_hints, parent->dyn.rpath);
if (object != NULL)
goto done;
}
@@ -107,8 +107,7 @@ again:
if (object != NULL)
goto done;
}
- object = elf_load_shlib_hint(&sod, &req_sod,
- ignore_hints, NULL);
+ object = elf_load_shlib_hint(&sod, &req_sod, ignore_hints, NULL);
if (try_any_minor == 0) {
try_any_minor = 1;
@@ -155,11 +154,11 @@ char *
elf_find_shlib(struct sod *sodp, const char *searchpath, int nohints)
{
char *hint, lp[PATH_MAX + 10], *path;
+ struct sod tsod, bsod; /* transient and best sod */
struct dirent *dp;
const char *pp;
int match, len;
DIR *dd;
- struct sod tsod, bsod; /* transient and best sod */
/* if we are to search default directories, and hints
* are not to be used, search the standard path from ldconfig
@@ -287,9 +286,9 @@ elf_tryload_shlib(const char *libname)
{
struct elf_object *object;
object = elf_lookup_object(libname);
- if (object == NULL) {
+
+ if (object == NULL)
object = load_file(libname, OBJTYPE_LIB);
- }
if (object == NULL)
printf("tryload_shlib %s\n", libname);
return object;
@@ -325,11 +324,10 @@ elf_match_file(struct sod *sodp, char *name, int namelen)
_dl_build_sod(name, &lsod);
match = 0;
- if ((strcmp((char *)lsod.sod_name, (char *)sodp->sod_name) == 0) &&
- (lsod.sod_library == sodp->sod_library) &&
- ((sodp->sod_major == -1) || (sodp->sod_major == lsod.sod_major)) &&
- ((sodp->sod_minor == -1) ||
- (lsod.sod_minor >= sodp->sod_minor))) {
+ if (strcmp((char *)lsod.sod_name, (char *)sodp->sod_name) == 0 &&
+ lsod.sod_library == sodp->sod_library &&
+ (sodp->sod_major == -1 || sodp->sod_major == lsod.sod_major) &&
+ (sodp->sod_minor == -1 || lsod.sod_minor >= sodp->sod_minor)) {
match = 1;
/* return version matched */
diff --git a/libexec/ld.so/ldconfig/prebind.c b/libexec/ld.so/ldconfig/prebind.c
index 3d32a25a8e0..f8064ad0b98 100644
--- a/libexec/ld.so/ldconfig/prebind.c
+++ b/libexec/ld.so/ldconfig/prebind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prebind.c,v 1.2 2006/05/13 05:59:28 deraadt Exp $ */
+/* $OpenBSD: prebind.c,v 1.3 2006/05/13 16:33:40 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
*
@@ -494,6 +494,7 @@ elf_load_object(void *pexe, const char *name)
/* XXX can only occur in programs */
curbin->interp = strdup((char *)((char *)pexe +
phdr[i].p_offset));
+ break;
default:
break;
}
@@ -525,7 +526,7 @@ elf_load_object(void *pexe, const char *name)
dynp++;
}
- needed_list = calloc((needed_cnt + 1), (sizeof (Elf_Word)));
+ needed_list = calloc((needed_cnt + 1), sizeof(Elf_Word));
if (needed_list == NULL) {
printf("unable to allocate needed_list for %s\n", name);
exit(10);
@@ -705,7 +706,7 @@ map_to_virt(Elf_Phdr *phdr, Elf_Ehdr *ehdr, Elf_Addr base, u_long *vaddr)
printf("%lx, base %lx %lx %llx\n", *vaddr, base,
phdr[i].p_vaddr, phdr[i].p_offset );
#endif
-
+ break;
default:
break;
}
diff --git a/libexec/ld.so/ldconfig/prebind_delete.c b/libexec/ld.so/ldconfig/prebind_delete.c
index b5fa6a3cf03..6a1c93316a3 100644
--- a/libexec/ld.so/ldconfig/prebind_delete.c
+++ b/libexec/ld.so/ldconfig/prebind_delete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prebind_delete.c,v 1.3 2006/05/12 23:20:52 deraadt Exp $ */
+/* $OpenBSD: prebind_delete.c,v 1.4 2006/05/13 16:33:40 deraadt Exp $ */
/*
* Copyright (c) 2006 Dale Rahn <drahn@dalerahn.com>
@@ -41,8 +41,6 @@ extern int verbose;
int
prebind_delete(char **argv)
{
- extern char *__progname;
-
while (*argv) {
if (strip_prebind(*argv) == -1)
return (1);
diff --git a/libexec/ld.so/ldconfig/shlib.c b/libexec/ld.so/ldconfig/shlib.c
index 4d765f51d71..def2ac0a7dc 100644
--- a/libexec/ld.so/ldconfig/shlib.c
+++ b/libexec/ld.so/ldconfig/shlib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shlib.c,v 1.8 2003/07/06 20:04:00 deraadt Exp $ */
+/* $OpenBSD: shlib.c,v 1.9 2006/05/13 16:33:40 deraadt Exp $ */
/* $NetBSD: shlib.c,v 1.13 1998/04/04 01:00:29 fvdl Exp $ */
/*
@@ -70,7 +70,8 @@ char *standard_search_dirs[] = {
void
add_search_dir(char *name)
{
- int i, len;
+ size_t len;
+ int i;
len = strlen(name);
@@ -82,8 +83,8 @@ add_search_dir(char *name)
!strncmp(search_dirs[i], name, len))
return;
n_search_dirs++;
- search_dirs = (char **)
- xrealloc(search_dirs, n_search_dirs * sizeof search_dirs[0]);
+ search_dirs = (char **)xrealloc(search_dirs,
+ n_search_dirs * sizeof search_dirs[0]);
search_dirs[n_search_dirs - 1] = xmalloc(++len);
(void)strlcpy(search_dirs[n_search_dirs - 1], name, len);
}
@@ -91,7 +92,8 @@ add_search_dir(char *name)
void
remove_search_dir(char *name)
{
- int i, len;
+ size_t len;
+ int i;
len = strlen(name);
@@ -128,21 +130,6 @@ add_search_path(char *path)
free(dup);
}
-static void
-remove_search_path(char *path)
-{
- char *cp, *dup;
-
- if (path == NULL)
- return;
-
- /* Remove search directories from `path' */
- path = dup = strdup(path);
- while ((cp = strsep(&path, ":")) != NULL)
- remove_search_dir(cp);
- free(dup);
-}
-
void
std_search_path(void)
{
@@ -208,88 +195,3 @@ cmpndewey(int d1[], int n1, int d2[], int n2)
errx(1, "cmpndewey: cant happen");
return 0;
}
-
-/*
- * Search directories for a shared library matching the given
- * major and minor version numbers.
- *
- * MAJOR == -1 && MINOR == -1 --> find highest version
- * MAJOR != -1 && MINOR == -1 --> find highest minor version
- * MAJOR == -1 && MINOR != -1 --> invalid
- * MAJOR != -1 && MINOR != -1 --> find highest micro version
- */
-
-/* Not interested in devices right now... */
-#undef major
-#undef minor
-
-static char *
-findshlib(char *name, int *majorp, int *minorp, int do_dot_a)
-{
- int major = *majorp, minor = *minorp, ndewey, i, len;
- int dewey[MAXDEWEY], tmp[MAXDEWEY];
- char *lname;
-
- len = strlen(name) + sizeof("lib");
- lname = (char *)alloca(len);
- snprintf(lname, len, "lib%s", name);
-
- ndewey = 0;
-
- for (i = 0; i < n_search_dirs; i++) {
- struct dirent *dp;
- char *path = NULL;
- DIR *dd;
-
- dd = opendir(search_dirs[i]);
- if (dd == NULL)
- continue;
-
- while ((dp = readdir(dd)) != NULL) {
- int n;
-
- if (do_dot_a && path == NULL &&
- dp->d_namlen == len + 2 &&
- strncmp(dp->d_name, lname, len) == 0 &&
- (dp->d_name+len)[0] == '.' &&
- (dp->d_name+len)[1] == 'a')
- path = concat(search_dirs[i], "/", dp->d_name);
-
- if (dp->d_namlen < len + 4)
- continue;
- if (strncmp(dp->d_name, lname, len) != 0)
- continue;
- if (strncmp(dp->d_name+len, ".so.", 4) != 0)
- continue;
-
- if ((n = getdewey(tmp, dp->d_name+len+4)) == 0)
- continue;
-
- /* skip inappropriate versions. */
- if (major != -1) {
- if (tmp[0] != major)
- continue;
- if (n != 1 && minor != -1 && tmp[1] < minor)
- continue;
- }
-
- if (cmpndewey(tmp, n, dewey, ndewey) <= 0)
- continue;
-
- /* We have a better version */
- if (path)
- free(path);
- path = concat(search_dirs[i], "/", dp->d_name);
- bcopy(tmp, dewey, sizeof(dewey));
- ndewey = n;
- *majorp = dewey[0];
- *minorp = dewey[1];
- }
- closedir(dd);
-
- /* There's a lib in this dir; take it. */
- if (path != NULL)
- return path;
- }
- return NULL;
-}