diff options
Diffstat (limited to 'meta/packages/pseudo/pseudo/data-as-env.patch')
-rw-r--r-- | meta/packages/pseudo/pseudo/data-as-env.patch | 382 |
1 files changed, 0 insertions, 382 deletions
diff --git a/meta/packages/pseudo/pseudo/data-as-env.patch b/meta/packages/pseudo/pseudo/data-as-env.patch deleted file mode 100644 index 6cef1b316b..0000000000 --- a/meta/packages/pseudo/pseudo/data-as-env.patch +++ /dev/null | |||
@@ -1,382 +0,0 @@ | |||
1 | We observed the pseudo database becoming large and corrupted when undergoing | ||
2 | significant use (generating multiple output package types). | ||
3 | |||
4 | This patch checks for the existence of an PSEUDO_DATADIR environment variable | ||
5 | and, when it exists, uses the directory specified there to store the pseudo | ||
6 | database. This should enable us to use a different database for each run of | ||
7 | pseudo. | ||
8 | |||
9 | JL (23/07/10) | ||
10 | |||
11 | Updates to include lock/log/socket/pid files | ||
12 | |||
13 | RP (24/07/10) | ||
14 | |||
15 | Index: git/pseudo.h | ||
16 | =================================================================== | ||
17 | --- git.orig/pseudo.h 2010-07-24 00:28:35.762423800 +0100 | ||
18 | +++ git/pseudo.h 2010-07-24 10:34:33.902335659 +0100 | ||
19 | @@ -123,6 +123,7 @@ | ||
20 | extern char *pseudo_fix_path(const char *, const char *, size_t, size_t, size_t *, int); | ||
21 | extern char **pseudo_dropenv(char * const *); | ||
22 | extern char **pseudo_setupenv(char * const *, char *); | ||
23 | +extern char *pseudo_data_path(char *); | ||
24 | extern char *pseudo_prefix_path(char *); | ||
25 | extern char *pseudo_get_prefix(char *); | ||
26 | extern int pseudo_logfile(char *defname); | ||
27 | @@ -134,10 +135,16 @@ | ||
28 | |||
29 | extern char *pseudo_version; | ||
30 | |||
31 | -#define PSEUDO_LOCKFILE PSEUDO_DATA "/pseudo.lock" | ||
32 | -#define PSEUDO_LOGFILE PSEUDO_DATA "/pseudo.log" | ||
33 | -#define PSEUDO_PIDFILE PSEUDO_DATA "/pseudo.pid" | ||
34 | -#define PSEUDO_SOCKET PSEUDO_DATA "/pseudo.socket" | ||
35 | +#define PSEUDO_LOCKFILE "/pseudo.lock" | ||
36 | +#define PSEUDO_LOGFILE "/pseudo.log" | ||
37 | +#define PSEUDO_PIDFILE "/pseudo.pid" | ||
38 | +#define PSEUDO_SOCKET "/pseudo.socket" | ||
39 | + | ||
40 | +extern char *pseudo_get_pid(); | ||
41 | +extern char *pseudo_get_lockfile(); | ||
42 | +extern char *pseudo_get_logfile(); | ||
43 | +extern char *pseudo_get_socketfile(); | ||
44 | + | ||
45 | |||
46 | /* some systems might not have *at(). We like to define operations in | ||
47 | * terms of each other, and for instance, open(...) is the same as | ||
48 | Index: git/pseudo_db.c | ||
49 | =================================================================== | ||
50 | --- git.orig/pseudo_db.c 2010-07-24 00:28:35.762423800 +0100 | ||
51 | +++ git/pseudo_db.c 2010-07-24 00:28:36.282335730 +0100 | ||
52 | @@ -465,17 +465,18 @@ | ||
53 | char *errmsg; | ||
54 | static int registered_cleanup = 0; | ||
55 | char *dbfile; | ||
56 | + char *data_dir; | ||
57 | |||
58 | if (!db) | ||
59 | return 1; | ||
60 | if (*db) | ||
61 | return 0; | ||
62 | if (db == &file_db) { | ||
63 | - dbfile = strdup(PSEUDO_DATA "/files.db"); | ||
64 | + dbfile = pseudo_data_path("files.db"); | ||
65 | rc = sqlite3_open(dbfile, db); | ||
66 | free(dbfile); | ||
67 | } else { | ||
68 | - dbfile = strdup(PSEUDO_DATA "/logs.db"); | ||
69 | + dbfile = pseudo_data_path("logs.db"); | ||
70 | rc = sqlite3_open(dbfile, db); | ||
71 | free(dbfile); | ||
72 | } | ||
73 | Index: git/pseudo_server.c | ||
74 | =================================================================== | ||
75 | --- git.orig/pseudo_server.c 2010-07-24 00:28:35.762423800 +0100 | ||
76 | +++ git/pseudo_server.c 2010-07-24 10:27:59.242335869 +0100 | ||
77 | @@ -107,7 +107,7 @@ | ||
78 | } | ||
79 | |||
80 | /* cd to the data directory */ | ||
81 | - pseudo_path = strdup(PSEUDO_DATA); | ||
82 | + pseudo_path = pseudo_data_path(NULL); | ||
83 | if (!pseudo_path) { | ||
84 | pseudo_diag("can't find %s directory.\n", PSEUDO_DATA); | ||
85 | return 1; | ||
86 | @@ -138,9 +138,9 @@ | ||
87 | return 0; | ||
88 | } | ||
89 | setsid(); | ||
90 | - pseudo_path = strdup(PSEUDO_PIDFILE); | ||
91 | + pseudo_path = pseudo_get_pid(); | ||
92 | if (!pseudo_path) { | ||
93 | - pseudo_diag("Couldn't get path for %s\n", PSEUDO_PIDFILE); | ||
94 | + pseudo_diag("Couldn't get pid path\n"); | ||
95 | return 1; | ||
96 | } | ||
97 | fp = fopen(pseudo_path, "w"); | ||
98 | @@ -156,7 +156,7 @@ | ||
99 | pseudo_new_pid(); | ||
100 | fclose(stdin); | ||
101 | fclose(stdout); | ||
102 | - if (!pseudo_logfile(PSEUDO_LOGFILE)) | ||
103 | + if (!pseudo_logfile(pseudo_get_logfile())) | ||
104 | fclose(stderr); | ||
105 | } | ||
106 | signal(SIGHUP, quit_now); | ||
107 | Index: git/pseudo_util.c | ||
108 | =================================================================== | ||
109 | --- git.orig/pseudo_util.c 2010-07-24 00:28:35.962336149 +0100 | ||
110 | +++ git/pseudo_util.c 2010-07-24 10:50:48.062336358 +0100 | ||
111 | @@ -593,6 +593,50 @@ | ||
112 | return new_environ; | ||
113 | } | ||
114 | |||
115 | +/* get the full path to the datadir for this run of pseudo | ||
116 | + * file parameter is optional and returns the datadir path | ||
117 | + * with the file name appended. | ||
118 | + */ | ||
119 | +char * | ||
120 | +pseudo_data_path(char *file) { | ||
121 | + static char *datadir = NULL; | ||
122 | + static size_t datadir_len; | ||
123 | + char *path; | ||
124 | + | ||
125 | + if (!datadir) { | ||
126 | + datadir = getenv("PSEUDO_DATADIR"); | ||
127 | + if (!datadir) { | ||
128 | + datadir = strdup(PSEUDO_DATA); | ||
129 | + } | ||
130 | + datadir_len = strlen(datadir); | ||
131 | + } | ||
132 | + | ||
133 | + if (!file) { | ||
134 | + return strdup(datadir); | ||
135 | + } else { | ||
136 | + size_t len = datadir_len + strlen(file) + 2; | ||
137 | + path = malloc(len); | ||
138 | + if (path) { | ||
139 | + char *endptr; | ||
140 | + int rc; | ||
141 | + | ||
142 | + rc = snprintf(path, len, "%s", datadir); | ||
143 | + /* this certainly SHOULD be impossible */ | ||
144 | + if ((size_t) rc >= len) | ||
145 | + rc = len - 1; | ||
146 | + endptr = path + rc; | ||
147 | + /* strip extra slashes. | ||
148 | + * This probably has no real effect, but I don't like | ||
149 | + * seeing " //" in paths. | ||
150 | + */ | ||
151 | + while ((endptr > path) && (endptr[-1] == '/')) | ||
152 | + --endptr; | ||
153 | + snprintf(endptr, len - (endptr - path), "/%s", file); | ||
154 | + } | ||
155 | + return path; | ||
156 | + } | ||
157 | +} | ||
158 | + | ||
159 | /* get the full path to a file under $PSEUDO_PREFIX. Other ways of | ||
160 | * setting the prefix all set it in the environment. | ||
161 | */ | ||
162 | @@ -691,6 +735,26 @@ | ||
163 | return s; | ||
164 | } | ||
165 | |||
166 | +char * | ||
167 | +pseudo_get_pid() { | ||
168 | + return pseudo_data_path(PSEUDO_PIDFILE); | ||
169 | +} | ||
170 | + | ||
171 | +char * | ||
172 | +pseudo_get_lockfile() { | ||
173 | + return pseudo_data_path(PSEUDO_LOCKFILE); | ||
174 | +} | ||
175 | + | ||
176 | +char * | ||
177 | +pseudo_get_logfile() { | ||
178 | + return pseudo_data_path(PSEUDO_LOGFILE); | ||
179 | +} | ||
180 | + | ||
181 | +char * | ||
182 | +pseudo_get_socketfile() { | ||
183 | + return pseudo_data_path(PSEUDO_SOCKET); | ||
184 | +} | ||
185 | + | ||
186 | /* these functions define the sizes pseudo will try to use | ||
187 | * when trying to allocate space, or guess how much space | ||
188 | * other people will have allocated; see the GNU man page | ||
189 | @@ -844,20 +908,14 @@ | ||
190 | |||
191 | /* set up a log file */ | ||
192 | int | ||
193 | -pseudo_logfile(char *defname) { | ||
194 | - char *pseudo_path; | ||
195 | +pseudo_logfile(char *pseudo_path) { | ||
196 | char *filename, *s; | ||
197 | extern char *program_invocation_short_name; /* glibcism */ | ||
198 | int fd; | ||
199 | |||
200 | if ((filename = getenv("PSEUDO_DEBUG_FILE")) == NULL) { | ||
201 | - if (!defname) { | ||
202 | - pseudo_debug(3, "no special log file requested, using stderr.\n"); | ||
203 | - return -1; | ||
204 | - } | ||
205 | - pseudo_path = strdup(defname); | ||
206 | if (!pseudo_path) { | ||
207 | - pseudo_diag("can't get path for prefix/%s\n", PSEUDO_LOGFILE); | ||
208 | + pseudo_debug(3, "no special log file requested or unable to malloc space, using stderr.\n"); | ||
209 | return -1; | ||
210 | } | ||
211 | } else { | ||
212 | @@ -903,6 +961,7 @@ | ||
213 | len += 8; | ||
214 | if (prog) | ||
215 | len += strlen(program_invocation_short_name); | ||
216 | + free(pseudo_path); | ||
217 | pseudo_path = malloc(len); | ||
218 | if (!pseudo_path) { | ||
219 | pseudo_diag("can't allocate space for debug file name.\n"); | ||
220 | Index: git/pseudo.c | ||
221 | =================================================================== | ||
222 | --- git.orig/pseudo.c 2010-07-24 10:22:10.053594896 +0100 | ||
223 | +++ git/pseudo.c 2010-07-24 10:23:20.883585467 +0100 | ||
224 | @@ -272,7 +272,7 @@ | ||
225 | pseudo_new_pid(); | ||
226 | |||
227 | pseudo_debug(3, "opening lock.\n"); | ||
228 | - lockname = strdup(PSEUDO_LOCKFILE); | ||
229 | + lockname = pseudo_get_lockfile(); | ||
230 | if (!lockname) { | ||
231 | pseudo_diag("Couldn't allocate a file path.\n"); | ||
232 | exit(EXIT_FAILURE); | ||
233 | Index: git/pseudo_client.c | ||
234 | =================================================================== | ||
235 | --- git.orig/pseudo_client.c 2010-07-24 10:03:51.933588401 +0100 | ||
236 | +++ git/pseudo_client.c 2010-07-25 00:30:29.152364992 +0100 | ||
237 | @@ -359,6 +359,7 @@ | ||
238 | FILE *fp; | ||
239 | extern char **environ; | ||
240 | int cwd_fd; | ||
241 | + char *pidpath; | ||
242 | |||
243 | if ((server_pid = fork()) != 0) { | ||
244 | if (server_pid == -1) { | ||
245 | @@ -383,7 +384,12 @@ | ||
246 | pseudo_diag("Couldn't change to server dir [%d]: %s\n", | ||
247 | pseudo_dir_fd, strerror(errno)); | ||
248 | } | ||
249 | - fp = fopen(PSEUDO_PIDFILE, "r"); | ||
250 | + pidpath = pseudo_get_pid(); | ||
251 | + if (!pidpath) { | ||
252 | + pseudo_diag("Couldn't get pid path\n"); | ||
253 | + return 1; | ||
254 | + } | ||
255 | + fp = fopen(pidpath, "r"); | ||
256 | if (fchdir(cwd_fd) == -1) { | ||
257 | pseudo_diag("return to previous directory failed: %s\n", | ||
258 | strerror(errno)); | ||
259 | @@ -396,8 +402,9 @@ | ||
260 | fclose(fp); | ||
261 | } else { | ||
262 | pseudo_diag("no pid file (%s): %s\n", | ||
263 | - PSEUDO_PIDFILE, strerror(errno)); | ||
264 | + pidpath, strerror(errno)); | ||
265 | } | ||
266 | + free(pidpath); | ||
267 | pseudo_debug(2, "read new pid file: %d\n", server_pid); | ||
268 | /* at this point, we should have a new server_pid */ | ||
269 | return 0; | ||
270 | @@ -407,6 +414,8 @@ | ||
271 | char **new_environ; | ||
272 | int args; | ||
273 | int fd; | ||
274 | + int pseudo_prefix_fd; | ||
275 | + char *pseudo_path; | ||
276 | |||
277 | pseudo_new_pid(); | ||
278 | base_args[0] = "bin/pseudo"; | ||
279 | @@ -439,9 +448,21 @@ | ||
280 | } else { | ||
281 | argv = base_args; | ||
282 | } | ||
283 | - if (fchdir(pseudo_dir_fd)) { | ||
284 | + | ||
285 | + | ||
286 | + pseudo_path = pseudo_prefix_path(NULL); | ||
287 | + if (pseudo_path) { | ||
288 | + pseudo_prefix_fd = open(pseudo_path, O_RDONLY); | ||
289 | + pseudo_prefix_fd = pseudo_fd(pseudo_prefix_fd, MOVE_FD); | ||
290 | + free(pseudo_path); | ||
291 | + } else { | ||
292 | + pseudo_diag("No prefix available to to find server.\n"); | ||
293 | + exit(1); | ||
294 | + } | ||
295 | + | ||
296 | + if (fchdir(pseudo_prefix_fd)) { | ||
297 | pseudo_diag("Couldn't change to server dir [%d]: %s\n", | ||
298 | - pseudo_dir_fd, strerror(errno)); | ||
299 | + pseudo_prefix_fd, strerror(errno)); | ||
300 | } | ||
301 | /* close any higher-numbered fds which might be open, | ||
302 | * such as sockets. We don't have to worry about 0 and 1; | ||
303 | @@ -535,10 +556,17 @@ | ||
304 | |||
305 | static int | ||
306 | client_connect(void) { | ||
307 | + char *socketfile = pseudo_get_socketfile(); | ||
308 | /* we have a server pid, is it responsive? */ | ||
309 | - struct sockaddr_un sun = { AF_UNIX, PSEUDO_SOCKET }; | ||
310 | + struct sockaddr_un sun = { AF_UNIX, "pseudo.socket" }; | ||
311 | int cwd_fd; | ||
312 | |||
313 | + if (!socketfile) { | ||
314 | + pseudo_diag("Couldn't malloc socketfile"); | ||
315 | + | ||
316 | + return 1; | ||
317 | + } | ||
318 | + | ||
319 | connect_fd = socket(PF_UNIX, SOCK_STREAM, 0); | ||
320 | connect_fd = pseudo_fd(connect_fd, MOVE_FD); | ||
321 | if (connect_fd == -1) { | ||
322 | @@ -564,7 +592,7 @@ | ||
323 | return 1; | ||
324 | } | ||
325 | if (connect(connect_fd, (struct sockaddr *) &sun, sizeof(sun)) == -1) { | ||
326 | - pseudo_debug(3, "can't connect socket to pseudo.socket: (%s)\n", strerror(errno)); | ||
327 | + pseudo_debug(3, "can't connect socket to %s: (%s)\n", sun.sun_path, strerror(errno)); | ||
328 | close(connect_fd); | ||
329 | if (fchdir(cwd_fd) == -1) { | ||
330 | pseudo_diag("return to previous directory failed: %s\n", | ||
331 | @@ -588,6 +616,7 @@ | ||
332 | FILE *fp; | ||
333 | server_pid = 0; | ||
334 | int cwd_fd; | ||
335 | + char *pidpath; | ||
336 | |||
337 | /* avoid descriptor leak, I hope */ | ||
338 | if (connect_fd >= 0) { | ||
339 | @@ -604,7 +633,12 @@ | ||
340 | return 1; | ||
341 | } | ||
342 | if (fchdir(pseudo_dir_fd) != 1) { | ||
343 | - fp = fopen(PSEUDO_PIDFILE, "r"); | ||
344 | + pidpath = pseudo_get_pid(); | ||
345 | + if (!pidpath) { | ||
346 | + pseudo_diag("Couldn't get pid path\n"); | ||
347 | + return 1; | ||
348 | + } | ||
349 | + fp = fopen(pidpath, "r"); | ||
350 | if (fchdir(cwd_fd) == -1) { | ||
351 | pseudo_diag("return to previous directory failed: %s\n", | ||
352 | strerror(errno)); | ||
353 | @@ -619,6 +653,7 @@ | ||
354 | pseudo_debug(1, "Opened server PID file, but didn't get a pid.\n"); | ||
355 | } | ||
356 | fclose(fp); | ||
357 | + free(pidpath); | ||
358 | } | ||
359 | if (server_pid) { | ||
360 | if (kill(server_pid, 0) == -1) { | ||
361 | @@ -710,7 +745,7 @@ | ||
362 | pseudo_msg_t *ack; | ||
363 | char *pseudo_path; | ||
364 | |||
365 | - pseudo_path = pseudo_prefix_path(NULL); | ||
366 | + pseudo_path = pseudo_data_path(NULL); | ||
367 | if (pseudo_dir_fd == -1) { | ||
368 | if (pseudo_path) { | ||
369 | pseudo_dir_fd = open(pseudo_path, O_RDONLY); | ||
370 | Index: git/pseudo_wrappers.c | ||
371 | =================================================================== | ||
372 | --- git.orig/pseudo_wrappers.c 2010-07-25 00:21:35.263587003 +0100 | ||
373 | +++ git/pseudo_wrappers.c 2010-07-25 00:29:03.052345996 +0100 | ||
374 | @@ -180,7 +180,7 @@ | ||
375 | * value for cwd. | ||
376 | */ | ||
377 | pseudo_client_reset(); | ||
378 | - pseudo_path = pseudo_prefix_path(NULL); | ||
379 | + pseudo_path = pseudo_data_path(NULL); | ||
380 | if (pseudo_dir_fd == -1) { | ||
381 | if (pseudo_path) { | ||
382 | pseudo_dir_fd = open(pseudo_path, O_RDONLY); | ||