Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 840 lines (679 sloc) 18.086 kb
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
24
25 #include "common-internal.h"
26 #include "source_interpreter.h"
27 #include "util.h"
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
28 #include "connection-protected.h"
29 #include "thread.h"
30 #include "bogotime.h"
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
31 #include "spawner.h"
32 #include "logger_writer.h"
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
33
34 #include <sys/types.h>
35 #include <unistd.h>
7bf81a3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2258 5dc97367-9…
alobbs authored
36 #include <signal.h>
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
37
38 #define ENTRIES "source,src,interpreter"
f9c1534 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2285 5dc97367-9…
alobbs authored
39
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
40 #define DEFAULT_TIMEOUT 10
41 #define GRNAM_BUF_LEN 8192
42 #define MAX_SPAWN_FAILS_IN_A_ROW 5
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
43
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
44 static void interpreter_free (void *src);
45
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
46 #define source_is_unresponsive(src) \
47 (cherokee_bogonow_now > (src)->spawning_since + (src)->timeout)
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
48
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
49 ret_t
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
50 cherokee_source_interpreter_new (cherokee_source_interpreter_t **src)
51 {
52 CHEROKEE_NEW_STRUCT(n, source_interpreter);
53
54 cherokee_source_init (SOURCE(n));
55 cherokee_buffer_init (&n->interpreter);
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
56 cherokee_buffer_init (&n->change_user_name);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
57
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
58 n->custom_env = NULL;
59 n->custom_env_len = 0;
60 n->env_inherited = true;
61 n->debug = false;
62 n->pid = -1;
63 n->timeout = DEFAULT_TIMEOUT;
64 n->change_user = -1;
65 n->change_group = -1;
66 n->spawn_type = spawn_unknown;
67 n->spawning_since = 0;
68 n->spawning_since_fails = 0;
69 n->last_connect = 0;
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
70
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
71 SOURCE(n)->type = source_interpreter;
72 SOURCE(n)->free = (cherokee_func_free_t)interpreter_free;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
73
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
74 CHEROKEE_MUTEX_INIT (&n->launching_mutex, NULL);
75 n->launching = false;
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
76
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
77 *src = n;
78 return ret_ok;
79 }
80
81
82 static void
aca1459 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2150 5dc97367-9…
alobbs authored
83 free_custom_env (void *ptr)
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
84 {
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
85 cuint_t i;
86 cherokee_source_interpreter_t *src = ptr;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
87
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
88 for (i=0; src->custom_env[i] != NULL; i++) {
89 free (src->custom_env[i]);
90 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
91
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
92 free (src->custom_env);
93 }
94
95
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
96 static void
1512210 @alobbs Clean up. Nothing important.
alobbs authored
97 kill_pid (cherokee_source_interpreter_t *src)
98 {
99 if (src->pid <= 0)
100 return;
101
102 TRACE(ENTRIES, "Killing %s, pid=%d\n", src->interpreter.buf, src->pid);
103 kill (src->pid, SIGTERM);
104 }
105
106 static void
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
107 interpreter_free (void *ptr)
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
108 {
c69a7c8 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@852 5dc97367-97…
alobbs authored
109 cherokee_source_interpreter_t *src = ptr;
110
111 /* Only frees its stuff, the rest will be freed by
112 * cherokee_source_t.
113 */
1512210 @alobbs Clean up. Nothing important.
alobbs authored
114 kill_pid (src);
7bf81a3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2258 5dc97367-9…
alobbs authored
115
6cda111 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2910 5dc97367-9…
alobbs authored
116 cherokee_buffer_mrproper (&src->interpreter);
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
117 cherokee_buffer_mrproper (&src->change_user_name);
6cda111 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2910 5dc97367-9…
alobbs authored
118
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
119 if (src->custom_env)
aca1459 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2150 5dc97367-9…
alobbs authored
120 free_custom_env (src);
9636b82 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2061 5dc97367-9…
alobbs authored
121
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
122 CHEROKEE_MUTEX_DESTROY (&src->launching_mutex);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
123 }
124
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
125 static char *
126 find_next_stop (char *p)
127 {
128 char *s;
129 char *w;
130
131 s = strchr (p, '/');
132 w = strchr (p, ' ');
133
134 if ((s == NULL) && (w == NULL))
135 return NULL;
136
137 if (w == NULL)
138 return s;
139 if (s == NULL)
140 return w;
141
142 return (w > s) ? s : w;
143 }
144
145 static ret_t
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
146 check_interpreter_full (cherokee_buffer_t *fullpath)
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
147 {
148 int re;
149 struct stat inter;
150 char *p;
151 char tmp;
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
152 const char *end = fullpath->buf + fullpath->len;
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
153
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
154 p = find_next_stop (fullpath->buf + 1);
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
155 if (p == NULL)
156 return ret_error;
157
158 while (p <= end) {
159 /* Set a temporal end */
160 tmp = *p;
161 *p = '\0';
162
163 /* Does the file exist? */
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
164 re = cherokee_stat (fullpath->buf, &inter);
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
165 if ((re == 0) &&
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
166 (! S_ISDIR(inter.st_mode)))
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
167 {
168 *p = tmp;
169 return ret_ok;
170 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
171
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
172 *p = tmp;
173
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
174 /* Exit if already reached the end */
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
175 if (p >= end)
176 break;
177
178 /* Find the next position */
179 p = find_next_stop (p+1);
180 if (p == NULL)
181 p = (char *)end;
182 }
183
184 return ret_error;
185 }
186
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
187
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
188 static ret_t
189 check_interpreter_path (cherokee_buffer_t *partial_path)
190 {
191 ret_t ret;
192 char *p;
193 char *colon;
194 char *path;
195 cherokee_buffer_t fullpath = CHEROKEE_BUF_INIT;
196
c43d737 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2892 5dc97367-9…
alobbs authored
197 p = getenv("PATH");
198 if (p == NULL)
199 return ret_error;
200
201 path = strdup (p);
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
202 if (path == NULL)
203 return ret_error;
204
205 p = path;
206 do {
207 colon = strchr(p, ':');
208 if (colon != NULL)
209 *colon = '\0';
210
211 cherokee_buffer_clean (&fullpath);
212 cherokee_buffer_add (&fullpath, p, strlen(p));
213 cherokee_buffer_add_char (&fullpath, '/');
214 cherokee_buffer_add_buffer (&fullpath, partial_path);
215
216 ret = check_interpreter_full (&fullpath);
217 if (ret == ret_ok)
218 goto done;
219
220 if (colon == NULL)
221 break;
222
223 p = colon + 1;
224 } while (true);
225
226 ret = ret_not_found;
227
228 done:
229 cherokee_buffer_mrproper (&fullpath);
230 free (path);
231
232 return ret;
233 }
234
235 static ret_t
2c6976b @alobbs Ensure that Interpreter commands are not prepended are not prepended
alobbs authored
236 command_has_env_variables (cherokee_buffer_t *command)
237 {
238 int n = 0;
239 cherokee_boolean_t equal = false;
240
241 while (n < command->len) {
242 if (command->buf[n] == '=') {
243 equal = true;
244 } else if (command->buf[n] == ' ') {
245 return (equal)? ret_error : ret_ok;
246 }
247 n++;
248 }
249
250 return ret_ok;
251 }
252
253 static ret_t
95c9bc3 @alobbs Little clean up over the previous patch
alobbs authored
254 check_interpreter (cherokee_source_interpreter_t *src)
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
255 {
256 ret_t ret;
257
258 if (src->interpreter.buf[0] == '/') {
259 ret = check_interpreter_full (&src->interpreter);
2c6976b @alobbs Ensure that Interpreter commands are not prepended are not prepended
alobbs authored
260 } else {
261 ret = check_interpreter_path (&src->interpreter);
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
262 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
263
2c6976b @alobbs Ensure that Interpreter commands are not prepended are not prepended
alobbs authored
264 return ret;
55ca816 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2868 5dc97367-9…
alobbs authored
265 }
266
453c4de @alobbs The environment variables of the information sources can contain
alobbs authored
267
268 static ret_t
269 replace_environment_variables (cherokee_buffer_t *buf)
270 {
271 char *dollar;
272 char *p;
273 char *val;
274 cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
275
276 do {
277 /* Find $
278 */
279 dollar = strchr (buf->buf, '$');
280 if (dollar == NULL) {
281 goto out;
282 }
283
284 /* End of the variable name
285 */
286 p = dollar + 1;
287 while ((*p == '_') ||
288 ((*p >= '0') && (*p <= '9')) ||
289 ((*p >= 'A') && (*p <= 'Z')) ||
290 ((*p >= 'a') && (*p <= 'z')))
291 {
292 p++;
293 }
294
295 /* Call getenv
296 */
297 cherokee_buffer_clean (&tmp);
298 cherokee_buffer_add (&tmp, dollar, p-dollar);
299
300 val = getenv (tmp.buf + 1);
301
302 /* Replacement
303 */
304 if (val != NULL) {
305 cherokee_buffer_replace_string (buf, tmp.buf, tmp.len, val, strlen(val));
306 } else {
307 cherokee_buffer_remove_string (buf, tmp.buf, tmp.len);
308 }
309
310 } while (true);
311
312 out:
313 cherokee_buffer_mrproper (&tmp);
314 return ret_ok;
315 }
316
317
318 static ret_t
319 add_env (cherokee_source_interpreter_t *src,
320 cherokee_buffer_t *env,
321 cherokee_buffer_t *val_orig)
322 {
323 ret_t ret;
324 int entry_len;
325 char *entry;
326 cherokee_buffer_t *val = NULL;
327
328 /* Replace $ENVs
329 */
330 cherokee_buffer_dup (val_orig, &val);
331
332 ret = replace_environment_variables (val);
333 if (ret != ret_ok) {
334 ret = ret_error;
335 goto error;
336 }
337
338 /* Build the env entry
339 */
340 entry_len = env->len + val->len + 2;
341
342 entry = (char *) malloc (entry_len);
eb5e52c @alobbs "Pointer 'src->custom_env' returned from call to function 'malloc' at
alobbs authored
343 if (unlikely (entry == NULL)) {
453c4de @alobbs The environment variables of the information sources can contain
alobbs authored
344 ret = ret_nomem;
345 goto error;
346 }
347
348 snprintf (entry, entry_len, "%s=%s", env->buf, val->buf);
349 TRACE(ENTRIES, "Adding env: %s\n", entry);
350
351 /* Add it into the env array
352 */
353 if (src->custom_env_len == 0) {
354 src->custom_env = malloc (sizeof (char *) * 2);
355 } else {
356 src->custom_env = realloc (src->custom_env, (src->custom_env_len + 2) * sizeof (char *));
357 }
358
eb5e52c @alobbs "Pointer 'src->custom_env' returned from call to function 'malloc' at
alobbs authored
359 if (unlikely (src->custom_env == NULL)) {
360 ret = ret_nomem;
361 free (entry);
362 goto error;
363 }
364
365 src->custom_env_len += 1;
453c4de @alobbs The environment variables of the information sources can contain
alobbs authored
366 src->custom_env[src->custom_env_len - 1] = entry;
367 src->custom_env[src->custom_env_len] = NULL;
368
369 cherokee_buffer_free (val);
370 return ret_ok;
371
372 error:
373 cherokee_buffer_free (val);
374 return ret;
375 }
376
377
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
378 ret_t
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
379 cherokee_source_interpreter_configure (cherokee_source_interpreter_t *src,
380 cherokee_config_node_t *conf,
381 int prio)
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
382 {
383 ret_t ret;
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
384 int val;
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
385 cherokee_list_t *i, *j;
386 cherokee_config_node_t *child;
387
388 /* Configure the base class
389 */
390 ret = cherokee_source_configure (SOURCE(src), conf);
a274737 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2863 5dc97367-9…
alobbs authored
391 if (ret != ret_ok)
392 return ret;
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
393
394 /* Interpreter parameters
395 */
396 cherokee_config_node_foreach (i, conf) {
397 child = CONFIG_NODE(i);
398
399 if (equal_buf_str (&child->key, "interpreter")) {
400 cherokee_buffer_add_buffer (&src->interpreter, &child->val);
401
4df058e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2026 5dc97367-9…
alobbs authored
402 } else if (equal_buf_str (&child->key, "debug")) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
403 ret = cherokee_atob (child->val.buf, &src->debug);
404 if (ret != ret_ok) return ret_error;
4df058e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2026 5dc97367-9…
alobbs authored
405
f9c1534 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2285 5dc97367-9…
alobbs authored
406 } else if (equal_buf_str (&child->key, "timeout")) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
407 ret = cherokee_atoi (child->val.buf, &val);
408 if (ret != ret_ok) return ret_error;
409 src->timeout = val;
f9c1534 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2285 5dc97367-9…
alobbs authored
410
9043538 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2885 5dc97367-9…
alobbs authored
411 } else if (equal_buf_str (&child->key, "user")) {
e7b8481 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2270 5dc97367-9…
alobbs authored
412 struct passwd pwd;
413 char tmp[1024];
414
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
415 cherokee_buffer_add_buffer (&src->change_user_name, &child->val);
416
5d975d1 @alobbs Clean up: Replaces some custom code by a call to cherokee_getpwnam_u…
alobbs authored
417 ret = cherokee_getpwnam_uid (child->val.buf, &pwd, tmp, sizeof(tmp));
e7b8481 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2270 5dc97367-9…
alobbs authored
418 if ((ret != ret_ok) || (pwd.pw_dir == NULL)) {
5d975d1 @alobbs Clean up: Replaces some custom code by a call to cherokee_getpwnam_u…
alobbs authored
419 LOG_CRITICAL (CHEROKEE_ERROR_SRC_INTER_NO_USER, child->val.buf, prio);
420 return ret_error;
e7b8481 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2270 5dc97367-9…
alobbs authored
421 }
422
423 src->change_user = pwd.pw_uid;
424
a6b0bd2 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3185 5dc97367-9…
alobbs authored
425 if (src->change_group == -1) {
426 src->change_group = pwd.pw_gid;
427 }
428
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
429 } else if (equal_buf_str (&child->key, "group")) {
430 struct group grp;
f7fcea6 @alobbs Same patch as before.. for source_interpreter.c.
alobbs authored
431 char tmp[GRNAM_BUF_LEN];
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
432
3ff6f3c @alobbs Groups could only be defined by name. GIDs are alright now too.
alobbs authored
433 ret = cherokee_getgrnam_gid (child->val.buf, &grp, tmp, sizeof(tmp));
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
434 if (ret != ret_ok) {
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
435 LOG_CRITICAL (CHEROKEE_ERROR_SRC_INTER_NO_GROUP, conf->val.buf, prio);
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
436 return ret_error;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
437 }
438
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
439 src->change_group = grp.gr_gid;
440
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
441 } else if (equal_buf_str (&child->key, "env")) {
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
442 cherokee_config_node_foreach (j, child) {
443 cherokee_config_node_t *child2 = CONFIG_NODE(j);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
444
453c4de @alobbs The environment variables of the information sources can contain
alobbs authored
445 ret = add_env (src, &child2->key, &child2->val);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
446 if (ret != ret_ok) return ret;
447 }
9b3cd10 @alobbs Be slightly smarter when trying to figure whether to inherit the
alobbs authored
448
449 } else if (equal_buf_str (&child->key, "env_inherited")) {
450 /* Handled later on */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
451 }
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
452 }
453
9b3cd10 @alobbs Be slightly smarter when trying to figure whether to inherit the
alobbs authored
454 /* Inherited Environment
455 */
456 ret = cherokee_config_node_get (conf, "env_inherited", &child);
457 if (ret == ret_ok) {
2459250 @alobbs Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
458 ret = cherokee_atob (child->val.buf, &src->env_inherited);
459 if (ret != ret_ok) return ret_error;
9b3cd10 @alobbs Be slightly smarter when trying to figure whether to inherit the
alobbs authored
460 } else {
461 src->env_inherited = (src->custom_env_len == 0);
462 }
463
a274737 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2863 5dc97367-9…
alobbs authored
464 /* Sanity check
465 */
466 if (cherokee_buffer_is_empty (&src->interpreter)) {
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
467 LOG_CRITICAL (CHEROKEE_ERROR_SRC_INTER_EMPTY_INTERPRETER, prio);
a274737 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2863 5dc97367-9…
alobbs authored
468 return ret_error;
469 }
470
2c6976b @alobbs Ensure that Interpreter commands are not prepended are not prepended
alobbs authored
471 ret = command_has_env_variables (&src->interpreter);
472 if (ret != ret_ok) {
473 LOG_CRITICAL (CHEROKEE_ERROR_SRC_INTER_ENV_IN_COMMAND, prio, src->interpreter.buf);
474 return ret_error;
475 }
476
95c9bc3 @alobbs Little clean up over the previous patch
alobbs authored
477 ret = check_interpreter (src);
ad3474f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2886 5dc97367-9…
alobbs authored
478 if (ret != ret_ok) {
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
479 LOG_ERROR (CHEROKEE_ERROR_SRC_INTER_NO_INTERPRETER, src->interpreter.buf, prio);
0d3a69e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2867 5dc97367-9…
alobbs authored
480 return ret_error;
ad3474f @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2886 5dc97367-9…
alobbs authored
481 }
a274737 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2863 5dc97367-9…
alobbs authored
482
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
483 return ret_ok;
484 }
485
486
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
487 static ret_t
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
488 _spawn_shm (cherokee_source_interpreter_t *src,
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
489 cherokee_logger_writer_t *error_writer)
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
490 {
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
491 ret_t ret;
492 char **envp;
493 char *empty_envp[] = {NULL};
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
494
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
495 /* Sanity check
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
496 */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
497 if (cherokee_buffer_is_empty (&src->interpreter))
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
498 return ret_not_found;
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
499
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
500 /* Maybe set a custom enviroment variable set
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
501 */
502 envp = (src->custom_env) ? src->custom_env : empty_envp;
8b6c0ba @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2450 5dc97367-9…
alobbs authored
503
d87e0cc @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3169 5dc97367-9…
alobbs authored
504 /* If a user isn't specified, use the same one..
505 */
506 if (src->change_user == -1) {
74e2a5b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3209 5dc97367-9…
alobbs authored
507 src->change_user = getuid();
508 src->change_group = getgid();
d87e0cc @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3169 5dc97367-9…
alobbs authored
509 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
510
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
511 /* Invoke the spawn mechanism
512 */
513 ret = cherokee_spawner_spawn (&src->interpreter,
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
514 &src->change_user_name,
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
515 src->change_user,
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
516 src->change_group,
666305d @alobbs Adds a new option to allow information sources to inherit the server's
alobbs authored
517 src->env_inherited,
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
518 envp,
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
519 error_writer,
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
520 &src->pid);
541f55a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3325 5dc97367-9…
alobbs authored
521 switch (ret) {
522 case ret_ok:
523 break;
524 case ret_eagain:
525 return ret_eagain;
526 default:
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
527 return ret_error;
528 }
8b6c0ba @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2450 5dc97367-9…
alobbs authored
529
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
530 return ret_ok;
531 }
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
532
533
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
534 static ret_t
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
535 _spawn_local (cherokee_source_interpreter_t *src,
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
536 cherokee_logger_writer_t *error_writer)
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
537 {
538 int re;
a26f980 @alobbs The server failed to launch some applications when its virtual server
alobbs authored
539 int tmp_fd;
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
540 char **envp;
541 const char *argv[] = {"sh", "-c", NULL, NULL};
542 int child = -1;
543 char *empty_envp[] = {NULL};
544 cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
2a5defc @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@506 5dc97367-97…
alobbs authored
545
7bf81a3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2258 5dc97367-9…
alobbs authored
546 /* If there is a previous instance running, kill it
547 */
1512210 @alobbs Clean up. Nothing important.
alobbs authored
548 kill_pid (src);
7bf81a3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2258 5dc97367-9…
alobbs authored
549
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
550 /* Maybe set a custom enviroment variable set
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
551 */
552 envp = (src->custom_env) ? src->custom_env : empty_envp;
553
554 /* Execute the FastCGI server
555 */
556 cherokee_buffer_add_va (&tmp, "exec %s", src->interpreter.buf);
666305d @alobbs Adds a new option to allow information sources to inherit the server's
alobbs authored
557 TRACE (ENTRIES, "Spawn: /bin/sh -c \"exec %s\"\n", src->interpreter.buf);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
558
559 #ifndef _WIN32
560 child = fork();
561 #endif
562 switch (child) {
563 case 0:
e7b8481 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2270 5dc97367-9…
alobbs authored
564 /* Change user if requested
565 */
a182eab @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3183 5dc97367-9…
alobbs authored
566 if (! cherokee_buffer_is_empty (&src->change_user_name)) {
567 initgroups (src->change_user_name.buf, src->change_user);
568 }
569
570 if (src->change_group != -1) {
571 setgid (src->change_group);
572 }
573
574 if (src->change_user != -1) {
e7b8481 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2270 5dc97367-9…
alobbs authored
575 setuid (src->change_user);
576 }
577
b79c48f @alobbs Implements cherokee_reset_signals(). The Information Source spawner
alobbs authored
578 /* Reset signals
579 */
580 cherokee_reset_signals();
581
eba5b56 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2388 5dc97367-9…
alobbs authored
582 /* Redirect/Close stderr and stdout
32e6fe4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1968 5dc97367-9…
alobbs authored
583 */
4df058e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2026 5dc97367-9…
alobbs authored
584 if (! src->debug) {
a26f980 @alobbs The server failed to launch some applications when its virtual server
alobbs authored
585 cherokee_fd_close (STDOUT_FILENO);
586 cherokee_fd_close (STDERR_FILENO);
587
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
588 if ((error_writer != NULL) &&
589 (error_writer->fd != -1))
590 {
591 dup2 (error_writer->fd, STDOUT_FILENO);
592 dup2 (error_writer->fd, STDERR_FILENO);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
593 }
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
594 else {
a68f41b @alobbs Merges the Front-Line Cache branch.
alobbs authored
595 tmp_fd = cherokee_open ("/dev/null", O_WRONLY, 0700);
a26f980 @alobbs The server failed to launch some applications when its virtual server
alobbs authored
596 if (tmp_fd != -1) {
597 dup2 (tmp_fd, STDOUT_FILENO);
598 dup2 (tmp_fd, STDERR_FILENO);
599 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
600 }
4df058e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2026 5dc97367-9…
alobbs authored
601 }
32e6fe4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1968 5dc97367-9…
alobbs authored
602
b90a109 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2034 5dc97367-9…
alobbs authored
603 argv[2] = (char *)tmp.buf;
666305d @alobbs Adds a new option to allow information sources to inherit the server's
alobbs authored
604 if (src->env_inherited) {
5ced005 @alobbs Handles EINTR while invoking execv*()
alobbs authored
605 do {
606 re = execv ("/bin/sh", (char **)argv);
607 } while (errno == EINTR);
666305d @alobbs Adds a new option to allow information sources to inherit the server's
alobbs authored
608 } else {
5ced005 @alobbs Handles EINTR while invoking execv*()
alobbs authored
609 do {
610 re = execve ("/bin/sh", (char **)argv, envp);
611 } while (errno == EINTR);
666305d @alobbs Adds a new option to allow information sources to inherit the server's
alobbs authored
612 }
613
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
614 if (re < 0) {
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
615 LOG_ERROR (CHEROKEE_ERROR_SRC_INTER_SPAWN, tmp.buf);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
616 exit (1);
617 }
618
cda4134 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@935 5dc97367-97…
alobbs authored
619 exit ((re == 0) ? 0 : 1);
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
620 case -1:
621 goto error;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
622
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
623 default:
7bf81a3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2258 5dc97367-9…
alobbs authored
624 src->pid = child;
625
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
626 sleep (1);
627 break;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
628
7b0e48a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…
alobbs authored
629 }
630
631 cherokee_buffer_mrproper (&tmp);
632 return ret_ok;
633
634 error:
635 cherokee_buffer_mrproper (&tmp);
636 return ret_error;
637 }
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
638
639
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
640 ret_t
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
641 cherokee_source_interpreter_spawn (cherokee_source_interpreter_t *src,
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
642 cherokee_logger_writer_t *error_writer)
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
643 {
644 ret_t ret;
645
646 /* Sanity check
647 */
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
648 if (cherokee_buffer_is_empty (&src->interpreter)) {
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
649 return ret_not_found;
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
650 }
651
652 /* Try with SHM first
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
653 */
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
654 if ((src->spawn_type == spawn_shm) ||
655 (src->spawn_type == spawn_unknown))
541f55a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3325 5dc97367-9…
alobbs authored
656 {
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
657 ret = _spawn_shm (src, error_writer);
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
658 if (ret == ret_ok) {
659 if (src->spawn_type == spawn_unknown) {
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
660 src->spawn_type = spawn_shm;
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
661 }
662
663 return ret_ok;
664
665 } else if (ret == ret_eagain) {
666 return ret_eagain;
667 }
668 if (src->spawn_type == spawn_shm) {
669 return ret_error;
670 }
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
671 }
672
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
673 /* No luck, go 'local' then..
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
674 */
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
675 if (src->spawn_type == spawn_unknown) {
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
676 src->spawn_type = spawn_local;
b7606da @alobbs Once the SHM spawning method has been successfully used once, do not
alobbs authored
677 }
678
c5fe3a4 @alobbs Errors are not longer written through the logger objects. They are
alobbs authored
679 ret = _spawn_local (src, error_writer);
468a464 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3168 5dc97367-9…
alobbs authored
680 if (ret != ret_ok) {
681 return ret;
682 }
683
684 return ret_ok;
685 }
686
687
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
688 ret_t
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
689 cherokee_source_interpreter_connect_polling (cherokee_source_interpreter_t *src,
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
690 cherokee_socket_t *socket,
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
691 cherokee_connection_t *conn)
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
692 {
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
693 int re;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
694 ret_t ret;
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
695 int unlocked;
696 int kill_prev;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
697
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
698 /* Connect
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
699 */
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
700 ret = cherokee_source_connect (SOURCE(src), socket);
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
701 switch (ret) {
702 case ret_ok:
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
703 /* connected */
704 if (src->spawning_since != 0) {
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
705 src->spawning_since = 0;
706 src->spawning_since_fails = 0;
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
707 }
708 src->last_connect = cherokee_bogonow_now;
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
709 TRACE (ENTRIES, "Connected successfully fd=%d\n", socket->socket);
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
710 return ret_ok;
711
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
712 case ret_eagain:
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
713 /* wait for the fd */
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
714 ret = cherokee_thread_deactive_to_polling (CONN_THREAD(conn),
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
715 conn, SOCKET_FD(socket),
716 FDPOLL_MODE_WRITE, false);
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
717 if (ret != ret_ok) {
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
718 return ret_error;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
719 }
720 return ret_eagain;
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
721
722 case ret_deny:
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
723 case ret_error:
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
724 /* reset by peer: spawn process? */
725 TRACE (ENTRIES, "Connection refused (closing fd=%d)\n", socket->socket);
726 cherokee_socket_close (socket);
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
727 break;
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
728
729 default:
730 cherokee_socket_close (socket);
731 RET_UNKNOWN(ret);
732 return ret_error;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
733 }
734
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
735 /* Spawn a new process
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
736 */
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
737 unlocked = CHEROKEE_MUTEX_TRY_LOCK (&src->launching_mutex);
738 if (unlocked) {
739 cherokee_connection_sleep (conn, 1000);
740 return ret_eagain;
741 }
b9f9a9a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2072 5dc97367-9…
alobbs authored
742
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
743 if (src->spawning_since == 0) {
8dbf0dc @alobbs Error log management clean up. It should work better now.
alobbs authored
744 cherokee_logger_writer_t *error_writer = NULL;
745
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
746 /* Check re-try limit */
747 if (src->spawning_since_fails >= MAX_SPAWN_FAILS_IN_A_ROW) {
42f9994 @alobbs Adds a new tracing point to inform about reiterative fails to spawn
alobbs authored
748 TRACE (ENTRIES, "Failed to launch the interpreter %d consecutive times. Giving up now.\n",
749 src->spawning_since_fails);
750
751 src->spawning_since_fails = 0;
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
752 ret = ret_error;
753 goto out;
754 }
755
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
756 /* Kill prev (unresponsive) interpreter? */
757 kill_prev = ((src->pid > 0) && (source_is_unresponsive(src)));
758 if (! kill_prev) {
759 src->pid = -1;
760 }
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
761
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
762 /* Spawn */
8dbf0dc @alobbs Error log management clean up. It should work better now.
alobbs authored
763 ret = cherokee_virtual_server_get_error_log (CONN_VSRV(conn), &error_writer);
764 if (ret != ret_ok) {
0398aa4 @alobbs "Variable 'src->launching_mutex' locked on line 735 was not unlocked."
alobbs authored
765 ret = ret_error;
766 goto out;
8dbf0dc @alobbs Error log management clean up. It should work better now.
alobbs authored
767 }
768
769 ret = cherokee_source_interpreter_spawn (src, error_writer);
541f55a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3325 5dc97367-9…
alobbs authored
770 switch (ret) {
771 case ret_ok:
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
772 src->spawning_since = cherokee_bogonow_now;
773 ret = ret_eagain;
774 goto out;
775
541f55a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3325 5dc97367-9…
alobbs authored
776 case ret_eagain:
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
777 cherokee_connection_sleep (conn, 1000);
541f55a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3325 5dc97367-9…
alobbs authored
778 ret = ret_eagain;
779 goto out;
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
780
541f55a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3325 5dc97367-9…
alobbs authored
781 default:
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
782 if (src->interpreter.buf) {
783 TRACE (ENTRIES, "Couldn't spawn: %s\n", src->interpreter.buf);
784 } else {
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
785 TRACE (ENTRIES, "No interpreter to be spawned %s", "\n");
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
786 }
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
787 ret = ret_error;
788 goto out;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
789 }
790
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
791 SHOULDNT_HAPPEN;
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
792 ret = ret_error;
793 goto out;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
794 }
795
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
796 /* Is the launching process death?
797 */
798 if (src->pid > 0) {
799 re = kill (src->pid, 0);
a75653e @skarcha Death processes were not being properly detected while launching new …
skarcha authored
800 if ((re != 0) && (errno == ESRCH)) {
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
801 /* It's death */
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
802 TRACE (ENTRIES, "PID %d is already death\n", src->pid);
803
048aa59 @alobbs Miscellaneous spawner fixes.
alobbs authored
804 src->pid = -1;
805
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
806 src->spawning_since = 0;
807 src->spawning_since_fails += 1;
808
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
809 ret = ret_eagain;
810 goto out;
811 }
812 }
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
813
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
814 /* Is it unresponsive?
815 */
816 if (source_is_unresponsive(src)) {
5fc51f7 @alobbs This patch tries to address a spawning issue where the server was
alobbs authored
817 src->spawning_since = 0;
818 src->spawning_since_fails += 1;
819
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
820 ret = ret_eagain;
821 goto out;
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
822 }
823
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
824 /* Spawning on-going
825 */
826 cherokee_connection_sleep (conn, 1000);
827 ret = ret_eagain;
828
829 out:
739b5aa @alobbs Raise the connection timeout limit when it's trying to access a
alobbs authored
830 /* Raise conn's timeout? */
831 if ((src->spawning_since != 0) &&
832 (src->spawning_since + src->timeout > conn->timeout))
833 {
834 conn->timeout = src->spawning_since + src->timeout + 1;
835 }
836
83990a0 @alobbs A fragment of the spawning mechanism has been rewritten. This new
alobbs authored
837 CHEROKEE_MUTEX_UNLOCK (&src->launching_mutex);
471c8b4 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2065 5dc97367-9…
alobbs authored
838 return ret;
5695e23 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1849 5dc97367-9…
alobbs authored
839 }
Something went wrong with that request. Please try again.