ldconfig: support for include directive
Luciano Miguel Ferreira Rocha
strange at nsk.no-ip.org
Mon Dec 18 21:20:25 UTC 2006
Hello,
The attached patch isn't pretty, but adds support for include directives
in ld.so.conf:
$ cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
$ cat /etc/ld.so.conf.d/nvidia.conf
/usr/lib/nvidia
$ ./ldconfig -v
...
libgimpbase-2.0.so.0 => libgimpbase-2.0.so.0.200.13
/usr/lib/nvidia:
libnvidia-tls.so.1 => libnvidia-tls.so.1.0.9631
--
lfr
0/0
-------------- next part --------------
--- ldconfig.c.1 2006-12-18 20:57:30.000000000 +0000
+++ ldconfig.c 2006-12-18 21:10:24.000000000 +0000
@@ -633,6 +633,75 @@
return;
}
#else
+static char *extend_single(char *mem, char *path)
+{
+ FILE *file;
+ struct stat stat;
+ char *n;
+ int l;
+
+ if ((file = fopen(path, "r")) == NULL)
+ return mem;
+ fstat(fileno(file), &stat);
+ l = strlen(mem);
+ n = realloc(mem, l + stat.st_size + 2);
+ if (!n) {
+ perror(path);
+ fclose(file);
+ return mem;
+ }
+ n[l] = '\n';
+ fread(n + l + 1, 1, stat.st_size, file);
+ fclose(file);
+ n[l + 1 + stat.st_size] = '\0';
+ return n;
+}
+
+static char *filter;
+
+#include <fnmatch.h>
+
+static int f(const struct dirent *d)
+{
+ return fnmatch(filter, d->d_name, 0) == 0;
+}
+
+static char *extend(char *mem, char *path)
+{
+ char *p;
+ struct dirent **files;
+ int i, n;
+
+ if (!strchr(path, '?') && !strchr(path, '*'))
+ return extend_single(mem, path);
+ p = strrchr(path, '/');
+ /* needs a path */
+ if (!p) return mem;
+ *p = '\0';
+ if (strchr(path, '?') || strchr(path, '*'))
+ /* not supported */
+ return mem;
+ filter = p + 1;
+
+ n = scandir(path, &files, f, alphasort);
+ if (n < 0) {
+ perror(path);
+ return mem;
+ }
+
+ *p = '/';
+ for (i = 0; i < n; i++) {
+ if (strlen(files[i]->d_name) < 256) {
+ strcpy(p + 1, files[i]->d_name);
+ mem = extend_single(mem, path);
+ }
+ free(files[i]);
+ }
+ free(files);
+ return mem;
+}
+
+
/* return the list of system-specific directories */
char *get_extpath(void)
{
@@ -640,10 +709,15 @@
FILE *file;
struct stat stat;
char realconffile[BUFFER_SIZE];
+ char *realconfpath, *path;
if (!chroot_realpath(chroot_dir, conffile, realconffile))
return NULL;
+ realconfpath = xmalloc(strlen(realconffile) + 512);
+ strcpy(realconfpath, realconffile);
+ path = strrchr(realconfpath, '/') + 1;
+
if ((file = fopen(realconffile, "r")) != NULL)
{
fstat(fileno(file), &stat);
@@ -662,8 +736,30 @@
cp++;
}
}
+
+ cp = res;
+ while ((cp = strstr(cp, "include "))) {
+ int i;
+
+ memset(cp, ' ', 7);
+ cp += 8;
+ while (*cp == ' ') cp++;
+ if (*cp == '\0' || *cp == '\n')
+ continue;
+ for (i = 0; i < 255 && cp[i] && cp[i] != '\n'; i++) {
+ path[i] = cp[i];
+ cp[i] = ' ';
+ }
+ if (i == 255) {
+ while (*cp && *cp != '\n') *cp++ = ' ';
+ continue;
+ }
+ path[i] = '\0';
+ res = extend(res, *path == '/' ? path : realconfpath);
+ }
}
+ free(realconfpath);
return res;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20061218/cc280da1/attachment-0002.pgp
More information about the uClibc
mailing list