xp_ldd can now read from ld.so.conf for additional library paths.
It also supports the new ld.so.conf file format with the 'include'
directive.

Signed-off-by: Abhishek Kulkarni <[EMAIL PROTECTED]>
Index: libxcpu/ldd.c
===================================================================
--- libxcpu/ldd.c	(revision 693)
+++ libxcpu/ldd.c	(working copy)
@@ -21,6 +21,8 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#define _GNU_SOURCE
+
 #ifndef XP_LDD
 
 int xp_ldd_support = 0;
@@ -42,12 +44,15 @@
 #include <errno.h>
 #include <libelf.h>
 #include <gelf.h>
+#include <glob.h>
 #include "spfs.h"
 #include "spclient.h"
 #include "libxauth.h"
 #include "libxcpu.h"
 #include "xcpuimpl.h"
 
+#define LD_SO_CONF "/etc/ld.so.conf"
+
 int xp_ldd_support = 1;
 
 typedef struct Dep Dep;
@@ -232,6 +237,95 @@
 	return 0;
 }
 
+static char ** 
+parse_conf(FILE *file)
+{
+        char *line;
+        char **ret = NULL, **temp = NULL;
+	FILE *fp;
+
+        int n = 0, i, result;
+	int maxentries = 16;
+        size_t len = 0;
+	ssize_t read = 0;
+	glob_t libglob;
+
+        ret = sp_malloc(maxentries*sizeof(char *));
+        if(!ret)
+                return NULL;
+
+        ret[0] = (char *)ret + (maxentries*sizeof(char *));
+        
+        while((read = getline(&line, &len, file)) != -1) {
+		
+		if(n > maxentries)
+			break;		
+			
+                /* Skip the whitespace */
+                while(*line==' ' || *line=='\t') {
+                        line++;
+                        read--;
+                }
+
+		/* Skip comments and/or blank lines */
+                if (*line == '#' || *line == '\n' || *line == '\0')
+                        continue;
+
+		if (line[read-1] == '\n') {
+			line[read-1] = '\0';
+			read--;
+		}
+
+                if (!strncmp(line, "include" , 7)) {
+			line += 8;
+			read -= 8;
+			result = glob(line, GLOB_NOSORT, NULL, &libglob);
+			
+			switch(result) {
+			case 0:
+				for(i = 0; i < libglob.gl_pathc; i++) {
+					if ((fp = fopen(libglob.gl_pathv[i], "r")) != NULL) {
+						temp = parse_conf(fp);
+						
+						while(*temp != NULL) {
+							ret[n] = sp_malloc(128);
+							strncpy(ret[n], *temp, strlen(*temp));				
+							n++;
+							temp++;
+						}
+					}
+				}
+
+				globfree(&libglob);
+				break;
+				
+			case GLOB_NOMATCH:
+				break;
+				
+			case GLOB_NOSPACE:
+				sp_werror(Enomem, EIO, line);
+				break;
+
+			case GLOB_ABORTED:
+				sp_werror("Cannot read directory: %s\n", EIO, line);
+				break;				
+			}
+			
+		} else {
+                        ret[n] = sp_malloc(128);
+                        strncpy(ret[n], line, read);
+                        ret[n][read] = '\0';
+			n++;
+                }
+		
+        }
+	
+        fclose(file);
+
+        ret[n] = NULL;
+        return ret;        
+}
+
 static char **
 parse_path(char *path)
 {
@@ -353,6 +447,7 @@
 init_paths(Deplist *dl)
 {
 	char *s;
+        FILE *f;        
 
 	elf_version(EV_CURRENT);
 
@@ -362,7 +457,8 @@
 		dl->ldlibpath = parse_path(s);
 
 	/* ld.so.conf */
-	// TODO
+        if ((f = fopen(LD_SO_CONF, "r")) != NULL) 
+                dl->ldsoconf = parse_conf(f);
 }
 
 int

Reply via email to