diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/gnunet-arm.c | 402 | ||||
-rw-r--r-- | src/util/program.c | 201 |
2 files changed, 272 insertions, 331 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 80b5ca3e2..5a4acb31a 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -146,20 +146,21 @@ static struct GNUNET_ARM_Operation *op; | |||
146 | static void | 146 | static void |
147 | delete_files () | 147 | delete_files () |
148 | { | 148 | { |
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 149 | GNUNET_log ( |
150 | "Will attempt to remove configuration file %s and service directory %s\n", | 150 | GNUNET_ERROR_TYPE_DEBUG, |
151 | config_file, | 151 | "Will attempt to remove configuration file %s and service directory %s\n", |
152 | dir); | 152 | config_file, |
153 | dir); | ||
153 | if (0 != UNLINK (config_file)) | 154 | if (0 != UNLINK (config_file)) |
154 | { | 155 | { |
155 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 156 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
156 | _("Failed to remove configuration file %s\n"), | 157 | _ ("Failed to remove configuration file %s\n"), |
157 | config_file); | 158 | config_file); |
158 | } | 159 | } |
159 | if (GNUNET_OK != GNUNET_DISK_directory_remove (dir)) | 160 | if (GNUNET_OK != GNUNET_DISK_directory_remove (dir)) |
160 | { | 161 | { |
161 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
162 | _("Failed to remove servicehome directory %s\n"), | 163 | _ ("Failed to remove servicehome directory %s\n"), |
163 | dir); | 164 | dir); |
164 | } | 165 | } |
165 | } | 166 | } |
@@ -208,7 +209,7 @@ shutdown_task (void *cls) | |||
208 | 209 | ||
209 | 210 | ||
210 | /** | 211 | /** |
211 | * Returns a string interpretation of 'rs' | 212 | * Returns a string interpretation of @a rs |
212 | * | 213 | * |
213 | * @param rs the request status from ARM | 214 | * @param rs the request status from ARM |
214 | * @return a string interpretation of the request status | 215 | * @return a string interpretation of the request status |
@@ -219,16 +220,16 @@ req_string (enum GNUNET_ARM_RequestStatus rs) | |||
219 | switch (rs) | 220 | switch (rs) |
220 | { | 221 | { |
221 | case GNUNET_ARM_REQUEST_SENT_OK: | 222 | case GNUNET_ARM_REQUEST_SENT_OK: |
222 | return _("Message was sent successfully"); | 223 | return _ ("Message was sent successfully"); |
223 | case GNUNET_ARM_REQUEST_DISCONNECTED: | 224 | case GNUNET_ARM_REQUEST_DISCONNECTED: |
224 | return _("We disconnected from ARM before we could send a request"); | 225 | return _ ("We disconnected from ARM before we could send a request"); |
225 | } | 226 | } |
226 | return _("Unknown request status"); | 227 | return _ ("Unknown request status"); |
227 | } | 228 | } |
228 | 229 | ||
229 | 230 | ||
230 | /** | 231 | /** |
231 | * Returns a string interpretation of the 'result' | 232 | * Returns a string interpretation of the @a result |
232 | * | 233 | * |
233 | * @param result the arm result | 234 | * @param result the arm result |
234 | * @return a string interpretation | 235 | * @return a string interpretation |
@@ -239,27 +240,27 @@ ret_string (enum GNUNET_ARM_Result result) | |||
239 | switch (result) | 240 | switch (result) |
240 | { | 241 | { |
241 | case GNUNET_ARM_RESULT_STOPPED: | 242 | case GNUNET_ARM_RESULT_STOPPED: |
242 | return _("is stopped"); | 243 | return _ ("is stopped"); |
243 | case GNUNET_ARM_RESULT_STARTING: | 244 | case GNUNET_ARM_RESULT_STARTING: |
244 | return _("is starting"); | 245 | return _ ("is starting"); |
245 | case GNUNET_ARM_RESULT_STOPPING: | 246 | case GNUNET_ARM_RESULT_STOPPING: |
246 | return _("is stopping"); | 247 | return _ ("is stopping"); |
247 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: | 248 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: |
248 | return _("is starting already"); | 249 | return _ ("is starting already"); |
249 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: | 250 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: |
250 | return _("is stopping already"); | 251 | return _ ("is stopping already"); |
251 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: | 252 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: |
252 | return _("is started already"); | 253 | return _ ("is started already"); |
253 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: | 254 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: |
254 | return _("is stopped already"); | 255 | return _ ("is stopped already"); |
255 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: | 256 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: |
256 | return _("service is not known to ARM"); | 257 | return _ ("service is not known to ARM"); |
257 | case GNUNET_ARM_RESULT_START_FAILED: | 258 | case GNUNET_ARM_RESULT_START_FAILED: |
258 | return _("service failed to start"); | 259 | return _ ("service failed to start"); |
259 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | 260 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: |
260 | return _("service cannot be manipulated because ARM is shutting down"); | 261 | return _ ("service cannot be manipulated because ARM is shutting down"); |
261 | } | 262 | } |
262 | return _("Unknown result code."); | 263 | return _ ("Unknown result code."); |
263 | } | 264 | } |
264 | 265 | ||
265 | 266 | ||
@@ -282,17 +283,15 @@ action_loop (void *cls); | |||
282 | * #GNUNET_SYSERR on error. | 283 | * #GNUNET_SYSERR on error. |
283 | */ | 284 | */ |
284 | static void | 285 | static void |
285 | conn_status (void *cls, | 286 | conn_status (void *cls, int connected) |
286 | int connected) | ||
287 | { | 287 | { |
288 | static int once; | 288 | static int once; |
289 | 289 | ||
290 | (void) cls; | 290 | (void) cls; |
291 | if ( (GNUNET_SYSERR == connected) && | 291 | if ((GNUNET_SYSERR == connected) && (0 == once)) |
292 | (0 == once) ) | ||
293 | { | 292 | { |
294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 293 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
295 | _("Fatal error initializing ARM API.\n")); | 294 | _ ("Fatal error initializing ARM API.\n")); |
296 | GNUNET_SCHEDULER_shutdown (); | 295 | GNUNET_SCHEDULER_shutdown (); |
297 | return; | 296 | return; |
298 | } | 297 | } |
@@ -313,30 +312,29 @@ conn_status (void *cls, | |||
313 | */ | 312 | */ |
314 | static void | 313 | static void |
315 | start_callback (void *cls, | 314 | start_callback (void *cls, |
316 | enum GNUNET_ARM_RequestStatus rs, | 315 | enum GNUNET_ARM_RequestStatus rs, |
317 | enum GNUNET_ARM_Result result) | 316 | enum GNUNET_ARM_Result result) |
318 | { | 317 | { |
319 | (void) cls; | 318 | (void) cls; |
320 | op = NULL; | 319 | op = NULL; |
321 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 320 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
322 | { | 321 | { |
323 | FPRINTF (stdout, | 322 | FPRINTF (stdout, |
324 | _("Failed to start the ARM service: %s\n"), | 323 | _ ("Failed to start the ARM service: %s\n"), |
325 | req_string (rs)); | 324 | req_string (rs)); |
326 | GNUNET_SCHEDULER_shutdown (); | 325 | GNUNET_SCHEDULER_shutdown (); |
327 | return; | 326 | return; |
328 | } | 327 | } |
329 | if ( (GNUNET_ARM_RESULT_STARTING != result) && | 328 | if ((GNUNET_ARM_RESULT_STARTING != result) && |
330 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result) ) | 329 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) |
331 | { | 330 | { |
332 | FPRINTF (stdout, | 331 | FPRINTF (stdout, |
333 | _("Failed to start the ARM service: %s\n"), | 332 | _ ("Failed to start the ARM service: %s\n"), |
334 | ret_string (result)); | 333 | ret_string (result)); |
335 | GNUNET_SCHEDULER_shutdown (); | 334 | GNUNET_SCHEDULER_shutdown (); |
336 | return; | 335 | return; |
337 | } | 336 | } |
338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n"); |
339 | "ARM service [re]start successful\n"); | ||
340 | start = 0; | 338 | start = 0; |
341 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 339 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); |
342 | } | 340 | } |
@@ -355,8 +353,8 @@ start_callback (void *cls, | |||
355 | */ | 353 | */ |
356 | static void | 354 | static void |
357 | stop_callback (void *cls, | 355 | stop_callback (void *cls, |
358 | enum GNUNET_ARM_RequestStatus rs, | 356 | enum GNUNET_ARM_RequestStatus rs, |
359 | enum GNUNET_ARM_Result result) | 357 | enum GNUNET_ARM_Result result) |
360 | { | 358 | { |
361 | char *msg; | 359 | char *msg; |
362 | 360 | ||
@@ -364,8 +362,10 @@ stop_callback (void *cls, | |||
364 | op = NULL; | 362 | op = NULL; |
365 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 363 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
366 | { | 364 | { |
367 | GNUNET_asprintf (&msg, "%s", | 365 | GNUNET_asprintf (&msg, |
368 | _("Failed to send a stop request to the ARM service: %s\n")); | 366 | "%s", |
367 | _ ( | ||
368 | "Failed to send a stop request to the ARM service: %s\n")); | ||
369 | FPRINTF (stdout, msg, req_string (rs)); | 369 | FPRINTF (stdout, msg, req_string (rs)); |
370 | GNUNET_free (msg); | 370 | GNUNET_free (msg); |
371 | GNUNET_SCHEDULER_shutdown (); | 371 | GNUNET_SCHEDULER_shutdown (); |
@@ -376,20 +376,18 @@ stop_callback (void *cls, | |||
376 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) | 376 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) |
377 | { | 377 | { |
378 | FPRINTF (stdout, | 378 | FPRINTF (stdout, |
379 | _("Failed to stop the ARM service: %s\n"), | 379 | _ ("Failed to stop the ARM service: %s\n"), |
380 | ret_string (result)); | 380 | ret_string (result)); |
381 | GNUNET_SCHEDULER_shutdown (); | 381 | GNUNET_SCHEDULER_shutdown (); |
382 | return; | 382 | return; |
383 | } | 383 | } |
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service shutdown successful\n"); |
385 | "ARM service shutdown successful\n"); | ||
386 | end = 0; | 385 | end = 0; |
387 | if (restart) | 386 | if (restart) |
388 | { | 387 | { |
389 | restart = 0; | 388 | restart = 0; |
390 | start = 1; | 389 | start = 1; |
391 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating an ARM restart\n"); |
392 | "Initiating an ARM restart\n"); | ||
393 | } | 391 | } |
394 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 392 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); |
395 | } | 393 | } |
@@ -408,15 +406,15 @@ stop_callback (void *cls, | |||
408 | */ | 406 | */ |
409 | static void | 407 | static void |
410 | init_callback (void *cls, | 408 | init_callback (void *cls, |
411 | enum GNUNET_ARM_RequestStatus rs, | 409 | enum GNUNET_ARM_RequestStatus rs, |
412 | enum GNUNET_ARM_Result result) | 410 | enum GNUNET_ARM_Result result) |
413 | { | 411 | { |
414 | (void) cls; | 412 | (void) cls; |
415 | op = NULL; | 413 | op = NULL; |
416 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 414 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
417 | { | 415 | { |
418 | FPRINTF (stdout, | 416 | FPRINTF (stdout, |
419 | _("Failed to send a request to start the `%s' service: %s\n"), | 417 | _ ("Failed to send a request to start the `%s' service: %s\n"), |
420 | init, | 418 | init, |
421 | req_string (rs)); | 419 | req_string (rs)); |
422 | GNUNET_SCHEDULER_shutdown (); | 420 | GNUNET_SCHEDULER_shutdown (); |
@@ -426,15 +424,15 @@ init_callback (void *cls, | |||
426 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) | 424 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) |
427 | { | 425 | { |
428 | FPRINTF (stdout, | 426 | FPRINTF (stdout, |
429 | _("Failed to start the `%s' service: %s\n"), | 427 | _ ("Failed to start the `%s' service: %s\n"), |
430 | init, | 428 | init, |
431 | ret_string (result)); | 429 | ret_string (result)); |
432 | GNUNET_SCHEDULER_shutdown (); | 430 | GNUNET_SCHEDULER_shutdown (); |
433 | return; | 431 | return; |
434 | } | 432 | } |
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
436 | "Service %s [re]started successfully\n", | 434 | "Service %s [re]started successfully\n", |
437 | init); | 435 | init); |
438 | GNUNET_free (init); | 436 | GNUNET_free (init); |
439 | init = NULL; | 437 | init = NULL; |
440 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 438 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); |
@@ -454,8 +452,8 @@ init_callback (void *cls, | |||
454 | */ | 452 | */ |
455 | static void | 453 | static void |
456 | term_callback (void *cls, | 454 | term_callback (void *cls, |
457 | enum GNUNET_ARM_RequestStatus rs, | 455 | enum GNUNET_ARM_RequestStatus rs, |
458 | enum GNUNET_ARM_Result result) | 456 | enum GNUNET_ARM_Result result) |
459 | { | 457 | { |
460 | char *msg; | 458 | char *msg; |
461 | 459 | ||
@@ -464,7 +462,8 @@ term_callback (void *cls, | |||
464 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 462 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
465 | { | 463 | { |
466 | GNUNET_asprintf (&msg, | 464 | GNUNET_asprintf (&msg, |
467 | _("Failed to send a request to kill the `%s' service: %%s\n"), | 465 | _ ( |
466 | "Failed to send a request to kill the `%s' service: %%s\n"), | ||
468 | term); | 467 | term); |
469 | FPRINTF (stdout, msg, req_string (rs)); | 468 | FPRINTF (stdout, msg, req_string (rs)); |
470 | GNUNET_free (msg); | 469 | GNUNET_free (msg); |
@@ -475,7 +474,7 @@ term_callback (void *cls, | |||
475 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) | 474 | (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) |
476 | { | 475 | { |
477 | FPRINTF (stdout, | 476 | FPRINTF (stdout, |
478 | _("Failed to kill the `%s' service: %s\n"), | 477 | _ ("Failed to kill the `%s' service: %s\n"), |
479 | term, | 478 | term, |
480 | ret_string (result)); | 479 | ret_string (result)); |
481 | GNUNET_SCHEDULER_shutdown (); | 480 | GNUNET_SCHEDULER_shutdown (); |
@@ -483,7 +482,7 @@ term_callback (void *cls, | |||
483 | } | 482 | } |
484 | 483 | ||
485 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
486 | "Service %s stopped successfully\n", | 485 | "Service %s stopped successfully\n", |
487 | term); | 486 | term); |
488 | GNUNET_free (term); | 487 | GNUNET_free (term); |
489 | term = NULL; | 488 | term = NULL; |
@@ -503,20 +502,19 @@ term_callback (void *cls, | |||
503 | */ | 502 | */ |
504 | static void | 503 | static void |
505 | list_callback (void *cls, | 504 | list_callback (void *cls, |
506 | enum GNUNET_ARM_RequestStatus rs, | 505 | enum GNUNET_ARM_RequestStatus rs, |
507 | unsigned int count, | 506 | unsigned int count, |
508 | const char *const*list) | 507 | const char *const *list) |
509 | { | 508 | { |
510 | unsigned int i; | ||
511 | |||
512 | (void) cls; | 509 | (void) cls; |
513 | op = NULL; | 510 | op = NULL; |
514 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 511 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
515 | { | 512 | { |
516 | char *msg; | 513 | char *msg; |
517 | 514 | ||
518 | GNUNET_asprintf (&msg, "%s", | 515 | GNUNET_asprintf (&msg, |
519 | _("Failed to request a list of services: %s\n")); | 516 | "%s", |
517 | _ ("Failed to request a list of services: %s\n")); | ||
520 | FPRINTF (stdout, msg, req_string (rs)); | 518 | FPRINTF (stdout, msg, req_string (rs)); |
521 | GNUNET_free (msg); | 519 | GNUNET_free (msg); |
522 | ret = 3; | 520 | ret = 3; |
@@ -524,15 +522,16 @@ list_callback (void *cls, | |||
524 | } | 522 | } |
525 | if (NULL == list) | 523 | if (NULL == list) |
526 | { | 524 | { |
527 | FPRINTF (stderr, "%s", | 525 | FPRINTF (stderr, |
528 | _("Error communicating with ARM. ARM not running?\n")); | 526 | "%s", |
527 | _ ("Error communicating with ARM. ARM not running?\n")); | ||
529 | GNUNET_SCHEDULER_shutdown (); | 528 | GNUNET_SCHEDULER_shutdown (); |
530 | ret = 3; | 529 | ret = 3; |
531 | return; | 530 | return; |
532 | } | 531 | } |
533 | if (! quiet) | 532 | if (! quiet) |
534 | FPRINTF (stdout, "%s", _("Running services:\n")); | 533 | FPRINTF (stdout, "%s", _ ("Running services:\n")); |
535 | for (i = 0; i < count; i++) | 534 | for (unsigned int i = 0; i < count; i++) |
536 | FPRINTF (stdout, "%s\n", list[i]); | 535 | FPRINTF (stdout, "%s\n", list[i]); |
537 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 536 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); |
538 | } | 537 | } |
@@ -549,8 +548,7 @@ action_loop (void *cls) | |||
549 | { | 548 | { |
550 | (void) cls; | 549 | (void) cls; |
551 | al_task = NULL; | 550 | al_task = NULL; |
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n"); |
553 | "Running requested actions\n"); | ||
554 | while (1) | 552 | while (1) |
555 | { | 553 | { |
556 | switch (phase++) | 554 | switch (phase++) |
@@ -558,46 +556,43 @@ action_loop (void *cls) | |||
558 | case 0: | 556 | case 0: |
559 | if (NULL != term) | 557 | if (NULL != term) |
560 | { | 558 | { |
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n"); |
562 | "Termination action\n"); | 560 | op = GNUNET_ARM_request_service_stop (h, term, &term_callback, NULL); |
563 | op = GNUNET_ARM_request_service_stop (h, | 561 | return; |
564 | term, | ||
565 | &term_callback, | ||
566 | NULL); | ||
567 | return; | ||
568 | } | 562 | } |
569 | break; | 563 | break; |
570 | case 1: | 564 | case 1: |
571 | if (end || restart) | 565 | if (end || restart) |
572 | { | 566 | { |
573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 567 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n"); |
574 | "End action\n"); | 568 | op = GNUNET_ARM_request_service_stop (h, "arm", &stop_callback, NULL); |
575 | op = GNUNET_ARM_request_service_stop (h, | ||
576 | "arm", | ||
577 | &stop_callback, | ||
578 | NULL); | ||
579 | return; | 569 | return; |
580 | } | 570 | } |
581 | break; | 571 | break; |
582 | case 2: | 572 | case 2: |
583 | if (start) | 573 | if (start) |
584 | { | 574 | { |
585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n"); |
586 | "Start action\n"); | 576 | op = |
587 | op = GNUNET_ARM_request_service_start (h, "arm", | 577 | GNUNET_ARM_request_service_start (h, |
588 | (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | | 578 | "arm", |
589 | (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), | 579 | (no_stdout |
590 | &start_callback, | 580 | ? 0 |
591 | NULL); | 581 | : GNUNET_OS_INHERIT_STD_OUT) | |
582 | (no_stderr | ||
583 | ? 0 | ||
584 | : GNUNET_OS_INHERIT_STD_ERR), | ||
585 | &start_callback, | ||
586 | NULL); | ||
592 | return; | 587 | return; |
593 | } | 588 | } |
594 | break; | 589 | break; |
595 | case 3: | 590 | case 3: |
596 | if (NULL != init) | 591 | if (NULL != init) |
597 | { | 592 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n"); |
599 | "Initialization action\n"); | 594 | op = GNUNET_ARM_request_service_start (h, |
600 | op = GNUNET_ARM_request_service_start (h, init, | 595 | init, |
601 | GNUNET_OS_INHERIT_STD_NONE, | 596 | GNUNET_OS_INHERIT_STD_NONE, |
602 | &init_callback, | 597 | &init_callback, |
603 | NULL); | 598 | NULL); |
@@ -607,25 +602,23 @@ action_loop (void *cls) | |||
607 | case 4: | 602 | case 4: |
608 | if (list) | 603 | if (list) |
609 | { | 604 | { |
610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
611 | "Going to list all running services controlled by ARM.\n"); | 606 | "Going to list all running services controlled by ARM.\n"); |
612 | op = GNUNET_ARM_request_service_list (h, | 607 | op = GNUNET_ARM_request_service_list (h, &list_callback, &list); |
613 | &list_callback, | 608 | return; |
614 | &list); | ||
615 | return; | ||
616 | } | 609 | } |
617 | break; | 610 | break; |
618 | case 5: | 611 | case 5: |
619 | if (monitor) | 612 | if (monitor) |
620 | { | 613 | { |
621 | if (! quiet) | 614 | if (! quiet) |
622 | fprintf (stderr, | 615 | fprintf (stderr, _ ("Now only monitoring, press CTRL-C to stop.\n")); |
623 | _("Now only monitoring, press CTRL-C to stop.\n")); | 616 | quiet = |
624 | quiet = 0; /* does not make sense to stay quiet in monitor mode at this time */ | 617 | 0; /* does not make sense to stay quiet in monitor mode at this time */ |
625 | return; /* done with tasks, just monitor */ | 618 | return; /* done with tasks, just monitor */ |
626 | } | 619 | } |
627 | break; | 620 | break; |
628 | default: /* last phase */ | 621 | default: /* last phase */ |
629 | GNUNET_SCHEDULER_shutdown (); | 622 | GNUNET_SCHEDULER_shutdown (); |
630 | return; | 623 | return; |
631 | } | 624 | } |
@@ -642,8 +635,8 @@ action_loop (void *cls) | |||
642 | */ | 635 | */ |
643 | static void | 636 | static void |
644 | srv_status (void *cls, | 637 | srv_status (void *cls, |
645 | const char *service, | 638 | const char *service, |
646 | enum GNUNET_ARM_ServiceStatus status) | 639 | enum GNUNET_ARM_ServiceStatus status) |
647 | { | 640 | { |
648 | const char *msg; | 641 | const char *msg; |
649 | 642 | ||
@@ -653,13 +646,13 @@ srv_status (void *cls, | |||
653 | case GNUNET_ARM_SERVICE_MONITORING_STARTED: | 646 | case GNUNET_ARM_SERVICE_MONITORING_STARTED: |
654 | return; /* this should be done silently */ | 647 | return; /* this should be done silently */ |
655 | case GNUNET_ARM_SERVICE_STOPPED: | 648 | case GNUNET_ARM_SERVICE_STOPPED: |
656 | msg = _("Stopped %s.\n"); | 649 | msg = _ ("Stopped %s.\n"); |
657 | break; | 650 | break; |
658 | case GNUNET_ARM_SERVICE_STARTING: | 651 | case GNUNET_ARM_SERVICE_STARTING: |
659 | msg = _("Starting %s...\n"); | 652 | msg = _ ("Starting %s...\n"); |
660 | break; | 653 | break; |
661 | case GNUNET_ARM_SERVICE_STOPPING: | 654 | case GNUNET_ARM_SERVICE_STOPPING: |
662 | msg = _("Stopping %s...\n"); | 655 | msg = _ ("Stopping %s...\n"); |
663 | break; | 656 | break; |
664 | default: | 657 | default: |
665 | msg = NULL; | 658 | msg = NULL; |
@@ -668,19 +661,17 @@ srv_status (void *cls, | |||
668 | if (! quiet) | 661 | if (! quiet) |
669 | { | 662 | { |
670 | if (NULL != msg) | 663 | if (NULL != msg) |
671 | FPRINTF (stderr, | 664 | FPRINTF (stderr, msg, service); |
672 | msg, | ||
673 | service); | ||
674 | else | 665 | else |
675 | FPRINTF (stderr, | 666 | FPRINTF (stderr, |
676 | _("Unknown status %u for service %s.\n"), | 667 | _ ("Unknown status %u for service %s.\n"), |
677 | status, | 668 | status, |
678 | service); | 669 | service); |
679 | } | 670 | } |
680 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
681 | "Got service %s status %d\n", | 672 | "Got service %s status %d\n", |
682 | service, (int) | 673 | service, |
683 | status); | 674 | (int) status); |
684 | } | 675 | } |
685 | 676 | ||
686 | 677 | ||
@@ -716,36 +707,24 @@ run (void *cls, | |||
716 | (void) cfgfile; | 707 | (void) cfgfile; |
717 | cfg = GNUNET_CONFIGURATION_dup (c); | 708 | cfg = GNUNET_CONFIGURATION_dup (c); |
718 | if (GNUNET_OK != | 709 | if (GNUNET_OK != |
719 | GNUNET_CONFIGURATION_get_value_string (cfg, | 710 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "GNUNET_HOME", &dir)) |
720 | "PATHS", | ||
721 | "GNUNET_HOME", | ||
722 | &dir)) | ||
723 | { | 711 | { |
724 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 712 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "PATHS", "GNUNET_HOME"); |
725 | "PATHS", | ||
726 | "GNUNET_HOME"); | ||
727 | return; | 713 | return; |
728 | } | 714 | } |
729 | (void) GNUNET_CONFIGURATION_get_value_filename (cfg, | 715 | (void) GNUNET_CONFIGURATION_get_value_filename (cfg, |
730 | "arm", | 716 | "arm", |
731 | "CONFIG", | 717 | "CONFIG", |
732 | &config_file); | 718 | &config_file); |
733 | if (NULL == (h = GNUNET_ARM_connect (cfg, | 719 | if (NULL == (h = GNUNET_ARM_connect (cfg, &conn_status, NULL))) |
734 | &conn_status, | ||
735 | NULL))) | ||
736 | return; | 720 | return; |
737 | if (monitor) | 721 | if (monitor) |
738 | m = GNUNET_ARM_monitor_start (cfg, | 722 | m = GNUNET_ARM_monitor_start (cfg, &srv_status, NULL); |
739 | &srv_status, | 723 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); |
740 | NULL); | 724 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
741 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, | ||
742 | NULL); | ||
743 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
744 | NULL); | ||
745 | if (0 != timeout.rel_value_us) | 725 | if (0 != timeout.rel_value_us) |
746 | timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 726 | timeout_task = |
747 | &timeout_task_cb, | 727 | GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task_cb, NULL); |
748 | NULL); | ||
749 | } | 728 | } |
750 | 729 | ||
751 | 730 | ||
@@ -757,82 +736,87 @@ run (void *cls, | |||
757 | * @return 0 ok, 1 on error, 2 on timeout | 736 | * @return 0 ok, 1 on error, 2 on timeout |
758 | */ | 737 | */ |
759 | int | 738 | int |
760 | main (int argc, | 739 | main (int argc, char *const *argv) |
761 | char *const *argv) | ||
762 | { | 740 | { |
763 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 741 | struct GNUNET_GETOPT_CommandLineOption options[] = |
764 | GNUNET_GETOPT_option_flag ('e', | 742 | {GNUNET_GETOPT_option_flag ('e', |
765 | "end", | 743 | "end", |
766 | gettext_noop ("stop all GNUnet services"), | 744 | gettext_noop ("stop all GNUnet services"), |
767 | &end), | 745 | &end), |
768 | GNUNET_GETOPT_option_string ('i', | 746 | GNUNET_GETOPT_option_string ('i', |
769 | "init", | 747 | "init", |
770 | "SERVICE", | 748 | "SERVICE", |
771 | gettext_noop ("start a particular service"), | 749 | gettext_noop ("start a particular service"), |
772 | &init), | 750 | &init), |
773 | GNUNET_GETOPT_option_string ('k', | 751 | GNUNET_GETOPT_option_string ('k', |
774 | "kill", | 752 | "kill", |
775 | "SERVICE", | 753 | "SERVICE", |
776 | gettext_noop ("stop a particular service"), | 754 | gettext_noop ("stop a particular service"), |
777 | &term), | 755 | &term), |
778 | GNUNET_GETOPT_option_flag ('s', | 756 | GNUNET_GETOPT_option_flag ('s', |
779 | "start", | 757 | "start", |
780 | gettext_noop ("start all GNUnet default services"), | 758 | gettext_noop ( |
781 | &start), | 759 | "start all GNUnet default services"), |
782 | GNUNET_GETOPT_option_flag ('r', | 760 | &start), |
783 | "restart", | 761 | GNUNET_GETOPT_option_flag ('r', |
784 | gettext_noop ("stop and start all GNUnet default services"), | 762 | "restart", |
785 | &restart), | 763 | gettext_noop ( |
786 | GNUNET_GETOPT_option_flag ('d', | 764 | "stop and start all GNUnet default services"), |
787 | "delete", | 765 | &restart), |
788 | gettext_noop ("delete config file and directory on exit"), | 766 | GNUNET_GETOPT_option_flag ('d', |
789 | &delete), | 767 | "delete", |
790 | GNUNET_GETOPT_option_flag ('m', | 768 | gettext_noop ( |
791 | "monitor", | 769 | "delete config file and directory on exit"), |
792 | gettext_noop ("monitor ARM activities"), | 770 | &delete), |
793 | &monitor), | 771 | GNUNET_GETOPT_option_flag ('m', |
794 | GNUNET_GETOPT_option_flag ('q', | 772 | "monitor", |
795 | "quiet", | 773 | gettext_noop ("monitor ARM activities"), |
796 | gettext_noop ("don't print status messages"), | 774 | &monitor), |
797 | &quiet), | 775 | GNUNET_GETOPT_option_flag ('q', |
798 | GNUNET_GETOPT_option_relative_time ('T', | 776 | "quiet", |
799 | "timeout", | 777 | gettext_noop ("don't print status messages"), |
800 | "DELAY", | 778 | &quiet), |
801 | gettext_noop ("exit with error status if operation does not finish after DELAY"), | 779 | GNUNET_GETOPT_option_relative_time ( |
802 | &timeout), | 780 | 'T', |
803 | GNUNET_GETOPT_option_flag ('I', | 781 | "timeout", |
804 | "info", | 782 | "DELAY", |
805 | gettext_noop ("list currently running services"), | 783 | gettext_noop ( |
806 | &list), | 784 | "exit with error status if operation does not finish after DELAY"), |
807 | GNUNET_GETOPT_option_flag ('O', | 785 | &timeout), |
808 | "no-stdout", | 786 | GNUNET_GETOPT_option_flag ('I', |
809 | gettext_noop ("don't let gnunet-service-arm inherit standard output"), | 787 | "info", |
810 | &no_stdout), | 788 | gettext_noop ( |
811 | GNUNET_GETOPT_option_flag ('E', | 789 | "list currently running services"), |
812 | "no-stderr", | 790 | &list), |
813 | gettext_noop ("don't let gnunet-service-arm inherit standard error"), | 791 | GNUNET_GETOPT_option_flag ( |
814 | &no_stderr), | 792 | 'O', |
815 | GNUNET_GETOPT_OPTION_END | 793 | "no-stdout", |
816 | }; | 794 | gettext_noop ("don't let gnunet-service-arm inherit standard output"), |
817 | 795 | &no_stdout), | |
818 | if (GNUNET_OK != | 796 | GNUNET_GETOPT_option_flag ( |
819 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 797 | 'E', |
820 | &argc, &argv)) | 798 | "no-stderr", |
799 | gettext_noop ("don't let gnunet-service-arm inherit standard error"), | ||
800 | &no_stderr), | ||
801 | GNUNET_GETOPT_OPTION_END}; | ||
802 | |||
803 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
821 | return 2; | 804 | return 2; |
822 | |||
823 | if (GNUNET_OK == | 805 | if (GNUNET_OK == |
824 | GNUNET_PROGRAM_run (argc, | 806 | GNUNET_PROGRAM_run ( |
825 | argv, | 807 | argc, |
826 | "gnunet-arm", | 808 | argv, |
827 | gettext_noop | 809 | "gnunet-arm", |
828 | ("Control services and the Automated Restart Manager (ARM)"), | 810 | gettext_noop ( |
829 | options, | 811 | "Control services and the Automated Restart Manager (ARM)"), |
830 | &run, NULL)) | 812 | options, |
813 | &run, | ||
814 | NULL)) | ||
831 | { | 815 | { |
832 | GNUNET_free ((void *) argv); | 816 | GNUNET_free ((void *) argv); |
833 | return ret; | 817 | return ret; |
834 | } | 818 | } |
835 | GNUNET_free ((void*) argv); | 819 | GNUNET_free ((void *) argv); |
836 | return 1; | 820 | return 1; |
837 | } | 821 | } |
838 | 822 | ||
diff --git a/src/util/program.c b/src/util/program.c index f22dcddbf..8a5b1c414 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -31,9 +31,10 @@ | |||
31 | #include "speedup.h" | 31 | #include "speedup.h" |
32 | #include <gcrypt.h> | 32 | #include <gcrypt.h> |
33 | 33 | ||
34 | #define LOG(kind,...) GNUNET_log_from (kind, "util-program", __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from (kind, "util-program", __VA_ARGS__) |
35 | 35 | ||
36 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-program", syscall, filename) | 36 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
37 | GNUNET_log_from_strerror_file (kind, "util-program", syscall, filename) | ||
37 | 38 | ||
38 | /** | 39 | /** |
39 | * Context for the command. | 40 | * Context for the command. |
@@ -64,7 +65,6 @@ struct CommandContext | |||
64 | * Configuration to use. | 65 | * Configuration to use. |
65 | */ | 66 | */ |
66 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 67 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
67 | |||
68 | }; | 68 | }; |
69 | 69 | ||
70 | 70 | ||
@@ -88,14 +88,10 @@ program_main (void *cls) | |||
88 | { | 88 | { |
89 | struct CommandContext *cc = cls; | 89 | struct CommandContext *cc = cls; |
90 | 90 | ||
91 | GNUNET_SPEEDUP_start_(cc->cfg); | 91 | GNUNET_SPEEDUP_start_ (cc->cfg); |
92 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 92 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
93 | NULL); | ||
94 | GNUNET_RESOLVER_connect (cc->cfg); | 93 | GNUNET_RESOLVER_connect (cc->cfg); |
95 | cc->task (cc->task_cls, | 94 | cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg); |
96 | cc->args, | ||
97 | cc->cfgfile, | ||
98 | cc->cfg); | ||
99 | } | 95 | } |
100 | 96 | ||
101 | 97 | ||
@@ -107,8 +103,7 @@ program_main (void *cls) | |||
107 | * @param a2 second command line option | 103 | * @param a2 second command line option |
108 | */ | 104 | */ |
109 | static int | 105 | static int |
110 | cmd_sorter (const void *a1, | 106 | cmd_sorter (const void *a1, const void *a2) |
111 | const void *a2) | ||
112 | { | 107 | { |
113 | const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; | 108 | const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; |
114 | const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; | 109 | const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; |
@@ -144,12 +139,12 @@ cmd_sorter (const void *a1, | |||
144 | */ | 139 | */ |
145 | int | 140 | int |
146 | GNUNET_PROGRAM_run2 (int argc, | 141 | GNUNET_PROGRAM_run2 (int argc, |
147 | char *const *argv, | 142 | char *const *argv, |
148 | const char *binaryName, | 143 | const char *binaryName, |
149 | const char *binaryHelp, | 144 | const char *binaryHelp, |
150 | const struct GNUNET_GETOPT_CommandLineOption *options, | 145 | const struct GNUNET_GETOPT_CommandLineOption *options, |
151 | GNUNET_PROGRAM_Main task, | 146 | GNUNET_PROGRAM_Main task, |
152 | void *task_cls, | 147 | void *task_cls, |
153 | int run_without_scheduler) | 148 | int run_without_scheduler) |
154 | { | 149 | { |
155 | struct CommandContext cc; | 150 | struct CommandContext cc; |
@@ -166,13 +161,12 @@ GNUNET_PROGRAM_run2 (int argc, | |||
166 | unsigned long long skew_variance; | 161 | unsigned long long skew_variance; |
167 | long long clock_offset; | 162 | long long clock_offset; |
168 | struct GNUNET_CONFIGURATION_Handle *cfg; | 163 | struct GNUNET_CONFIGURATION_Handle *cfg; |
169 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { | 164 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = |
170 | GNUNET_GETOPT_option_cfgfile (&cc.cfgfile), | 165 | {GNUNET_GETOPT_option_cfgfile (&cc.cfgfile), |
171 | GNUNET_GETOPT_option_help (binaryHelp), | 166 | GNUNET_GETOPT_option_help (binaryHelp), |
172 | GNUNET_GETOPT_option_loglevel (&loglev), | 167 | GNUNET_GETOPT_option_loglevel (&loglev), |
173 | GNUNET_GETOPT_option_logfile (&logfile), | 168 | GNUNET_GETOPT_option_logfile (&logfile), |
174 | GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION) | 169 | GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION)}; |
175 | }; | ||
176 | struct GNUNET_GETOPT_CommandLineOption *allopts; | 170 | struct GNUNET_GETOPT_CommandLineOption *allopts; |
177 | const char *gargs; | 171 | const char *gargs; |
178 | char *lpfx; | 172 | char *lpfx; |
@@ -189,26 +183,16 @@ GNUNET_PROGRAM_run2 (int argc, | |||
189 | gargv = NULL; | 183 | gargv = NULL; |
190 | gargc = 0; | 184 | gargc = 0; |
191 | for (int i = 0; i < argc; i++) | 185 | for (int i = 0; i < argc; i++) |
192 | GNUNET_array_append (gargv, | 186 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); |
193 | gargc, | ||
194 | GNUNET_strdup (argv[i])); | ||
195 | cargs = GNUNET_strdup (gargs); | 187 | cargs = GNUNET_strdup (gargs); |
196 | for (char *tok = strtok (cargs, " "); | 188 | for (char *tok = strtok (cargs, " "); NULL != tok; tok = strtok (NULL, " ")) |
197 | NULL != tok; | 189 | GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); |
198 | tok = strtok (NULL, " ")) | ||
199 | GNUNET_array_append (gargv, | ||
200 | gargc, | ||
201 | GNUNET_strdup (tok)); | ||
202 | GNUNET_free (cargs); | 190 | GNUNET_free (cargs); |
203 | GNUNET_array_append (gargv, | 191 | GNUNET_array_append (gargv, gargc, NULL); |
204 | gargc, | ||
205 | NULL); | ||
206 | argv = (char *const *) gargv; | 192 | argv = (char *const *) gargv; |
207 | argc = gargc - 1; | 193 | argc = gargc - 1; |
208 | } | 194 | } |
209 | memset (&cc, | 195 | memset (&cc, 0, sizeof (cc)); |
210 | 0, | ||
211 | sizeof (cc)); | ||
212 | loglev = NULL; | 196 | loglev = NULL; |
213 | cc.task = task; | 197 | cc.task = task; |
214 | cc.task_cls = task_cls; | 198 | cc.task_cls = task_cls; |
@@ -219,8 +203,7 @@ GNUNET_PROGRAM_run2 (int argc, | |||
219 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); | 203 | path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
220 | if (NULL != path) | 204 | if (NULL != path) |
221 | { | 205 | { |
222 | BINDTEXTDOMAIN ("GNUnet", | 206 | BINDTEXTDOMAIN ("GNUnet", path); |
223 | path); | ||
224 | GNUNET_free (path); | 207 | GNUNET_free (path); |
225 | } | 208 | } |
226 | textdomain ("GNUnet"); | 209 | textdomain ("GNUnet"); |
@@ -229,20 +212,17 @@ GNUNET_PROGRAM_run2 (int argc, | |||
229 | while (NULL != options[cnt].name) | 212 | while (NULL != options[cnt].name) |
230 | cnt++; | 213 | cnt++; |
231 | allopts = | 214 | allopts = |
232 | GNUNET_malloc ((cnt + | 215 | GNUNET_malloc ((cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + |
233 | 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + | 216 | sizeof (defoptions)); |
234 | sizeof (defoptions)); | 217 | GNUNET_memcpy (allopts, defoptions, sizeof (defoptions)); |
235 | GNUNET_memcpy (allopts, | 218 | GNUNET_memcpy (&allopts[sizeof (defoptions) / |
236 | defoptions, | 219 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], |
237 | sizeof (defoptions)); | 220 | options, |
238 | GNUNET_memcpy (&allopts | 221 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); |
239 | [sizeof (defoptions) / | ||
240 | sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, | ||
241 | (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); | ||
242 | cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); | 222 | cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); |
243 | qsort (allopts, | 223 | qsort (allopts, |
244 | cnt, | 224 | cnt, |
245 | sizeof (struct GNUNET_GETOPT_CommandLineOption), | 225 | sizeof (struct GNUNET_GETOPT_CommandLineOption), |
246 | &cmd_sorter); | 226 | &cmd_sorter); |
247 | loglev = NULL; | 227 | loglev = NULL; |
248 | xdg = getenv ("XDG_CONFIG_HOME"); | 228 | xdg = getenv ("XDG_CONFIG_HOME"); |
@@ -257,15 +237,9 @@ GNUNET_PROGRAM_run2 (int argc, | |||
257 | lpfx = GNUNET_strdup (binaryName); | 237 | lpfx = GNUNET_strdup (binaryName); |
258 | if (NULL != (spc = strstr (lpfx, " "))) | 238 | if (NULL != (spc = strstr (lpfx, " "))) |
259 | *spc = '\0'; | 239 | *spc = '\0'; |
260 | ret = GNUNET_GETOPT_run (binaryName, | 240 | ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv); |
261 | allopts, | ||
262 | (unsigned int) argc, | ||
263 | argv); | ||
264 | if ((GNUNET_OK > ret) || | 241 | if ((GNUNET_OK > ret) || |
265 | (GNUNET_OK != | 242 | (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) |
266 | GNUNET_log_setup (lpfx, | ||
267 | loglev, | ||
268 | logfile))) | ||
269 | { | 243 | { |
270 | GNUNET_free (allopts); | 244 | GNUNET_free (allopts); |
271 | GNUNET_free (lpfx); | 245 | GNUNET_free (lpfx); |
@@ -273,15 +247,13 @@ GNUNET_PROGRAM_run2 (int argc, | |||
273 | } | 247 | } |
274 | if (NULL != cc.cfgfile) | 248 | if (NULL != cc.cfgfile) |
275 | { | 249 | { |
276 | if ( (GNUNET_YES != | 250 | if ((GNUNET_YES != GNUNET_DISK_file_test (cc.cfgfile)) || |
277 | GNUNET_DISK_file_test (cc.cfgfile)) || | 251 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))) |
278 | (GNUNET_SYSERR == | ||
279 | GNUNET_CONFIGURATION_load (cfg, | ||
280 | cc.cfgfile)) ) | ||
281 | { | 252 | { |
282 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
283 | _("Unreadable or malformed configuration file `%s', exit ...\n"), | 254 | _ ( |
284 | cc.cfgfile); | 255 | "Unreadable or malformed configuration file `%s', exit ...\n"), |
256 | cc.cfgfile); | ||
285 | ret = GNUNET_SYSERR; | 257 | ret = GNUNET_SYSERR; |
286 | GNUNET_free (allopts); | 258 | GNUNET_free (allopts); |
287 | GNUNET_free (lpfx); | 259 | GNUNET_free (lpfx); |
@@ -290,51 +262,46 @@ GNUNET_PROGRAM_run2 (int argc, | |||
290 | } | 262 | } |
291 | else | 263 | else |
292 | { | 264 | { |
293 | if (GNUNET_YES == | 265 | if (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)) |
294 | GNUNET_DISK_file_test (cfg_fn)) | ||
295 | { | 266 | { |
296 | if (GNUNET_SYSERR == | 267 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) |
297 | GNUNET_CONFIGURATION_load (cfg, | ||
298 | cfg_fn)) | ||
299 | { | 268 | { |
300 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 269 | GNUNET_log ( |
301 | _("Unreadable or malformed default configuration file `%s', exit ...\n"), | 270 | GNUNET_ERROR_TYPE_ERROR, |
302 | cfg_fn); | 271 | _ ( |
303 | ret = GNUNET_SYSERR; | 272 | "Unreadable or malformed default configuration file `%s', exit ...\n"), |
304 | GNUNET_free (allopts); | 273 | cfg_fn); |
305 | GNUNET_free (lpfx); | 274 | ret = GNUNET_SYSERR; |
306 | goto cleanup; | 275 | GNUNET_free (allopts); |
276 | GNUNET_free (lpfx); | ||
277 | goto cleanup; | ||
307 | } | 278 | } |
308 | } | 279 | } |
309 | else | 280 | else |
310 | { | 281 | { |
311 | GNUNET_free (cfg_fn); | 282 | GNUNET_free (cfg_fn); |
312 | cfg_fn = NULL; | 283 | cfg_fn = NULL; |
313 | if (GNUNET_OK != | 284 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, NULL)) |
314 | GNUNET_CONFIGURATION_load (cfg, | ||
315 | NULL)) | ||
316 | { | 285 | { |
317 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 286 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
318 | _("Unreadable or malformed configuration, exit ...\n")); | 287 | _ ("Unreadable or malformed configuration, exit ...\n")); |
319 | ret = GNUNET_SYSERR; | 288 | ret = GNUNET_SYSERR; |
320 | GNUNET_free (allopts); | 289 | GNUNET_free (allopts); |
321 | GNUNET_free (lpfx); | 290 | GNUNET_free (lpfx); |
322 | goto cleanup; | 291 | goto cleanup; |
323 | } | 292 | } |
324 | } | 293 | } |
325 | } | 294 | } |
326 | GNUNET_free (allopts); | 295 | GNUNET_free (allopts); |
327 | GNUNET_free (lpfx); | 296 | GNUNET_free (lpfx); |
328 | if (GNUNET_OK == | 297 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, |
329 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, | 298 | "testing", |
330 | "testing", | 299 | "skew_offset", |
331 | "skew_offset", | 300 | &skew_offset) && |
332 | &skew_offset) && | 301 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, |
333 | (GNUNET_OK == | 302 | "testing", |
334 | GNUNET_CONFIGURATION_get_value_number (cc.cfg, | 303 | "skew_variance", |
335 | "testing", | 304 | &skew_variance))) |
336 | "skew_variance", | ||
337 | &skew_variance))) | ||
338 | { | 305 | { |
339 | clock_offset = skew_offset - skew_variance; | 306 | clock_offset = skew_offset - skew_variance; |
340 | GNUNET_TIME_set_offset (clock_offset); | 307 | GNUNET_TIME_set_offset (clock_offset); |
@@ -345,43 +312,29 @@ GNUNET_PROGRAM_run2 (int argc, | |||
345 | in "cfg". This is typically really only having an effect if we | 312 | in "cfg". This is typically really only having an effect if we |
346 | are running code in src/arm/, as obviously the rest of the code | 313 | are running code in src/arm/, as obviously the rest of the code |
347 | has little business with ARM-specific options. */ | 314 | has little business with ARM-specific options. */ |
348 | if (GNUNET_YES != | 315 | if (GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, "arm", "CONFIG")) |
349 | GNUNET_CONFIGURATION_have_value (cfg, | ||
350 | "arm", | ||
351 | "CONFIG")) | ||
352 | { | 316 | { |
353 | if (NULL != cc.cfgfile) | 317 | if (NULL != cc.cfgfile) |
354 | GNUNET_CONFIGURATION_set_value_string (cfg, | 318 | GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", cc.cfgfile); |
355 | "arm", | ||
356 | "CONFIG", | ||
357 | cc.cfgfile); | ||
358 | else if (NULL != cfg_fn) | 319 | else if (NULL != cfg_fn) |
359 | GNUNET_CONFIGURATION_set_value_string (cfg, | 320 | GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", cfg_fn); |
360 | "arm", | ||
361 | "CONFIG", | ||
362 | cfg_fn); | ||
363 | } | 321 | } |
364 | 322 | ||
365 | /* run */ | 323 | /* run */ |
366 | cc.args = &argv[ret]; | 324 | cc.args = &argv[ret]; |
367 | if ( (NULL == cc.cfgfile) && | 325 | if ((NULL == cc.cfgfile) && (NULL != cfg_fn)) |
368 | (NULL != cfg_fn) ) | ||
369 | cc.cfgfile = GNUNET_strdup (cfg_fn); | 326 | cc.cfgfile = GNUNET_strdup (cfg_fn); |
370 | if (GNUNET_NO == run_without_scheduler) | 327 | if (GNUNET_NO == run_without_scheduler) |
371 | { | 328 | { |
372 | GNUNET_SCHEDULER_run (&program_main, | 329 | GNUNET_SCHEDULER_run (&program_main, &cc); |
373 | &cc); | ||
374 | } | 330 | } |
375 | else | 331 | else |
376 | { | 332 | { |
377 | GNUNET_RESOLVER_connect (cc.cfg); | 333 | GNUNET_RESOLVER_connect (cc.cfg); |
378 | cc.task (cc.task_cls, | 334 | cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); |
379 | cc.args, | ||
380 | cc.cfgfile, | ||
381 | cc.cfg); | ||
382 | } | 335 | } |
383 | ret = GNUNET_OK; | 336 | ret = GNUNET_OK; |
384 | cleanup: | 337 | cleanup: |
385 | GNUNET_CONFIGURATION_destroy (cfg); | 338 | GNUNET_CONFIGURATION_destroy (cfg); |
386 | GNUNET_free_non_null (cc.cfgfile); | 339 | GNUNET_free_non_null (cc.cfgfile); |
387 | GNUNET_free_non_null (cfg_fn); | 340 | GNUNET_free_non_null (cfg_fn); |
@@ -405,17 +358,21 @@ GNUNET_PROGRAM_run2 (int argc, | |||
405 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 358 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
406 | */ | 359 | */ |
407 | int | 360 | int |
408 | GNUNET_PROGRAM_run (int argc, char *const *argv, | 361 | GNUNET_PROGRAM_run (int argc, |
362 | char *const *argv, | ||
409 | const char *binaryName, | 363 | const char *binaryName, |
410 | const char *binaryHelp, | 364 | const char *binaryHelp, |
411 | const struct GNUNET_GETOPT_CommandLineOption *options, | 365 | const struct GNUNET_GETOPT_CommandLineOption *options, |
412 | GNUNET_PROGRAM_Main task, | 366 | GNUNET_PROGRAM_Main task, |
413 | void *task_cls) | 367 | void *task_cls) |
414 | { | 368 | { |
415 | return GNUNET_PROGRAM_run2 (argc, argv, | 369 | return GNUNET_PROGRAM_run2 (argc, |
416 | binaryName, binaryHelp, | 370 | argv, |
371 | binaryName, | ||
372 | binaryHelp, | ||
417 | options, | 373 | options, |
418 | task, task_cls, | 374 | task, |
375 | task_cls, | ||
419 | GNUNET_NO); | 376 | GNUNET_NO); |
420 | } | 377 | } |
421 | 378 | ||