Add a new option "-f hints_file" to specify an alternate file instead of

"/var/run/ld.so.hints".

Delete an incorrect statement about LD_LIBRARY_PATH from the manual
page.
This commit is contained in:
John Polstra 1996-10-10 23:14:23 +00:00
parent 932b06fca5
commit 7c6da7dcef
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18859
4 changed files with 74 additions and 74 deletions

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.8,v 1.7 1995/06/24 10:08:43 asami Exp $ .\" $Id: ldconfig.8,v 1.8 1996/04/08 04:17:33 mpp Exp $
.\" .\"
.Dd October 3, 1993 .Dd October 3, 1993
.Dt LDCONFIG 8 .Dt LDCONFIG 8
@ -38,6 +38,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm ldconfig .Nm ldconfig
.Op Fl mrsv .Op Fl mrsv
.Op Fl f Ar hints_file
.Op Ar directory Ar ... .Op Ar directory Ar ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -82,15 +83,17 @@ is typically run as part of the boot sequence.
The following options recognized by The following options recognized by
.Nm ldconfig: .Nm ldconfig:
.Bl -tag -width indent .Bl -tag -width indent
.It Fl f Ar hints_file
Read and/or update the specified hints file, instead of
.Pa /var/run/ld.so.hints .
This option is provided primarily for testing.
.It Fl m .It Fl m
Instead of replacing the contents of Instead of replacing the contents of the hints file
.Pa ld.so.hints
with those found in the directories specified, with those found in the directories specified,
.Dq merge .Dq merge
in new entries. in new entries.
.It Fl r .It Fl r
Lists the current contents of Lists the current contents of the hints file
.Pa ld.so.hints
on the standard output. The hints file will not be modified. on the standard output. The hints file will not be modified.
.It Fl s .It Fl s
Do not scan the built-in system directory Do not scan the built-in system directory
@ -104,8 +107,7 @@ space of
.Ev set-user-Id .Ev set-user-Id
programs. Whenever such a program is run, programs. Whenever such a program is run,
.Nm ld.so .Nm ld.so
will only load shared libraries from the will only load shared libraries from the hints
.Pa ld.so.hints
file. In particular, the file. In particular, the
.Ev LD_LIBRARY_PATH .Ev LD_LIBRARY_PATH
is not used to search for libraries. Thus, the role of ldconfig is dual. In is not used to search for libraries. Thus, the role of ldconfig is dual. In
@ -114,11 +116,6 @@ specify the trusted collection of directories from which shared objects can
be safely loaded. It is presumed that the set of directories specified to be safely loaded. It is presumed that the set of directories specified to
.Nm ldconfig .Nm ldconfig
are under control of the system's administrator. are under control of the system's administrator.
.Nm ld.so
further assists set-user-Id programs by erasing the
.Ev LD_LIBRARY_PATH
from the environment.
.Sh FILES .Sh FILES
.Pa /var/run/ld.so.hints .Pa /var/run/ld.so.hints
.Sh SEE ALSO .Sh SEE ALSO

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.13 1996/07/12 19:08:34 jkh Exp $ * $Id: ldconfig.c,v 1.14 1996/10/01 01:31:51 peter Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -57,6 +57,11 @@
#include "shlib.h" #include "shlib.h"
#include "support.h" #include "support.h"
#if DEBUG
/* test */
#undef _PATH_LD_HINTS
#define _PATH_LD_HINTS "./ld.so.hints"
#endif
#undef major #undef major
#undef minor #undef minor
@ -67,6 +72,7 @@ static int verbose;
static int nostd; static int nostd;
static int justread; static int justread;
static int merge; static int merge;
static char *hints_file = _PATH_LD_HINTS;
struct shlib_list { struct shlib_list {
/* Internal list of shared libraries found */ /* Internal list of shared libraries found */
@ -96,8 +102,11 @@ char *argv[];
int i, c; int i, c;
int rval = 0; int rval = 0;
while ((c = getopt(argc, argv, "mrsv")) != EOF) { while ((c = getopt(argc, argv, "f:mrsv")) != EOF) {
switch (c) { switch (c) {
case 'f':
hints_file = optarg;
break;
case 'm': case 'm':
merge = 1; merge = 1;
break; break;
@ -111,7 +120,7 @@ char *argv[];
verbose = 1; verbose = 1;
break; break;
default: default:
errx(1, "Usage: %s [-mrsv] [dir ...]", errx(1, "Usage: %s [-mrsv] [-f hints_file] [dir ...]",
__progname); __progname);
break; break;
} }
@ -254,12 +263,6 @@ int dewey[], ndewey;
} }
#if DEBUG
/* test */
#undef _PATH_LD_HINTS
#define _PATH_LD_HINTS "./ld.so.hints"
#endif
int int
hinthash(cp, vmajor) hinthash(cp, vmajor)
char *cp; char *cp;
@ -366,7 +369,7 @@ buildhints()
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz); errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
} }
tmpfile = concat(_PATH_LD_HINTS, ".XXXXXX", ""); tmpfile = concat(hints_file, ".XXXXXX", "");
if ((tmpfile = mktemp(tmpfile)) == NULL) { if ((tmpfile = mktemp(tmpfile)) == NULL) {
warn("%s", tmpfile); warn("%s", tmpfile);
return -1; return -1;
@ -374,37 +377,37 @@ buildhints()
umask(0); /* Create with exact permissions */ 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", hints_file);
return -1; return -1;
} }
if (write(fd, &hdr, sizeof(struct hints_header)) != if (write(fd, &hdr, sizeof(struct hints_header)) !=
sizeof(struct hints_header)) { sizeof(struct hints_header)) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
hdr.hh_nbucket * sizeof(struct hints_bucket)) { hdr.hh_nbucket * sizeof(struct hints_bucket)) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (write(fd, strtab, strtab_sz) != strtab_sz) { if (write(fd, strtab, strtab_sz) != strtab_sz) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (close(fd) != 0) { if (close(fd) != 0) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
/* Install it */ /* Install it */
if (unlink(_PATH_LD_HINTS) != 0 && errno != ENOENT) { if (unlink(hints_file) != 0 && errno != ENOENT) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (rename(tmpfile, _PATH_LD_HINTS) != 0) { if (rename(tmpfile, hints_file) != 0) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
@ -423,8 +426,8 @@ readhints()
struct shlib_list *shp; struct shlib_list *shp;
int i; int i;
if ((fd = open(_PATH_LD_HINTS, O_RDONLY, 0)) == -1) { if ((fd = open(hints_file, O_RDONLY, 0)) == -1) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
@ -432,14 +435,14 @@ readhints()
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) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
hdr = (struct hints_header *)addr; hdr = (struct hints_header *)addr;
if (HH_BADMAG(*hdr)) { if (HH_BADMAG(*hdr)) {
warnx("%s: Bad magic: %o", warnx("%s: Bad magic: %o",
_PATH_LD_HINTS, hdr->hh_magic); hints_file, hdr->hh_magic);
return -1; return -1;
} }
@ -454,7 +457,7 @@ readhints()
PROT_READ, MAP_COPY|MAP_FIXED, PROT_READ, MAP_COPY|MAP_FIXED,
fd, msize) != (caddr_t)(addr+msize)) { fd, msize) != (caddr_t)(addr+msize)) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
} }
@ -499,7 +502,7 @@ listhints()
struct shlib_list *shp; struct shlib_list *shp;
int i; int i;
printf("%s:\n", _PATH_LD_HINTS); printf("%s:\n", hints_file);
printf("\tsearch directories: %s\n", dir_list); 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)

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.8,v 1.7 1995/06/24 10:08:43 asami Exp $ .\" $Id: ldconfig.8,v 1.8 1996/04/08 04:17:33 mpp Exp $
.\" .\"
.Dd October 3, 1993 .Dd October 3, 1993
.Dt LDCONFIG 8 .Dt LDCONFIG 8
@ -38,6 +38,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm ldconfig .Nm ldconfig
.Op Fl mrsv .Op Fl mrsv
.Op Fl f Ar hints_file
.Op Ar directory Ar ... .Op Ar directory Ar ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -82,15 +83,17 @@ is typically run as part of the boot sequence.
The following options recognized by The following options recognized by
.Nm ldconfig: .Nm ldconfig:
.Bl -tag -width indent .Bl -tag -width indent
.It Fl f Ar hints_file
Read and/or update the specified hints file, instead of
.Pa /var/run/ld.so.hints .
This option is provided primarily for testing.
.It Fl m .It Fl m
Instead of replacing the contents of Instead of replacing the contents of the hints file
.Pa ld.so.hints
with those found in the directories specified, with those found in the directories specified,
.Dq merge .Dq merge
in new entries. in new entries.
.It Fl r .It Fl r
Lists the current contents of Lists the current contents of the hints file
.Pa ld.so.hints
on the standard output. The hints file will not be modified. on the standard output. The hints file will not be modified.
.It Fl s .It Fl s
Do not scan the built-in system directory Do not scan the built-in system directory
@ -104,8 +107,7 @@ space of
.Ev set-user-Id .Ev set-user-Id
programs. Whenever such a program is run, programs. Whenever such a program is run,
.Nm ld.so .Nm ld.so
will only load shared libraries from the will only load shared libraries from the hints
.Pa ld.so.hints
file. In particular, the file. In particular, the
.Ev LD_LIBRARY_PATH .Ev LD_LIBRARY_PATH
is not used to search for libraries. Thus, the role of ldconfig is dual. In is not used to search for libraries. Thus, the role of ldconfig is dual. In
@ -114,11 +116,6 @@ specify the trusted collection of directories from which shared objects can
be safely loaded. It is presumed that the set of directories specified to be safely loaded. It is presumed that the set of directories specified to
.Nm ldconfig .Nm ldconfig
are under control of the system's administrator. are under control of the system's administrator.
.Nm ld.so
further assists set-user-Id programs by erasing the
.Ev LD_LIBRARY_PATH
from the environment.
.Sh FILES .Sh FILES
.Pa /var/run/ld.so.hints .Pa /var/run/ld.so.hints
.Sh SEE ALSO .Sh SEE ALSO

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.13 1996/07/12 19:08:34 jkh Exp $ * $Id: ldconfig.c,v 1.14 1996/10/01 01:31:51 peter Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -57,6 +57,11 @@
#include "shlib.h" #include "shlib.h"
#include "support.h" #include "support.h"
#if DEBUG
/* test */
#undef _PATH_LD_HINTS
#define _PATH_LD_HINTS "./ld.so.hints"
#endif
#undef major #undef major
#undef minor #undef minor
@ -67,6 +72,7 @@ static int verbose;
static int nostd; static int nostd;
static int justread; static int justread;
static int merge; static int merge;
static char *hints_file = _PATH_LD_HINTS;
struct shlib_list { struct shlib_list {
/* Internal list of shared libraries found */ /* Internal list of shared libraries found */
@ -96,8 +102,11 @@ char *argv[];
int i, c; int i, c;
int rval = 0; int rval = 0;
while ((c = getopt(argc, argv, "mrsv")) != EOF) { while ((c = getopt(argc, argv, "f:mrsv")) != EOF) {
switch (c) { switch (c) {
case 'f':
hints_file = optarg;
break;
case 'm': case 'm':
merge = 1; merge = 1;
break; break;
@ -111,7 +120,7 @@ char *argv[];
verbose = 1; verbose = 1;
break; break;
default: default:
errx(1, "Usage: %s [-mrsv] [dir ...]", errx(1, "Usage: %s [-mrsv] [-f hints_file] [dir ...]",
__progname); __progname);
break; break;
} }
@ -254,12 +263,6 @@ int dewey[], ndewey;
} }
#if DEBUG
/* test */
#undef _PATH_LD_HINTS
#define _PATH_LD_HINTS "./ld.so.hints"
#endif
int int
hinthash(cp, vmajor) hinthash(cp, vmajor)
char *cp; char *cp;
@ -366,7 +369,7 @@ buildhints()
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz); errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
} }
tmpfile = concat(_PATH_LD_HINTS, ".XXXXXX", ""); tmpfile = concat(hints_file, ".XXXXXX", "");
if ((tmpfile = mktemp(tmpfile)) == NULL) { if ((tmpfile = mktemp(tmpfile)) == NULL) {
warn("%s", tmpfile); warn("%s", tmpfile);
return -1; return -1;
@ -374,37 +377,37 @@ buildhints()
umask(0); /* Create with exact permissions */ 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", hints_file);
return -1; return -1;
} }
if (write(fd, &hdr, sizeof(struct hints_header)) != if (write(fd, &hdr, sizeof(struct hints_header)) !=
sizeof(struct hints_header)) { sizeof(struct hints_header)) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) != if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
hdr.hh_nbucket * sizeof(struct hints_bucket)) { hdr.hh_nbucket * sizeof(struct hints_bucket)) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (write(fd, strtab, strtab_sz) != strtab_sz) { if (write(fd, strtab, strtab_sz) != strtab_sz) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (close(fd) != 0) { if (close(fd) != 0) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
/* Install it */ /* Install it */
if (unlink(_PATH_LD_HINTS) != 0 && errno != ENOENT) { if (unlink(hints_file) != 0 && errno != ENOENT) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
if (rename(tmpfile, _PATH_LD_HINTS) != 0) { if (rename(tmpfile, hints_file) != 0) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
@ -423,8 +426,8 @@ readhints()
struct shlib_list *shp; struct shlib_list *shp;
int i; int i;
if ((fd = open(_PATH_LD_HINTS, O_RDONLY, 0)) == -1) { if ((fd = open(hints_file, O_RDONLY, 0)) == -1) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
@ -432,14 +435,14 @@ readhints()
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) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
hdr = (struct hints_header *)addr; hdr = (struct hints_header *)addr;
if (HH_BADMAG(*hdr)) { if (HH_BADMAG(*hdr)) {
warnx("%s: Bad magic: %o", warnx("%s: Bad magic: %o",
_PATH_LD_HINTS, hdr->hh_magic); hints_file, hdr->hh_magic);
return -1; return -1;
} }
@ -454,7 +457,7 @@ readhints()
PROT_READ, MAP_COPY|MAP_FIXED, PROT_READ, MAP_COPY|MAP_FIXED,
fd, msize) != (caddr_t)(addr+msize)) { fd, msize) != (caddr_t)(addr+msize)) {
warn("%s", _PATH_LD_HINTS); warn("%s", hints_file);
return -1; return -1;
} }
} }
@ -499,7 +502,7 @@ listhints()
struct shlib_list *shp; struct shlib_list *shp;
int i; int i;
printf("%s:\n", _PATH_LD_HINTS); printf("%s:\n", hints_file);
printf("\tsearch directories: %s\n", dir_list); 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)