From 571b472b209b70c4210d46d2f8845820d9ad4887 Mon Sep 17 00:00:00 2001 From: "Jordan K. Hubbard" Date: Fri, 11 Jul 1997 14:45:41 +0000 Subject: [PATCH] Allow ldconfig to accept files (containing directory paths) as well as directory paths. Reviewed by: jkh & jdp Submitted by: Hans Zuidam --- gnu/usr.bin/ld/ldconfig/ldconfig.8 | 19 +++++++-- gnu/usr.bin/ld/ldconfig/ldconfig.c | 63 +++++++++++++++++++++++++++--- sbin/ldconfig/ldconfig.8 | 19 +++++++-- sbin/ldconfig/ldconfig.c | 63 +++++++++++++++++++++++++++--- 4 files changed, 146 insertions(+), 18 deletions(-) diff --git a/gnu/usr.bin/ld/ldconfig/ldconfig.8 b/gnu/usr.bin/ld/ldconfig/ldconfig.8 index 07d5d69d48bf..3aee7bd533b4 100644 --- a/gnu/usr.bin/ld/ldconfig/ldconfig.8 +++ b/gnu/usr.bin/ld/ldconfig/ldconfig.8 @@ -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$ +.\" $Id: ldconfig.8,v 1.12 1997/02/22 15:46:37 peter Exp $ .\" .Dd October 3, 1993 .Dt LDCONFIG 8 @@ -39,7 +39,7 @@ .Nm ldconfig .Op Fl mrsv .Op Fl f Ar hints_file -.Op Ar directory Ar ... +.Op Ar directory | file Ar ... .Sh DESCRIPTION .Nm is used to prepare a set of @@ -57,6 +57,13 @@ directory search operations .Xr ld.so 1 would have to perform to load the required shared libraries. .Pp +Files named on the command line are expected to contain directories +to scan for shared libraries. Each directory's pathname must start on a new +line. Blank lines and lines starting with the comment character +.Ql \&# +are ignored. A standard name for this file is +.Xr /etc/ld.so.conf. +.Pp The shared libraries so found will be automatically available for loading if needed by the program being prepared for execution. This obviates the need for storing search paths within the executable. @@ -120,7 +127,13 @@ be safely loaded. It is presumed that the set of directories specified to .Nm ldconfig are under control of the system's administrator. .Sh FILES -.Pa /var/run/ld.so.hints +.Bl -tag -width /var/run/ld.so.hintsxxx -compact +.It Pa /var/run/ld.so.hints +Default +.Dq hints +file. +.It Pa /etc/ld.so.conf +Standard configuration file. .Sh SEE ALSO .Xr ld 1 , .Xr link 5 diff --git a/gnu/usr.bin/ld/ldconfig/ldconfig.c b/gnu/usr.bin/ld/ldconfig/ldconfig.c index c26edcbb9e10..3eed70a3a049 100644 --- a/gnu/usr.bin/ld/ldconfig/ldconfig.c +++ b/gnu/usr.bin/ld/ldconfig/ldconfig.c @@ -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$ + * $Id: ldconfig.c,v 1.18 1997/02/22 15:46:38 peter Exp $ */ #include @@ -120,7 +120,7 @@ char *argv[]; verbose = 1; break; default: - errx(1, "Usage: %s [-mrsv] [-f hints_file] [dir ...]", + errx(1, "Usage: %s [-mrsv] [-f hints_file] [dir | file ...]", __progname); break; } @@ -136,13 +136,24 @@ char *argv[]; if (!nostd && !merge) std_search_path(); - if (!justread) { /* Add any directories from the command line */ + /* Add any directories/files from the command line */ + if (!justread) { for (i = optind; i < argc; i++) { - if (access(argv[i], F_OK) == -1) { /* Doesn't exist */ + struct stat stbuf; + + if (stat(argv[i], &stbuf) == -1) { warn("%s", argv[i]); rval = -1; - } else - add_search_path(argv[i]); + } else { + /* + * See if this is a directory-containing + * file instead of a directory + */ + if (S_ISREG(stbuf.st_mode)) + rval |= dofile(argv[i], 0); + else + add_search_path(argv[i]); + } } } @@ -165,6 +176,45 @@ char *argv[]; return rval; } +int +dofile(fname, silent) +char *fname; +int silent; +{ + FILE *hfp; + char buf[MAXPATHLEN]; + int rval = 0; + char *cp, *sp; + + if ((hfp = fopen(fname, "r")) == NULL) { + warn("%s", fname); + return -1; + } + + while (fgets(buf, sizeof(buf), hfp)) { + cp = buf; + while (isspace(*cp)) + cp++; + if (*cp == '#' || *cp == '\0') + continue; + sp = cp; + while (!isspace(*cp) && *cp != '\0') + cp++; + + if (*cp != '\n') { + *cp = '\0'; + warnx("%s: Trailing characters ignored", sp); + } + + *cp = '\0'; + + rval |= dodir(sp, silent); + } + + (void)fclose(hfp); + return rval; +} + int dodir(dir, silent) char *dir; @@ -218,6 +268,7 @@ int silent; enter(dir, dp->d_name, name, dewey, ndewey); } + closedir(dd); return 0; } diff --git a/sbin/ldconfig/ldconfig.8 b/sbin/ldconfig/ldconfig.8 index 07d5d69d48bf..3aee7bd533b4 100644 --- a/sbin/ldconfig/ldconfig.8 +++ b/sbin/ldconfig/ldconfig.8 @@ -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$ +.\" $Id: ldconfig.8,v 1.12 1997/02/22 15:46:37 peter Exp $ .\" .Dd October 3, 1993 .Dt LDCONFIG 8 @@ -39,7 +39,7 @@ .Nm ldconfig .Op Fl mrsv .Op Fl f Ar hints_file -.Op Ar directory Ar ... +.Op Ar directory | file Ar ... .Sh DESCRIPTION .Nm is used to prepare a set of @@ -57,6 +57,13 @@ directory search operations .Xr ld.so 1 would have to perform to load the required shared libraries. .Pp +Files named on the command line are expected to contain directories +to scan for shared libraries. Each directory's pathname must start on a new +line. Blank lines and lines starting with the comment character +.Ql \&# +are ignored. A standard name for this file is +.Xr /etc/ld.so.conf. +.Pp The shared libraries so found will be automatically available for loading if needed by the program being prepared for execution. This obviates the need for storing search paths within the executable. @@ -120,7 +127,13 @@ be safely loaded. It is presumed that the set of directories specified to .Nm ldconfig are under control of the system's administrator. .Sh FILES -.Pa /var/run/ld.so.hints +.Bl -tag -width /var/run/ld.so.hintsxxx -compact +.It Pa /var/run/ld.so.hints +Default +.Dq hints +file. +.It Pa /etc/ld.so.conf +Standard configuration file. .Sh SEE ALSO .Xr ld 1 , .Xr link 5 diff --git a/sbin/ldconfig/ldconfig.c b/sbin/ldconfig/ldconfig.c index c26edcbb9e10..3eed70a3a049 100644 --- a/sbin/ldconfig/ldconfig.c +++ b/sbin/ldconfig/ldconfig.c @@ -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$ + * $Id: ldconfig.c,v 1.18 1997/02/22 15:46:38 peter Exp $ */ #include @@ -120,7 +120,7 @@ char *argv[]; verbose = 1; break; default: - errx(1, "Usage: %s [-mrsv] [-f hints_file] [dir ...]", + errx(1, "Usage: %s [-mrsv] [-f hints_file] [dir | file ...]", __progname); break; } @@ -136,13 +136,24 @@ char *argv[]; if (!nostd && !merge) std_search_path(); - if (!justread) { /* Add any directories from the command line */ + /* Add any directories/files from the command line */ + if (!justread) { for (i = optind; i < argc; i++) { - if (access(argv[i], F_OK) == -1) { /* Doesn't exist */ + struct stat stbuf; + + if (stat(argv[i], &stbuf) == -1) { warn("%s", argv[i]); rval = -1; - } else - add_search_path(argv[i]); + } else { + /* + * See if this is a directory-containing + * file instead of a directory + */ + if (S_ISREG(stbuf.st_mode)) + rval |= dofile(argv[i], 0); + else + add_search_path(argv[i]); + } } } @@ -165,6 +176,45 @@ char *argv[]; return rval; } +int +dofile(fname, silent) +char *fname; +int silent; +{ + FILE *hfp; + char buf[MAXPATHLEN]; + int rval = 0; + char *cp, *sp; + + if ((hfp = fopen(fname, "r")) == NULL) { + warn("%s", fname); + return -1; + } + + while (fgets(buf, sizeof(buf), hfp)) { + cp = buf; + while (isspace(*cp)) + cp++; + if (*cp == '#' || *cp == '\0') + continue; + sp = cp; + while (!isspace(*cp) && *cp != '\0') + cp++; + + if (*cp != '\n') { + *cp = '\0'; + warnx("%s: Trailing characters ignored", sp); + } + + *cp = '\0'; + + rval |= dodir(sp, silent); + } + + (void)fclose(hfp); + return rval; +} + int dodir(dir, silent) char *dir; @@ -218,6 +268,7 @@ int silent; enter(dir, dp->d_name, name, dewey, ndewey); } + closedir(dd); return 0; }