diff options
-rw-r--r-- | src/arm/Makefile.am | 3 | ||||
-rw-r--r-- | src/arm/arm_api.c | 32 | ||||
-rw-r--r-- | src/arm/do_start_process.c | 94 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.c | 87 | ||||
-rw-r--r-- | src/arm/test_arm_api_data.conf | 1 | ||||
-rw-r--r-- | src/arm/test_exponential_backoff.c | 2 |
6 files changed, 138 insertions, 81 deletions
diff --git a/src/arm/Makefile.am b/src/arm/Makefile.am index 8cd9cc0db..f9c2a3289 100644 --- a/src/arm/Makefile.am +++ b/src/arm/Makefile.am | |||
@@ -68,4 +68,5 @@ test_exponential_backoff_LDADD = \ | |||
68 | $(top_builddir)/src/util/libgnunetutil.la | 68 | $(top_builddir)/src/util/libgnunetutil.la |
69 | 69 | ||
70 | EXTRA_DIST = \ | 70 | EXTRA_DIST = \ |
71 | test_arm_api_data.conf | 71 | test_arm_api_data.conf \ |
72 | do_start_process.c | ||
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 847d838cd..138c95df4 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -143,6 +143,8 @@ struct RequestContext | |||
143 | 143 | ||
144 | }; | 144 | }; |
145 | 145 | ||
146 | #include "do_start_process.c" | ||
147 | |||
146 | 148 | ||
147 | /** | 149 | /** |
148 | * A client specifically requested starting of ARM itself. | 150 | * A client specifically requested starting of ARM itself. |
@@ -161,6 +163,8 @@ arm_service_report (void *cls, | |||
161 | pid_t pid; | 163 | pid_t pid; |
162 | char *binary; | 164 | char *binary; |
163 | char *config; | 165 | char *config; |
166 | char *loprefix; | ||
167 | char *lopostfix; | ||
164 | 168 | ||
165 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 169 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
166 | { | 170 | { |
@@ -181,9 +185,15 @@ arm_service_report (void *cls, | |||
181 | "gnunet-service-arm"); | 185 | "gnunet-service-arm"); |
182 | #endif | 186 | #endif |
183 | /* FIXME: should we check that HOSTNAME for 'arm' is localhost? */ | 187 | /* FIXME: should we check that HOSTNAME for 'arm' is localhost? */ |
184 | /* FIXME: interpret 'PREFIX' and 'OPTIONS' configuration options | 188 | |
185 | (as done by 'gnunet-service-arm.c::start_process') */ | 189 | if (GNUNET_OK != |
186 | /* start service */ | 190 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
191 | "arm", "PREFIX", &loprefix)) | ||
192 | loprefix = GNUNET_strdup (""); | ||
193 | if (GNUNET_OK != | ||
194 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | ||
195 | "arm", "OPTIONS", &lopostfix)) | ||
196 | lopostfix = GNUNET_strdup (""); | ||
187 | if (GNUNET_OK != | 197 | if (GNUNET_OK != |
188 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 198 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
189 | "arm", | 199 | "arm", |
@@ -197,6 +207,8 @@ arm_service_report (void *cls, | |||
197 | if (pos->callback != NULL) | 207 | if (pos->callback != NULL) |
198 | pos->callback (pos->cls, GNUNET_SYSERR); | 208 | pos->callback (pos->cls, GNUNET_SYSERR); |
199 | GNUNET_free (pos); | 209 | GNUNET_free (pos); |
210 | GNUNET_free (loprefix); | ||
211 | GNUNET_free (lopostfix); | ||
200 | return; | 212 | return; |
201 | } | 213 | } |
202 | if (GNUNET_OK != | 214 | if (GNUNET_OK != |
@@ -211,15 +223,23 @@ arm_service_report (void *cls, | |||
211 | pos->callback (pos->cls, GNUNET_SYSERR); | 223 | pos->callback (pos->cls, GNUNET_SYSERR); |
212 | GNUNET_free (binary); | 224 | GNUNET_free (binary); |
213 | GNUNET_free (pos); | 225 | GNUNET_free (pos); |
226 | GNUNET_free (loprefix); | ||
227 | GNUNET_free (lopostfix); | ||
214 | return; | 228 | return; |
215 | } | 229 | } |
216 | pid = GNUNET_OS_start_process (NULL, NULL, binary, binary, "-d", "-c", config, | 230 | pid = do_start_process (loprefix, |
231 | binary, | ||
232 | "-c", config, | ||
217 | #if DEBUG_ARM | 233 | #if DEBUG_ARM |
218 | "-L", "DEBUG", | 234 | "-L", "DEBUG", |
219 | #endif | 235 | #endif |
220 | NULL); | 236 | "-d", |
237 | lopostfix, | ||
238 | NULL); | ||
221 | GNUNET_free (binary); | 239 | GNUNET_free (binary); |
222 | GNUNET_free (config); | 240 | GNUNET_free (config); |
241 | GNUNET_free (loprefix); | ||
242 | GNUNET_free (lopostfix); | ||
223 | if (pid == -1) | 243 | if (pid == -1) |
224 | { | 244 | { |
225 | if (pos->callback != NULL) | 245 | if (pos->callback != NULL) |
diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c new file mode 100644 index 000000000..357d39920 --- /dev/null +++ b/src/arm/do_start_process.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /** | ||
2 | * Actually start a process. All of the arguments given to this | ||
3 | * function are strings that are used for the "argv" array. However, | ||
4 | * if those strings contain spaces, the given argument is split into | ||
5 | * multiple argv entries without spaces. Similarly, if an argument is | ||
6 | * the empty string, it is skipped. This function has the inherent | ||
7 | * limitation that it does NOT allow passing command line arguments | ||
8 | * with spaces to the new process. | ||
9 | * | ||
10 | * @param first_arg first argument for argv (may be an empty string) | ||
11 | * @param ... more arguments, NULL terminated | ||
12 | * @return PID of the started process, -1 on error | ||
13 | */ | ||
14 | static pid_t | ||
15 | do_start_process (const char *first_arg, ...) | ||
16 | { | ||
17 | va_list ap; | ||
18 | char **argv; | ||
19 | unsigned int argv_size; | ||
20 | const char *arg; | ||
21 | const char *rpos; | ||
22 | char *pos; | ||
23 | char *cp; | ||
24 | const char *last; | ||
25 | pid_t pid; | ||
26 | |||
27 | argv_size = 1; | ||
28 | va_start (ap, first_arg); | ||
29 | arg = first_arg; | ||
30 | last = NULL; | ||
31 | do | ||
32 | { | ||
33 | rpos = arg; | ||
34 | while ('\0' != *rpos) | ||
35 | { | ||
36 | if (' ' == *rpos) | ||
37 | { | ||
38 | if (last != NULL) | ||
39 | argv_size++; | ||
40 | last = NULL; | ||
41 | while (' ' == *rpos) | ||
42 | rpos++; | ||
43 | } | ||
44 | if ( (last == NULL) && (*rpos != '\0') ) | ||
45 | last = rpos; | ||
46 | if (*rpos != '\0') | ||
47 | rpos++; | ||
48 | } | ||
49 | if (last != NULL) | ||
50 | argv_size++; | ||
51 | } | ||
52 | while (NULL != (arg = (va_arg (ap, const char*)))); | ||
53 | va_end (ap); | ||
54 | |||
55 | argv = GNUNET_malloc (argv_size * sizeof (char *)); | ||
56 | argv_size = 0; | ||
57 | va_start (ap, first_arg); | ||
58 | arg = first_arg; | ||
59 | last = NULL; | ||
60 | do | ||
61 | { | ||
62 | cp = GNUNET_strdup (arg); | ||
63 | pos = cp; | ||
64 | while ('\0' != *pos) | ||
65 | { | ||
66 | if (' ' == *pos) | ||
67 | { | ||
68 | *pos = '\0'; | ||
69 | if (last != NULL) | ||
70 | argv[argv_size++] = GNUNET_strdup (last); | ||
71 | last = NULL; | ||
72 | pos++; | ||
73 | while (' ' == *pos) | ||
74 | pos++; | ||
75 | } | ||
76 | if ( (last == NULL) && (*pos != '\0') ) | ||
77 | last = pos; | ||
78 | if (*pos != '\0') | ||
79 | pos++; | ||
80 | } | ||
81 | if (last != NULL) | ||
82 | argv[argv_size++] = GNUNET_strdup (last); | ||
83 | last = NULL; | ||
84 | GNUNET_free (cp); | ||
85 | } | ||
86 | while (NULL != (arg = (va_arg (ap, const char*)))); | ||
87 | va_end (ap); | ||
88 | argv[argv_size] = NULL; | ||
89 | pid = GNUNET_OS_start_process_v (argv[0], argv); | ||
90 | while (argv_size > 0) | ||
91 | GNUNET_free (argv[--argv_size]); | ||
92 | GNUNET_free (argv); | ||
93 | return pid; | ||
94 | } | ||
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index acef4a1e1..e5f97498b 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -344,6 +344,7 @@ free_entry (struct ServiceList *pos) | |||
344 | GNUNET_free (pos); | 344 | GNUNET_free (pos); |
345 | } | 345 | } |
346 | 346 | ||
347 | #include "do_start_process.c" | ||
347 | 348 | ||
348 | /** | 349 | /** |
349 | * Actually start the process for the given service. | 350 | * Actually start the process for the given service. |
@@ -354,13 +355,8 @@ static void | |||
354 | start_process (struct ServiceList *sl) | 355 | start_process (struct ServiceList *sl) |
355 | { | 356 | { |
356 | char *loprefix; | 357 | char *loprefix; |
357 | char *lopostfix; | ||
358 | char *options; | 358 | char *options; |
359 | char **argv; | ||
360 | unsigned int argv_size; | ||
361 | char *lopos; | ||
362 | char *optpos; | 359 | char *optpos; |
363 | const char *firstarg; | ||
364 | int use_debug; | 360 | int use_debug; |
365 | 361 | ||
366 | /* start service */ | 362 | /* start service */ |
@@ -372,7 +368,7 @@ start_process (struct ServiceList *sl) | |||
372 | GNUNET_CONFIGURATION_get_value_string (cfg, | 368 | GNUNET_CONFIGURATION_get_value_string (cfg, |
373 | sl->name, "OPTIONS", &options)) | 369 | sl->name, "OPTIONS", &options)) |
374 | { | 370 | { |
375 | options = GNUNET_strdup (lopostfix); | 371 | options = GNUNET_strdup (final_option); |
376 | /* replace '{}' with service name */ | 372 | /* replace '{}' with service name */ |
377 | if (NULL == strstr (options, "%")) | 373 | if (NULL == strstr (options, "%")) |
378 | { | 374 | { |
@@ -396,75 +392,22 @@ start_process (struct ServiceList *sl) | |||
396 | "Starting service `%s' using binary `%s' and configuration `%s'\n", | 392 | "Starting service `%s' using binary `%s' and configuration `%s'\n", |
397 | sl->name, sl->binary, sl->config); | 393 | sl->name, sl->binary, sl->config); |
398 | #endif | 394 | #endif |
399 | argv_size = 6; | ||
400 | if (use_debug) | ||
401 | argv_size += 2; | ||
402 | lopos = loprefix; | ||
403 | while ('\0' != *lopos) | ||
404 | { | ||
405 | if (*lopos == ' ') | ||
406 | argv_size++; | ||
407 | lopos++; | ||
408 | } | ||
409 | optpos = options; | ||
410 | while ('\0' != *optpos) | ||
411 | { | ||
412 | if (*optpos == ' ') | ||
413 | argv_size++; | ||
414 | optpos++; | ||
415 | } | ||
416 | firstarg = NULL; | ||
417 | argv = GNUNET_malloc (argv_size * sizeof (char *)); | ||
418 | argv_size = 0; | ||
419 | lopos = loprefix; | ||
420 | |||
421 | while ('\0' != *lopos) | ||
422 | { | ||
423 | while (*lopos == ' ') | ||
424 | lopos++; | ||
425 | if (*lopos == '\0') | ||
426 | continue; | ||
427 | if (argv_size == 0) | ||
428 | firstarg = lopos; | ||
429 | argv[argv_size++] = lopos; | ||
430 | while (('\0' != *lopos) && (' ' != *lopos)) | ||
431 | lopos++; | ||
432 | if ('\0' == *lopos) | ||
433 | continue; | ||
434 | *lopos = '\0'; | ||
435 | lopos++; | ||
436 | } | ||
437 | if (argv_size == 0) | ||
438 | firstarg = sl->binary; | ||
439 | argv[argv_size++] = sl->binary; | ||
440 | argv[argv_size++] = "-c"; | ||
441 | argv[argv_size++] = sl->config; | ||
442 | if (GNUNET_YES == use_debug) | 395 | if (GNUNET_YES == use_debug) |
443 | { | 396 | sl->pid = do_start_process (loprefix, |
444 | argv[argv_size++] = "-L"; | 397 | sl->binary, |
445 | argv[argv_size++] = "DEBUG"; | 398 | "-c", sl->config, |
446 | } | 399 | "-L", "DEBUG", |
447 | optpos = options; | 400 | options, |
448 | while ('\0' != *optpos) | 401 | NULL); |
449 | { | 402 | else |
450 | while (*optpos == ' ') | 403 | sl->pid = do_start_process (loprefix, |
451 | optpos++; | 404 | sl->binary, |
452 | if (*optpos == '\0') | 405 | "-c", sl->config, |
453 | continue; | 406 | options, |
454 | argv[argv_size++] = optpos; | 407 | NULL); |
455 | while (('\0' != *optpos) && (' ' != *optpos)) | ||
456 | optpos++; | ||
457 | if ('\0' == *optpos) | ||
458 | continue; | ||
459 | *optpos = '\0'; | ||
460 | optpos++; | ||
461 | } | ||
462 | argv[argv_size] = NULL; | ||
463 | sl->pid = GNUNET_OS_start_process_v (firstarg, argv); | ||
464 | /* FIXME: should check sl->pid */ | ||
465 | GNUNET_free (argv); | ||
466 | GNUNET_free (loprefix); | 408 | GNUNET_free (loprefix); |
467 | GNUNET_free (options); | 409 | GNUNET_free (options); |
410 | /* FIXME: should check sl->pid */ | ||
468 | } | 411 | } |
469 | 412 | ||
470 | 413 | ||
diff --git a/src/arm/test_arm_api_data.conf b/src/arm/test_arm_api_data.conf index bdacfd476..17a8ac613 100644 --- a/src/arm/test_arm_api_data.conf +++ b/src/arm/test_arm_api_data.conf | |||
@@ -11,6 +11,7 @@ OPTIONS = -L ERROR | |||
11 | 11 | ||
12 | [resolver] | 12 | [resolver] |
13 | #DEBUG = YES | 13 | #DEBUG = YES |
14 | PORT = 23355 | ||
14 | 15 | ||
15 | [do-nothing] | 16 | [do-nothing] |
16 | #DEBUG = YES | 17 | #DEBUG = YES |
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index a3dcd9c99..425e6bd8d 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c | |||
@@ -248,8 +248,6 @@ main (int argc, char *argv[]) | |||
248 | { | 248 | { |
249 | int ret; | 249 | int ret; |
250 | 250 | ||
251 | fprintf (stdout, | ||
252 | "This test will print some warnings about 'do-nothing' being terminated. That's expected!\n"); | ||
253 | GNUNET_log_setup ("test-exponential-backoff", | 251 | GNUNET_log_setup ("test-exponential-backoff", |
254 | #if VERBOSE | 252 | #if VERBOSE |
255 | "DEBUG", | 253 | "DEBUG", |