Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jul 1996 16:59:45 +0200 (MET DST)
From:      hans@brandinnovators.com (Hans Zuidam)
To:        freebsd-hackers@freebsd.org
Subject:   Patch for ldconfig 2.1R
Message-ID:  <199607241459.QAA01080@truk.brandinnovators.com>

next in thread | raw e-mail | index | archive | help
Hi,

Below is a trivial patch for ldconfig(8) to make it read it's
directories from a file instead of enumerating them on the command
line.  Maybe something for inclusion in some future release.

To use the new version you would create a file like /etc/ld.so.conf
which lists each shared library directory and in /etc/rc only the
line `ldconfig /etc/ld.so.conf'

Below is a unified diff
----8<-------------------------------------------------------------------
diff -u /usr/src/gnu/usr.bin/ld/ldconfig/ldconfig.8 ldconfig/ldconfig.8
--- /usr/src/gnu/usr.bin/ld/ldconfig/ldconfig.8	Sun Aug 13 15:26:24 1995
+++ ldconfig/ldconfig.8	Wed Jul 24 16:45:25 1996
@@ -38,7 +38,7 @@
 .Sh SYNOPSIS
 .Nm ldconfig
 .Op Fl mrsv
-.Op Ar directory Ar ...
+.Op Ar directory | file Ar ...
 .Sh DESCRIPTION
 .Nm
 is used to prepare a set of
@@ -56,6 +56,13 @@
 .Xr ld.so
 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 must start on a new
+line and blank lines and lines starting with the comment character
+(`#') are ignored. A good name for this file would be
+.Xr /etc/ld.so.conf.
+The directories are treated as if they were entered on the command line.
+.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.
@@ -121,6 +128,8 @@
 
 .Sh FILES
 .Xr /var/run/ld.so.hints
+.br
+.Xr /etc/ld.so.conf
 .Sh SEE ALSO
 .Xr ld 1 ,
 .Xr link 5
diff -u /usr/src/gnu/usr.bin/ld/ldconfig/ldconfig.c ldconfig/ldconfig.c
--- /usr/src/gnu/usr.bin/ld/ldconfig/ldconfig.c	Fri Aug 25 06:41:14 1995
+++ ldconfig/ldconfig.c	Wed Jul 24 16:32:44 1996
@@ -103,7 +103,7 @@
 			verbose = 1;
 			break;
 		default:
-			errx(1, "Usage: %s [-m][-r][-s][-v][dir ...]",
+			errx(1, "Usage: %s [-m][-r][-s][-v][dir | file ...]",
 				__progname);
 			break;
 		}
@@ -124,8 +124,21 @@
 	for (i = 0; i < n_search_dirs; i++)
 		rval |= dodir(search_dirs[i], 1);
 
-	for (i = optind; i < argc; i++)
-		rval |= dodir(argv[i], 0);
+	for (i = optind; i < argc; i++) {
+		struct stat stbuf;
+
+		if (stat(argv[i], &stbuf) == -1) {
+			if (errno != ENOENT)
+				warn("%s", argv[i]);
+			continue;
+		}
+
+		/* See if this is a file instead of a directory */
+		if ((stbuf.st_mode & S_IFMT) == S_IFREG)
+			rval |= dofile(argv[i], 0);
+		else
+			rval |= dodir(argv[i], 0);
+	}
 
 	rval |= buildhints();
 
@@ -133,6 +146,39 @@
 }
 
 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 (*cp != '#' && *cp != '/' && *cp != '\0')
+			cp++;
+		if (*cp == '#' || *cp == '\0')
+			continue;
+		sp = cp;
+		while (!isspace(*cp) && *cp != '#' && *cp != '\0')
+			cp++;
+		*cp++ = '\0';
+
+		rval |= dodir(buf, silent);
+	}
+
+	(void) fclose(hfp);
+	return rval;
+}
+
+int
 dodir(dir, silent)
 char	*dir;
 int	silent;
@@ -163,6 +209,7 @@
 		enter(dir, dp->d_name, name, dewey, ndewey);
 	}
 
+	(void) closedir(dd);
 	return 0;
 }
 
----8<-------------------------------------------------------------------

Regards,
				Hans
-- 
Hans Zuidam                      E-Mail: hans@brandinnovators.com
Brand Innovators B.V.            P-Mail: P.O. Box 1377
de Pinckart 54                   5602 BJ Eindhoven, The Netherlands
5674 CC Nuenen                   Tel. +31 40 2631134, Fax. +31 40 2831138



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607241459.QAA01080>