diff options
| author | pk <pk@NetBSD.org> | 1995-06-20 23:12:33 +0000 |
|---|---|---|
| committer | pk <pk@NetBSD.org> | 1995-06-20 23:12:33 +0000 |
| commit | d8f640e15a63e3fb43864bbfe3735f1f9b8eb970 (patch) | |
| tree | 2a6372d7874b6bd49fb7cbf9a8c8193ad3b41d0c /gnu | |
| parent | 45359beaf47a30c84b3c1ff6e6ddb0ff455c3344 (diff) | |
Add a `merge' option.
Use err() & warn().
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/usr.bin/ld/ldconfig/ldconfig.8 | 11 | ||||
| -rw-r--r-- | gnu/usr.bin/ld/ldconfig/ldconfig.c | 109 |
2 files changed, 75 insertions, 45 deletions
diff --git a/gnu/usr.bin/ld/ldconfig/ldconfig.8 b/gnu/usr.bin/ld/ldconfig/ldconfig.8 index a2ffabefcde..08d830fffcc 100644 --- a/gnu/usr.bin/ld/ldconfig/ldconfig.8 +++ b/gnu/usr.bin/ld/ldconfig/ldconfig.8 @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 1993 Paul Kranenburg +.\" Copyright (c) 1993,1995 Paul Kranenburg .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $Id: ldconfig.8,v 1.3 1994/06/24 13:34:04 pk Exp $ +.\" $Id: ldconfig.8,v 1.4 1995/06/20 23:12:33 pk Exp $ .\" .Dd October 3, 1993 .Dt LDCONFIG 8 @@ -37,7 +37,7 @@ .Nd configure the shared library cache .Sh SYNOPSIS .Nm ldconfig -.Op Fl rsv +.Op Fl mrsv .Op Ar directory Ar ... .Sh DESCRIPTION .Nm @@ -79,9 +79,12 @@ switch of .Nm Ldconfig is typically run as part of the boot sequence. .Pp -The following options recognized by +The following options are recognized by .Nm ldconfig: .Bl -tag -width indent +.It Fl m +Merge the result of the scan of the directories given as arguments into +the existing hints file. The default action is to build the hints file afresh. .It Fl r Lists the current contents of .Xr ld.so.hints diff --git a/gnu/usr.bin/ld/ldconfig/ldconfig.c b/gnu/usr.bin/ld/ldconfig/ldconfig.c index a62d4bc5763..d91d523c09e 100644 --- a/gnu/usr.bin/ld/ldconfig/ldconfig.c +++ b/gnu/usr.bin/ld/ldconfig/ldconfig.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993 Paul Kranenburg + * Copyright (c) 1993,1995 Paul Kranenburg * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ldconfig.c,v 1.8 1994/06/16 13:38:32 pk Exp $ + * $Id: ldconfig.c,v 1.9 1995/06/20 23:12:35 pk Exp $ */ #include <sys/param.h> @@ -59,6 +59,7 @@ extern char *__progname; static int verbose; static int nostd; static int justread; +static int merge; struct shlib_list { /* Internal list of shared libraries found */ @@ -75,8 +76,9 @@ static struct shlib_list *shlib_head = NULL, **shlib_tail = &shlib_head; static void enter __P((char *, char *, char *, int *, int)); static int dodir __P((char *, int)); -static int build_hints __P((void)); -static int listhints __P((void)); +static int buildhints __P((void)); +static int readhints __P((void)); +static void listhints __P((void)); int main(argc, argv) @@ -86,29 +88,37 @@ char *argv[]; int i, c; int rval = 0; - while ((c = getopt(argc, argv, "rsv")) != EOF) { + while ((c = getopt(argc, argv, "mrsv")) != EOF) { switch (c) { - case 'v': - verbose = 1; + case 'm': + merge = 1; + break; + case 'r': + justread = 1; break; case 's': nostd = 1; break; - case 'r': - justread = 1; + case 'v': + verbose = 1; break; default: - fprintf(stderr, "Usage: %s [-r][-s][-v][dir ...]\n", + errx(1, "Usage: %s [-r][-s][-v][dir ...]", __progname); - exit(1); break; } } - if (justread) - return listhints(); + if (justread || merge) { + if ((rval = readhints()) != 0) + return rval; + if (justread) { + listhints(); + return; + } + } - if (!nostd) + if (!nostd && !merge) std_search_path(); for (i = 0; i < n_search_dirs; i++) @@ -117,7 +127,7 @@ char *argv[]; for (i = optind; i < argc; i++) rval |= dodir(argv[i], 0); - rval |= build_hints(); + rval |= buildhints(); return rval; } @@ -134,7 +144,7 @@ int silent; if ((dd = opendir(dir)) == NULL) { if (!silent || errno != ENOENT) - perror(dir); + warn("%s", dir); return -1; } @@ -229,7 +239,7 @@ int vmajor, vminor; } int -build_hints() +buildhints() { struct hints_header hdr; struct hints_bucket *blist; @@ -285,7 +295,7 @@ build_hints() break; } if (i == hdr.hh_nbucket) { - fprintf(stderr, "Bummer!\n"); + warnx("Bummer!"); return -1; } while (bp->hi_next != -1) @@ -310,37 +320,37 @@ build_hints() tmpfile = concat(_PATH_LD_HINTS, "+", ""); if ((fd = open(tmpfile, O_RDWR|O_CREAT|O_TRUNC, 0444)) == -1) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } if (write(fd, &hdr, sizeof(struct hints_header)) != sizeof(struct hints_header)) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != hdr.hh_nbucket * sizeof(struct hints_bucket)) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } if (write(fd, strtab, strtab_sz) != strtab_sz) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } if (close(fd) != 0) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } /* Install it */ if (unlink(_PATH_LD_HINTS) != 0 && errno != ENOENT) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } if (rename(tmpfile, _PATH_LD_HINTS) != 0) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } @@ -348,7 +358,7 @@ build_hints() } static int -listhints() +readhints() { int fd; caddr_t addr; @@ -356,10 +366,11 @@ listhints() struct hints_header *hdr; struct hints_bucket *blist; char *strtab; + struct shlib_list *shp; int i; if ((fd = open(_PATH_LD_HINTS, O_RDONLY, 0)) == -1) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } @@ -367,19 +378,19 @@ listhints() addr = mmap(0, msize, PROT_READ, MAP_COPY, fd, 0); if (addr == (caddr_t)-1) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } hdr = (struct hints_header *)addr; if (HH_BADMAG(*hdr)) { - fprintf(stderr, "%s: Bad magic: %o\n", + warnx("%s: Bad magic: %o", _PATH_LD_HINTS, hdr->hh_magic); return -1; } if (hdr->hh_version != LD_HINTS_VERSION_1) { - fprintf(stderr, "Unsupported version: %d\n", hdr->hh_version); + warnx("Unsupported version: %d", hdr->hh_version); return -1; } @@ -388,7 +399,7 @@ listhints() PROT_READ, MAP_COPY|MAP_FIXED, fd, msize) != (caddr_t)(addr+msize)) { - perror(_PATH_LD_HINTS); + warn("%s", _PATH_LD_HINTS); return -1; } } @@ -397,29 +408,45 @@ listhints() blist = (struct hints_bucket *)(addr + hdr->hh_hashtab); strtab = (char *)(addr + hdr->hh_strtab); - printf("%s:\n", _PATH_LD_HINTS); for (i = 0; i < hdr->hh_nbucket; i++) { struct hints_bucket *bp = &blist[i]; /* Sanity check */ if (bp->hi_namex >= hdr->hh_strtab_sz) { - fprintf(stderr, "Bad name index: %#x\n", bp->hi_namex); + warnx("Bad name index: %#x", bp->hi_namex); return -1; } if (bp->hi_pathx >= hdr->hh_strtab_sz) { - fprintf(stderr, "Bad path index: %#x\n", bp->hi_pathx); + warnx("Bad path index: %#x", bp->hi_pathx); return -1; } - printf("\t%d:-l%s.%d.%d => %s (%d -> %d)\n", - i, - strtab + bp->hi_namex, bp->hi_major, bp->hi_minor, - strtab + bp->hi_pathx, - hinthash(strtab+bp->hi_namex, bp->hi_major, bp->hi_minor) - % hdr->hh_nbucket, - bp->hi_next); + /* Allocate new list element */ + shp = (struct shlib_list *)xmalloc(sizeof *shp); + shp->name = strdup(strtab + bp->hi_namex); + shp->path = strdup(strtab + bp->hi_pathx); + bcopy(bp->hi_dewey, shp->dewey, sizeof(shp->dewey)); + shp->ndewey = bp->hi_ndewey; + shp->next = NULL; + + *shlib_tail = shp; + shlib_tail = &shp->next; } return 0; } +static void +listhints() +{ + struct shlib_list *shp; + int i; + + printf("%s:\n", _PATH_LD_HINTS); + + for (i = 0, shp = shlib_head; shp; i++, shp = shp->next) + printf("\t%d:-l%s.%d.%d => %s\n", + i, shp->name, shp->major, shp->minor, shp->path); + + return; +} |
