Allow ldconfig to accept files (containing directory paths) as well as

directory paths.
Reviewed by:	jkh & jdp
Submitted by:	Hans Zuidam <hans@brandinnovators.com>
This commit is contained in:
Jordan K. Hubbard 1997-07-11 14:45:41 +00:00
parent 73f3d05336
commit 571b472b20
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27334
4 changed files with 146 additions and 18 deletions

View File

@ -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

View File

@ -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 <sys/param.h>
@ -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;
}

View File

@ -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

View File

@ -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 <sys/param.h>
@ -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;
}