/[path-sandbox]/trunk/src/sandbox.c
Gentoo

Diff of /trunk/src/sandbox.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 86 Revision 87
89 if (data) 89 if (data)
90 free(data); 90 free(data);
91 data = NULL; 91 data = NULL;
92 92
93 return num_pids; 93 return num_pids;
94}
95
96/* Read ld.so.preload file, and loads dirs into an array. Return number of entries in array */
97int load_preload_libs(int fd, char ***preloads)
98{
99 char *data = NULL;
100 char *ptr = NULL, *ptr2 = NULL;
101 int num_entries = 0;
102 long len;
103
104 preloads[0] = NULL;
105
106 len = file_length(fd);
107
108 /* Allocate and zero datablock to read pids file */
109 data = (char *)malloc((len + 1) * sizeof(char));
110 memset(data, 0, len + 1);
111
112 /* Start at beginning of file */
113 lseek(fd, 0L, SEEK_SET);
114
115 /* read entire file into a buffer */
116 read(fd, data, len);
117
118 ptr = data;
119
120 /* Loop and read all pids */
121 while (1) {
122 /* Find new line */
123 ptr2 = strchr(ptr, '\n');
124
125 /* Clear the \n. And ptr should have a null-terminated decimal string
126 * Don't break from the loop though because the last line may not
127 * terminated with a \n
128 */
129 if (NULL != ptr2)
130 ptr2[0] = 0;
131
132 /* If listing does not match our libname, add it to the array */
133 if ((strlen(ptr)) && (NULL == strstr(ptr, LIB_NAME))) {
134 preloads[0] = (char **)realloc(preloads[0], (num_entries + 1) * sizeof(char **));
135 preloads[0][num_entries] = strdup(ptr);
136 num_entries++;
137 }
138
139 if (NULL == ptr2)
140 break; /* No more PIDs */
141
142 /* Put ptr past the NULL we just wrote */
143 ptr = ptr2 + 1;
144 }
145
146 if (data)
147 free(data);
148 data = NULL;
149
150 return num_entries;
151} 94}
152 95
153void cleanup() 96void cleanup()
154{ 97{
155 int i = 0; 98 int i = 0;

Legend:
Removed from v.86  
changed lines
  Added in v.87

  ViewVC Help
Powered by ViewVC 1.1.20