Updates to deal with ld.so.hints version 2. It now deals with the

ldconfig path (from NetBSD).  I added code to make sure there were no
duplicates in the path when multiple ldconfig -m's were used.

Reviewed by: nate, jdp
Obtained from: NetBSD (partly)
This commit is contained in:
peter 1996-10-01 01:31:51 +00:00
parent 180a0b4f4a
commit 23b0588846
4 changed files with 106 additions and 36 deletions

View File

@ -1,7 +1,7 @@
# $Id: Makefile,v 1.6 1994/02/13 20:42:18 jkh Exp $ # $Id: Makefile,v 1.7 1994/04/13 20:49:42 ats Exp $
PROG= ldconfig PROG= ldconfig
SRCS= ldconfig.c shlib.c etc.c SRCS= ldconfig.c shlib.c support.c
LDDIR?= $(.CURDIR)/.. LDDIR?= $(.CURDIR)/..
CFLAGS+=-I$(LDDIR) -I$(.CURDIR) -I$(LDDIR)/$(MACHINE) CFLAGS+=-I$(LDDIR) -I$(.CURDIR) -I$(LDDIR)/$(MACHINE)
LDFLAGS+=-static LDFLAGS+=-static

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: ldconfig.c,v 1.12 1996/02/26 02:22:33 pst Exp $ * $Id: ldconfig.c,v 1.13 1996/07/12 19:08:34 jkh Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -51,7 +51,12 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "ld.h" #include <machine/param.h>
#include <link.h>
#include "shlib.h"
#include "support.h"
#undef major #undef major
#undef minor #undef minor
@ -75,6 +80,7 @@ struct shlib_list {
}; };
static struct shlib_list *shlib_head = NULL, **shlib_tail = &shlib_head; static struct shlib_list *shlib_head = NULL, **shlib_tail = &shlib_head;
static char *dir_list;
static void enter __P((char *, char *, char *, int *, int)); static void enter __P((char *, char *, char *, int *, int));
static int dodir __P((char *, int)); static int dodir __P((char *, int));
@ -105,30 +111,39 @@ char *argv[];
verbose = 1; verbose = 1;
break; break;
default: default:
errx(1, "Usage: %s [-m][-r][-s][-v][dir ...]", errx(1, "Usage: %s [-mrsv] [dir ...]",
__progname); __progname);
break; break;
} }
} }
dir_list = strdup("");
if (justread || merge) { if (justread || merge) {
if ((rval = readhints()) != 0) if ((rval = readhints()) != 0)
return rval; return rval;
if (justread) {
listhints();
return 0;
}
} }
if (!nostd) if (!nostd && !merge)
std_search_path(); std_search_path();
for (i = optind; i < argc; i++)
add_search_path(argv[i]);
for (i = 0; i < n_search_dirs; i++) {
char *cp = concat(dir_list, *dir_list?":":"", search_dirs[i]);
free(dir_list);
dir_list = cp;
}
if (justread) {
listhints();
return 0;
}
for (i = 0; i < n_search_dirs; i++) for (i = 0; i < n_search_dirs; i++)
rval |= dodir(search_dirs[i], 1); rval |= dodir(search_dirs[i], 1);
for (i = optind; i < argc; i++)
rval |= dodir(argv[i], 0);
rval |= buildhints(); rval |= buildhints();
return rval; return rval;
@ -281,11 +296,13 @@ buildhints()
/* Fill hints file header */ /* Fill hints file header */
hdr.hh_magic = HH_MAGIC; hdr.hh_magic = HH_MAGIC;
hdr.hh_version = LD_HINTS_VERSION_1; hdr.hh_version = LD_HINTS_VERSION_2;
hdr.hh_nbucket = 1 * nhints; hdr.hh_nbucket = 1 * nhints;
n = hdr.hh_nbucket * sizeof(struct hints_bucket); n = hdr.hh_nbucket * sizeof(struct hints_bucket);
hdr.hh_hashtab = sizeof(struct hints_header); hdr.hh_hashtab = sizeof(struct hints_header);
hdr.hh_strtab = hdr.hh_hashtab + n; hdr.hh_strtab = hdr.hh_hashtab + n;
hdr.hh_dirlist = strtab_sz;
strtab_sz += 1 + strlen(dir_list);
hdr.hh_strtab_sz = strtab_sz; hdr.hh_strtab_sz = strtab_sz;
hdr.hh_ehints = hdr.hh_strtab + hdr.hh_strtab_sz; hdr.hh_ehints = hdr.hh_strtab + hdr.hh_strtab_sz;
@ -340,8 +357,22 @@ buildhints()
bp->hi_ndewey = shp->ndewey; bp->hi_ndewey = shp->ndewey;
} }
umask(022); /* ensure the file will be worl-readable */ /* Copy search directories */
tmpfile = concat(_PATH_LD_HINTS, "+", ""); strcpy(strtab + str_index, dir_list);
str_index += 1 + strlen(dir_list);
/* Sanity check */
if (str_index != strtab_sz) {
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
}
tmpfile = concat(_PATH_LD_HINTS, ".XXXXXX", "");
if ((tmpfile = mktemp(tmpfile)) == NULL) {
warn("%s", tmpfile);
return -1;
}
umask(0); /* Create with exact permissions */
if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC, 0444)) == -1) { if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC, 0444)) == -1) {
warn("%s", _PATH_LD_HINTS); warn("%s", _PATH_LD_HINTS);
return -1; return -1;
@ -397,7 +428,7 @@ readhints()
return -1; return -1;
} }
msize = PAGSIZ; msize = PAGE_SIZE;
addr = mmap(0, msize, PROT_READ, MAP_COPY, fd, 0); addr = mmap(0, msize, PROT_READ, MAP_COPY, fd, 0);
if (addr == (caddr_t)-1) { if (addr == (caddr_t)-1) {
@ -412,7 +443,8 @@ readhints()
return -1; return -1;
} }
if (hdr->hh_version != LD_HINTS_VERSION_1) { if (hdr->hh_version != LD_HINTS_VERSION_1 &&
hdr->hh_version != LD_HINTS_VERSION_2) {
warnx("Unsupported version: %d", hdr->hh_version); warnx("Unsupported version: %d", hdr->hh_version);
return -1; return -1;
} }
@ -455,6 +487,8 @@ readhints()
*shlib_tail = shp; *shlib_tail = shp;
shlib_tail = &shp->next; shlib_tail = &shp->next;
} }
if (hdr->hh_version >= LD_HINTS_VERSION_2)
add_search_path(strtab + hdr->hh_dirlist);
return 0; return 0;
} }
@ -466,6 +500,7 @@ listhints()
int i; int i;
printf("%s:\n", _PATH_LD_HINTS); printf("%s:\n", _PATH_LD_HINTS);
printf("\tsearch directories: %s\n", dir_list);
for (i = 0, shp = shlib_head; shp; i++, shp = shp->next) for (i = 0, shp = shlib_head; shp; i++, shp = shp->next)
printf("\t%d:-l%s.%d.%d => %s\n", printf("\t%d:-l%s.%d.%d => %s\n",

View File

@ -1,7 +1,7 @@
# $Id: Makefile,v 1.6 1994/02/13 20:42:18 jkh Exp $ # $Id: Makefile,v 1.7 1994/04/13 20:49:42 ats Exp $
PROG= ldconfig PROG= ldconfig
SRCS= ldconfig.c shlib.c etc.c SRCS= ldconfig.c shlib.c support.c
LDDIR?= $(.CURDIR)/.. LDDIR?= $(.CURDIR)/..
CFLAGS+=-I$(LDDIR) -I$(.CURDIR) -I$(LDDIR)/$(MACHINE) CFLAGS+=-I$(LDDIR) -I$(.CURDIR) -I$(LDDIR)/$(MACHINE)
LDFLAGS+=-static LDFLAGS+=-static

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: ldconfig.c,v 1.12 1996/02/26 02:22:33 pst Exp $ * $Id: ldconfig.c,v 1.13 1996/07/12 19:08:34 jkh Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -51,7 +51,12 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "ld.h" #include <machine/param.h>
#include <link.h>
#include "shlib.h"
#include "support.h"
#undef major #undef major
#undef minor #undef minor
@ -75,6 +80,7 @@ struct shlib_list {
}; };
static struct shlib_list *shlib_head = NULL, **shlib_tail = &shlib_head; static struct shlib_list *shlib_head = NULL, **shlib_tail = &shlib_head;
static char *dir_list;
static void enter __P((char *, char *, char *, int *, int)); static void enter __P((char *, char *, char *, int *, int));
static int dodir __P((char *, int)); static int dodir __P((char *, int));
@ -105,30 +111,39 @@ char *argv[];
verbose = 1; verbose = 1;
break; break;
default: default:
errx(1, "Usage: %s [-m][-r][-s][-v][dir ...]", errx(1, "Usage: %s [-mrsv] [dir ...]",
__progname); __progname);
break; break;
} }
} }
dir_list = strdup("");
if (justread || merge) { if (justread || merge) {
if ((rval = readhints()) != 0) if ((rval = readhints()) != 0)
return rval; return rval;
if (justread) {
listhints();
return 0;
}
} }
if (!nostd) if (!nostd && !merge)
std_search_path(); std_search_path();
for (i = optind; i < argc; i++)
add_search_path(argv[i]);
for (i = 0; i < n_search_dirs; i++) {
char *cp = concat(dir_list, *dir_list?":":"", search_dirs[i]);
free(dir_list);
dir_list = cp;
}
if (justread) {
listhints();
return 0;
}
for (i = 0; i < n_search_dirs; i++) for (i = 0; i < n_search_dirs; i++)
rval |= dodir(search_dirs[i], 1); rval |= dodir(search_dirs[i], 1);
for (i = optind; i < argc; i++)
rval |= dodir(argv[i], 0);
rval |= buildhints(); rval |= buildhints();
return rval; return rval;
@ -281,11 +296,13 @@ buildhints()
/* Fill hints file header */ /* Fill hints file header */
hdr.hh_magic = HH_MAGIC; hdr.hh_magic = HH_MAGIC;
hdr.hh_version = LD_HINTS_VERSION_1; hdr.hh_version = LD_HINTS_VERSION_2;
hdr.hh_nbucket = 1 * nhints; hdr.hh_nbucket = 1 * nhints;
n = hdr.hh_nbucket * sizeof(struct hints_bucket); n = hdr.hh_nbucket * sizeof(struct hints_bucket);
hdr.hh_hashtab = sizeof(struct hints_header); hdr.hh_hashtab = sizeof(struct hints_header);
hdr.hh_strtab = hdr.hh_hashtab + n; hdr.hh_strtab = hdr.hh_hashtab + n;
hdr.hh_dirlist = strtab_sz;
strtab_sz += 1 + strlen(dir_list);
hdr.hh_strtab_sz = strtab_sz; hdr.hh_strtab_sz = strtab_sz;
hdr.hh_ehints = hdr.hh_strtab + hdr.hh_strtab_sz; hdr.hh_ehints = hdr.hh_strtab + hdr.hh_strtab_sz;
@ -340,8 +357,22 @@ buildhints()
bp->hi_ndewey = shp->ndewey; bp->hi_ndewey = shp->ndewey;
} }
umask(022); /* ensure the file will be worl-readable */ /* Copy search directories */
tmpfile = concat(_PATH_LD_HINTS, "+", ""); strcpy(strtab + str_index, dir_list);
str_index += 1 + strlen(dir_list);
/* Sanity check */
if (str_index != strtab_sz) {
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
}
tmpfile = concat(_PATH_LD_HINTS, ".XXXXXX", "");
if ((tmpfile = mktemp(tmpfile)) == NULL) {
warn("%s", tmpfile);
return -1;
}
umask(0); /* Create with exact permissions */
if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC, 0444)) == -1) { if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC, 0444)) == -1) {
warn("%s", _PATH_LD_HINTS); warn("%s", _PATH_LD_HINTS);
return -1; return -1;
@ -397,7 +428,7 @@ readhints()
return -1; return -1;
} }
msize = PAGSIZ; msize = PAGE_SIZE;
addr = mmap(0, msize, PROT_READ, MAP_COPY, fd, 0); addr = mmap(0, msize, PROT_READ, MAP_COPY, fd, 0);
if (addr == (caddr_t)-1) { if (addr == (caddr_t)-1) {
@ -412,7 +443,8 @@ readhints()
return -1; return -1;
} }
if (hdr->hh_version != LD_HINTS_VERSION_1) { if (hdr->hh_version != LD_HINTS_VERSION_1 &&
hdr->hh_version != LD_HINTS_VERSION_2) {
warnx("Unsupported version: %d", hdr->hh_version); warnx("Unsupported version: %d", hdr->hh_version);
return -1; return -1;
} }
@ -455,6 +487,8 @@ readhints()
*shlib_tail = shp; *shlib_tail = shp;
shlib_tail = &shp->next; shlib_tail = &shp->next;
} }
if (hdr->hh_version >= LD_HINTS_VERSION_2)
add_search_path(strtab + hdr->hh_dirlist);
return 0; return 0;
} }
@ -466,6 +500,7 @@ listhints()
int i; int i;
printf("%s:\n", _PATH_LD_HINTS); printf("%s:\n", _PATH_LD_HINTS);
printf("\tsearch directories: %s\n", dir_list);
for (i = 0, shp = shlib_head; shp; i++, shp = shp->next) for (i = 0, shp = shlib_head; shp; i++, shp = shp->next)
printf("\t%d:-l%s.%d.%d => %s\n", printf("\t%d:-l%s.%d.%d => %s\n",