1 |
vapier 11/03/02 07:03:31 |
2 |
|
3 |
Modified: libq.c virtuals.c |
4 |
Added: profile.c |
5 |
Log: |
6 |
add a helper to walk the profile tree and read files |
7 |
|
8 |
Revision Changes Path |
9 |
1.24 portage-utils/libq/libq.c |
10 |
|
11 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.24&view=markup |
12 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.24&content-type=text/plain |
13 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?r1=1.23&r2=1.24 |
14 |
|
15 |
Index: libq.c |
16 |
=================================================================== |
17 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/libq.c,v |
18 |
retrieving revision 1.23 |
19 |
retrieving revision 1.24 |
20 |
diff -u -r1.23 -r1.24 |
21 |
--- libq.c 23 Feb 2011 22:58:52 -0000 1.23 |
22 |
+++ libq.c 2 Mar 2011 07:03:31 -0000 1.24 |
23 |
@@ -34,6 +34,7 @@ |
24 |
#include "basename.c" |
25 |
|
26 |
#ifndef _LIB_Q |
27 |
+# include "profile.c" |
28 |
# include "vdb_get_next_dir.c" |
29 |
# include "virtuals.c" |
30 |
#endif |
31 |
|
32 |
|
33 |
|
34 |
1.26 portage-utils/libq/virtuals.c |
35 |
|
36 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/virtuals.c?rev=1.26&view=markup |
37 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/virtuals.c?rev=1.26&content-type=text/plain |
38 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/virtuals.c?r1=1.25&r2=1.26 |
39 |
|
40 |
Index: virtuals.c |
41 |
=================================================================== |
42 |
RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v |
43 |
retrieving revision 1.25 |
44 |
retrieving revision 1.26 |
45 |
diff -u -r1.25 -r1.26 |
46 |
--- virtuals.c 24 Feb 2011 01:29:27 -0000 1.25 |
47 |
+++ virtuals.c 2 Mar 2011 07:03:31 -0000 1.26 |
48 |
@@ -1,12 +1,12 @@ |
49 |
/* |
50 |
* Copyright 2005-2010 Gentoo Foundation |
51 |
* Distributed under the terms of the GNU General Public License v2 |
52 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.25 2011/02/24 01:29:27 vapier Exp $ |
53 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.26 2011/03/02 07:03:31 vapier Exp $ |
54 |
* |
55 |
* Copyright 2005-2010 Ned Ludd - <solar@g.o> |
56 |
* Copyright 2005-2010 Mike Frysinger - <vapier@g.o> |
57 |
* |
58 |
- * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.25 2011/02/24 01:29:27 vapier Exp $ |
59 |
+ * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/virtuals.c,v 1.26 2011/03/02 07:03:31 vapier Exp $ |
60 |
*/ |
61 |
|
62 |
#include <stdio.h> |
63 |
@@ -81,10 +81,12 @@ |
64 |
strcpy(s, ptr); |
65 |
|
66 |
} while (v[0]); |
67 |
+ |
68 |
free(s); |
69 |
free(ptr); |
70 |
free(v); |
71 |
free(vptr); |
72 |
+ |
73 |
return q; |
74 |
} |
75 |
|
76 |
@@ -248,57 +250,28 @@ |
77 |
return virtuals; |
78 |
} |
79 |
|
80 |
-static queue *resolve_virtuals(void) |
81 |
+_q_static void * |
82 |
+resolve_virtuals_line(void *data, char *buf, FILE *fp) |
83 |
{ |
84 |
- static char buf[_Q_PATH_MAX]; |
85 |
- static char savecwd[_Q_PATH_MAX]; |
86 |
- static char *p; |
87 |
- FILE *fp; |
88 |
+ char *p; |
89 |
+ |
90 |
+ if (*buf != 'v') |
91 |
+ return data; |
92 |
|
93 |
- xgetcwd(savecwd, sizeof(savecwd)); |
94 |
+ rmspace(buf); |
95 |
+ if ((p = strchr(buf, ' ')) != NULL) { |
96 |
+ *p = 0; |
97 |
+ if (virtual(buf, virtuals) == NULL) |
98 |
+ virtuals = add_set(buf, rmspace(++p), virtuals); |
99 |
+ } |
100 |
+ |
101 |
+ return data; |
102 |
+} |
103 |
|
104 |
+_q_static queue *resolve_virtuals(void) |
105 |
+{ |
106 |
free_sets(virtuals); |
107 |
virtuals = resolve_local_profile_virtuals(); |
108 |
virtuals = resolve_vdb_virtuals(portvdb); |
109 |
- |
110 |
- if (chdir("/etc/") == -1) |
111 |
- return virtuals; |
112 |
- |
113 |
- if (readlink("make.profile", buf, sizeof(buf)) != -1) { |
114 |
- xchdir(buf); |
115 |
- xgetcwd(buf, sizeof(buf)); |
116 |
- if (access(buf, R_OK) != 0) |
117 |
- return virtuals; |
118 |
- vstart: |
119 |
- if ((fp = fopen("virtuals", "r")) != NULL) { |
120 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
121 |
- if (*buf != 'v') continue; |
122 |
- rmspace(buf); |
123 |
- if ((p = strchr(buf, ' ')) != NULL) { |
124 |
- *p = 0; |
125 |
- if (virtual(buf, virtuals) == NULL) |
126 |
- virtuals = add_set(buf, rmspace(++p), virtuals); |
127 |
- } |
128 |
- } |
129 |
- fclose(fp); |
130 |
- } |
131 |
- if ((fp = fopen("parent", "r")) != NULL) { |
132 |
- while ((fgets(buf, sizeof(buf), fp)) != NULL) { |
133 |
- rmspace(buf); |
134 |
- if (!*buf) continue; |
135 |
- if (*buf == '#') continue; |
136 |
- if (isspace(*buf)) continue; |
137 |
- fclose(fp); |
138 |
- if (chdir(buf) == -1) { |
139 |
- fclose(fp); |
140 |
- goto done; |
141 |
- } |
142 |
- goto vstart; |
143 |
- } |
144 |
- fclose(fp); |
145 |
- } |
146 |
- } |
147 |
- done: |
148 |
- xchdir(savecwd); |
149 |
- return virtuals; |
150 |
+ return q_profile_walk("virtuals", resolve_virtuals_line, virtuals); |
151 |
} |
152 |
|
153 |
|
154 |
|
155 |
1.1 portage-utils/libq/profile.c |
156 |
|
157 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/profile.c?rev=1.1&view=markup |
158 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/profile.c?rev=1.1&content-type=text/plain |
159 |
|
160 |
Index: profile.c |
161 |
=================================================================== |
162 |
typedef void *(q_profile_callback_t)(void *, char *, FILE *); |
163 |
|
164 |
_q_static void * |
165 |
q_profile_walk_at(int dir_fd, const char *dir, const char *file, |
166 |
q_profile_callback_t callback, void *data) |
167 |
{ |
168 |
FILE *fp; |
169 |
int subdir_fd, fd; |
170 |
size_t buflen; |
171 |
char *buf; |
172 |
|
173 |
/* Pop open this profile dir */ |
174 |
subdir_fd = openat(dir_fd, dir, O_RDONLY|O_CLOEXEC); |
175 |
if (subdir_fd < 0) |
176 |
return data; |
177 |
|
178 |
/* Then open the file */ |
179 |
fd = openat(subdir_fd, file, O_RDONLY|O_CLOEXEC); |
180 |
if (fd < 0) |
181 |
goto walk_parent; |
182 |
|
183 |
fp = fdopen(fd, "r"); |
184 |
if (!fp) { |
185 |
close(fd); |
186 |
goto walk_parent; |
187 |
} |
188 |
|
189 |
/* hand feed the file to the callback */ |
190 |
buf = NULL; |
191 |
while (getline(&buf, &buflen, fp) != -1) |
192 |
data = callback(data, buf, fp); |
193 |
free(buf); |
194 |
|
195 |
/* does close(fd) for us */ |
196 |
fclose(fp); |
197 |
|
198 |
/* Now walk the parents */ |
199 |
walk_parent: |
200 |
fd = openat(subdir_fd, "parent", O_RDONLY|O_CLOEXEC); |
201 |
if (fd < 0) |
202 |
goto done; |
203 |
fp = fdopen(fd, "r"); |
204 |
if (!fp) { |
205 |
close(fd); |
206 |
goto done; |
207 |
} |
208 |
|
209 |
buf = NULL; |
210 |
while (getline(&buf, &buflen, fp) != -1) { |
211 |
char *s; |
212 |
|
213 |
s = strchr(buf, '#'); |
214 |
if (s) |
215 |
*s = '\0'; |
216 |
rmspace(buf); |
217 |
|
218 |
data = q_profile_walk_at(subdir_fd, buf, file, callback, data); |
219 |
} |
220 |
free(buf); |
221 |
|
222 |
/* does close(fd) for us */ |
223 |
fclose(fp); |
224 |
|
225 |
done: |
226 |
if (subdir_fd != AT_FDCWD) |
227 |
close(subdir_fd); |
228 |
|
229 |
return data; |
230 |
} |
231 |
|
232 |
_q_static void * |
233 |
q_profile_walk(const char *file, q_profile_callback_t callback, void *data) |
234 |
{ |
235 |
/* Walk the profiles and read the file in question */ |
236 |
data = q_profile_walk_at(AT_FDCWD, EPREFIX "/etc/make.profile", file, callback, data); |
237 |
return q_profile_walk_at(AT_FDCWD, EPREFIX "/etc/portage/make.profile", file, callback, data); |
238 |
} |