diff options
author | Oleg Safiullin <form@cvs.openbsd.org> | 2000-06-28 15:32:41 +0000 |
---|---|---|
committer | Oleg Safiullin <form@cvs.openbsd.org> | 2000-06-28 15:32:41 +0000 |
commit | 363d7922c0a5ab61e3d447ef6e5d55a8d5e33987 (patch) | |
tree | 88bb0b2245d0b34f449a24dadb7abecea19a04cd /gnu | |
parent | 82ef3b7354ffc221ce5f60aa73d4b4a5a8be8d46 (diff) |
Improve remove_search_dir(), avoid memory leak.
Add support for -U option:
Unconfigure directories specified on the command line or remove
inaccessible directories from search path if no directories spec-
ified. This option cannot be used with -m.
- this option helps to correctly pkg_delete packages like postgresql,
mysql (with shared libs in package's own directory).
ok espie@
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/ld/ldconfig/ldconfig.8 | 21 | ||||
-rw-r--r-- | gnu/usr.bin/ld/ldconfig/ldconfig.c | 34 | ||||
-rw-r--r-- | gnu/usr.bin/ld/shlib.c | 25 |
3 files changed, 59 insertions, 21 deletions
diff --git a/gnu/usr.bin/ld/ldconfig/ldconfig.8 b/gnu/usr.bin/ld/ldconfig/ldconfig.8 index 7e257efc18d..a832f4bafbb 100644 --- a/gnu/usr.bin/ld/ldconfig/ldconfig.8 +++ b/gnu/usr.bin/ld/ldconfig/ldconfig.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ldconfig.8,v 1.4 2000/01/27 22:14:57 form Exp $ +.\" $OpenBSD: ldconfig.8,v 1.5 2000/06/28 15:32:40 form Exp $ .\" .\" Copyright (c) 1993,1995 Paul Kranenburg .\" All rights reserved. @@ -37,7 +37,7 @@ .Nd configure the shared library cache .Sh SYNOPSIS .Nm ldconfig -.Op Fl Rmrsv +.Op Fl RUmrsv .Op Ar directory Ar ... .Sh DESCRIPTION .Nm @@ -46,7 +46,7 @@ is used to prepare a set of for use by the run-time linker .Xr ld.so to facilitate quick lookup of shared libraries available in multiple -directories. It scans a set of built-in system directories and any +directories. It scans a set of built-in system directories and any .Ar directories specified on the command line (in the given order) looking for shared libraries and stores the results in the file @@ -83,14 +83,21 @@ The following options are recognized by .Nm ldconfig: .Bl -tag -width indent .It Fl R -Rescan the previously configured directories. This opens the hints file -and fetches the directory list from the header. Any additional pathnames +Rescan the previously configured directories. This opens the hints file +and fetches the directory list from the header. Any additional pathnames on the command line are also processed. +.It Fl U +Unconfigure directories specified on the command line or remove inaccessible +directories from search path if no directories specified. This option cannot +be used with +.Fl m . .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. +the existing hints file. The default action is to build the hints file +afresh. This option cannot be used with +.Fl U . .It Fl r -Lists the current contents of +List the current contents of .Xr ld.so.hints on the standard output. The hints file will not be modified. .It Fl s diff --git a/gnu/usr.bin/ld/ldconfig/ldconfig.c b/gnu/usr.bin/ld/ldconfig/ldconfig.c index 1d2e192b636..8887f06fb9f 100644 --- a/gnu/usr.bin/ld/ldconfig/ldconfig.c +++ b/gnu/usr.bin/ld/ldconfig/ldconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ldconfig.c,v 1.8 2000/04/30 15:14:34 form Exp $ */ +/* $OpenBSD: ldconfig.c,v 1.9 2000/06/28 15:32:40 form Exp $ */ /* * Copyright (c) 1993,1995 Paul Kranenburg @@ -63,6 +63,7 @@ static int nostd; static int justread; static int merge; static int rescan; +static int unconfig; struct shlib_list { /* Internal list of shared libraries found */ @@ -92,11 +93,14 @@ char *argv[]; int i, c; int rval = 0; - while ((c = getopt(argc, argv, "Rmrsv")) != EOF) { + while ((c = getopt(argc, argv, "RUmrsv")) != EOF) { switch (c) { case 'R': rescan = 1; break; + case 'U': + rescan = unconfig = 1; + break; case 'm': merge = 1; break; @@ -110,12 +114,16 @@ char *argv[]; verbose = 1; break; default: - errx(1, "Usage: %s [-Rmrsv] [dir ...]", - __progname); + (void)fprintf(stderr, + "usage: %s [-RUmrsv] [dir ...]\n", __progname); + exit(1); break; } } + if (unconfig && merge) + errx(1, "cannot use -U with -m"); + dir_list = xmalloc(1); *dir_list = '\0'; @@ -133,8 +141,22 @@ char *argv[]; if (!nostd) std_search_path(); - for (i = optind; i < argc; i++) - add_search_dir(argv[i]); + if (unconfig) { + if (optind < argc) + for (i = optind; i < argc; i++) + remove_search_dir(argv[i]); + else { + i = 0; + while (i < n_search_dirs) { + if (access(search_dirs[i], R_OK) < 0) + remove_search_dir(search_dirs[i]); + else + i++; + } + } + } else + for (i = optind; i < argc; i++) + add_search_dir(argv[i]); for (i = 0; i < n_search_dirs; i++) { char *cp = concat(dir_list, *dir_list?":":"", search_dirs[i]); diff --git a/gnu/usr.bin/ld/shlib.c b/gnu/usr.bin/ld/shlib.c index 9c564e631d7..be5105d0395 100644 --- a/gnu/usr.bin/ld/shlib.c +++ b/gnu/usr.bin/ld/shlib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: shlib.c,v 1.9 2000/04/24 03:33:27 form Exp $ */ +/* $OpenBSD: shlib.c,v 1.10 2000/06/28 15:32:40 form Exp $ */ /* $NetBSD: shlib.c,v 1.13 1998/04/04 01:00:29 fvdl Exp $ */ /* @@ -99,16 +99,25 @@ void remove_search_dir(name) char *name; { - int n; + int i, len; - for (n = 0; n < n_search_dirs; n++) { - if (strcmp(search_dirs[n], name)) + len = strlen(name); + + while (len > 1 && name[len - 1] == '/') + --len; + + for (i = 0; i < n_search_dirs; i++) { + if (strlen(search_dirs[i]) != len || + strncmp(search_dirs[i], name, len)) continue; - free(search_dirs[n]); - if (n < (n_search_dirs - 1)) - bcopy(&search_dirs[n+1], &search_dirs[n], - (n_search_dirs - n - 1) * sizeof search_dirs[0]); + free(search_dirs[i]); + if (i < (n_search_dirs - 1)) + bcopy(&search_dirs[i+1], &search_dirs[i], + (n_search_dirs - i - 1) * sizeof search_dirs[0]); n_search_dirs--; + search_dirs = (char **)xrealloc(search_dirs, + n_search_dirs * sizeof search_dirs[0]); + break; } } |