diff options
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r-- | src/arm/gnunet-arm.c | 159 |
1 files changed, 85 insertions, 74 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 75ade59da..3b024ea93 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -29,28 +29,6 @@ | |||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Timeout for stopping services. Long to give some services a real chance. | ||
33 | */ | ||
34 | #define STOP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1) | ||
35 | |||
36 | /** | ||
37 | * Timeout for stopping ARM. Extra-long since ARM needs to stop everyone else. | ||
38 | */ | ||
39 | #define STOP_TIMEOUT_ARM GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | ||
40 | |||
41 | /** | ||
42 | * Timeout for starting services, very short because of the strange way start works | ||
43 | * (by checking if running before starting, so really this time is always waited on | ||
44 | * startup (annoying)). | ||
45 | */ | ||
46 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
47 | |||
48 | /** | ||
49 | * Timeout for listing all running services. | ||
50 | */ | ||
51 | #define LIST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) | ||
52 | |||
53 | /** | ||
54 | * Set if we are to shutdown all services (including ARM). | 32 | * Set if we are to shutdown all services (including ARM). |
55 | */ | 33 | */ |
56 | static int end; | 34 | static int end; |
@@ -132,6 +110,7 @@ static unsigned int phase; | |||
132 | 110 | ||
133 | /** | 111 | /** |
134 | * User defined timestamp for completing operations. | 112 | * User defined timestamp for completing operations. |
113 | * FIXME: to be implemented! | ||
135 | */ | 114 | */ |
136 | static struct GNUNET_TIME_Relative timeout; | 115 | static struct GNUNET_TIME_Relative timeout; |
137 | 116 | ||
@@ -150,6 +129,10 @@ static unsigned int no_stderr; | |||
150 | */ | 129 | */ |
151 | static struct GNUNET_SCHEDULER_Task *al_task; | 130 | static struct GNUNET_SCHEDULER_Task *al_task; |
152 | 131 | ||
132 | /** | ||
133 | * Current operation. | ||
134 | */ | ||
135 | static struct GNUNET_ARM_Operation *op; | ||
153 | 136 | ||
154 | /** | 137 | /** |
155 | * Attempts to delete configuration file and GNUNET_HOME | 138 | * Attempts to delete configuration file and GNUNET_HOME |
@@ -193,14 +176,19 @@ shutdown_task (void *cls) | |||
193 | GNUNET_SCHEDULER_cancel (al_task); | 176 | GNUNET_SCHEDULER_cancel (al_task); |
194 | al_task = NULL; | 177 | al_task = NULL; |
195 | } | 178 | } |
179 | if (NULL != op) | ||
180 | { | ||
181 | GNUNET_ARM_operation_cancel (op); | ||
182 | op = NULL; | ||
183 | } | ||
196 | if (NULL != h) | 184 | if (NULL != h) |
197 | { | 185 | { |
198 | GNUNET_ARM_disconnect_and_free (h); | 186 | GNUNET_ARM_disconnect (h); |
199 | h = NULL; | 187 | h = NULL; |
200 | } | 188 | } |
201 | if (NULL != m) | 189 | if (NULL != m) |
202 | { | 190 | { |
203 | GNUNET_ARM_monitor_disconnect_and_free (m); | 191 | GNUNET_ARM_monitor_stop (m); |
204 | m = NULL; | 192 | m = NULL; |
205 | } | 193 | } |
206 | if ((GNUNET_YES == end) && (GNUNET_YES == delete)) | 194 | if ((GNUNET_YES == end) && (GNUNET_YES == delete)) |
@@ -229,8 +217,6 @@ req_string (enum GNUNET_ARM_RequestStatus rs) | |||
229 | return _("We disconnected from ARM before we could send a request"); | 217 | return _("We disconnected from ARM before we could send a request"); |
230 | case GNUNET_ARM_REQUEST_BUSY: | 218 | case GNUNET_ARM_REQUEST_BUSY: |
231 | return _("ARM API is busy"); | 219 | return _("ARM API is busy"); |
232 | case GNUNET_ARM_REQUEST_TOO_LONG: | ||
233 | return _("Request does not fit into a message"); | ||
234 | case GNUNET_ARM_REQUEST_TIMEOUT: | 220 | case GNUNET_ARM_REQUEST_TIMEOUT: |
235 | return _("Request timed out"); | 221 | return _("Request timed out"); |
236 | } | 222 | } |
@@ -289,8 +275,8 @@ action_loop (void *cls); | |||
289 | * our first attempt. | 275 | * our first attempt. |
290 | * | 276 | * |
291 | * @param cls closure | 277 | * @param cls closure |
292 | * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected, | 278 | * @param connected #GNUNET_YES if connected, #GNUNET_NO if disconnected, |
293 | * GNUNET_SYSERR on error. | 279 | * #GNUNET_SYSERR on error. |
294 | */ | 280 | */ |
295 | static void | 281 | static void |
296 | conn_status (void *cls, | 282 | conn_status (void *cls, |
@@ -318,18 +304,17 @@ conn_status (void *cls, | |||
318 | * | 304 | * |
319 | * @param cls closure unused | 305 | * @param cls closure unused |
320 | * @param rs what happened to our request | 306 | * @param rs what happened to our request |
321 | * @param service name of the service we tried to start ("arm") | ||
322 | * @param result if the request was processed, this is the result | 307 | * @param result if the request was processed, this is the result |
323 | * according to ARM | 308 | * according to ARM |
324 | */ | 309 | */ |
325 | static void | 310 | static void |
326 | start_callback (void *cls, | 311 | start_callback (void *cls, |
327 | enum GNUNET_ARM_RequestStatus rs, | 312 | enum GNUNET_ARM_RequestStatus rs, |
328 | const char *service, | ||
329 | enum GNUNET_ARM_Result result) | 313 | enum GNUNET_ARM_Result result) |
330 | { | 314 | { |
331 | char *msg; | 315 | char *msg; |
332 | 316 | ||
317 | op = NULL; | ||
333 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 318 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
334 | { | 319 | { |
335 | GNUNET_asprintf (&msg, "%s", _("Failed to start the ARM service: %s\n")); | 320 | GNUNET_asprintf (&msg, "%s", _("Failed to start the ARM service: %s\n")); |
@@ -362,18 +347,17 @@ start_callback (void *cls, | |||
362 | * | 347 | * |
363 | * @param cls closure unused | 348 | * @param cls closure unused |
364 | * @param rs what happened to our request | 349 | * @param rs what happened to our request |
365 | * @param service name of the service we tried to start ("arm") | ||
366 | * @param result if the request was processed, this is the result | 350 | * @param result if the request was processed, this is the result |
367 | * according to ARM | 351 | * according to ARM |
368 | */ | 352 | */ |
369 | static void | 353 | static void |
370 | stop_callback (void *cls, | 354 | stop_callback (void *cls, |
371 | enum GNUNET_ARM_RequestStatus rs, | 355 | enum GNUNET_ARM_RequestStatus rs, |
372 | const char *service, | ||
373 | enum GNUNET_ARM_Result result) | 356 | enum GNUNET_ARM_Result result) |
374 | { | 357 | { |
375 | char *msg; | 358 | char *msg; |
376 | 359 | ||
360 | op = NULL; | ||
377 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 361 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
378 | { | 362 | { |
379 | GNUNET_asprintf (&msg, "%s", | 363 | GNUNET_asprintf (&msg, "%s", |
@@ -416,18 +400,17 @@ stop_callback (void *cls, | |||
416 | * | 400 | * |
417 | * @param cls closure unused | 401 | * @param cls closure unused |
418 | * @param rs what happened to our request | 402 | * @param rs what happened to our request |
419 | * @param service name of the service we tried to start | ||
420 | * @param result if the request was processed, this is the result | 403 | * @param result if the request was processed, this is the result |
421 | * according to ARM | 404 | * according to ARM |
422 | */ | 405 | */ |
423 | static void | 406 | static void |
424 | init_callback (void *cls, | 407 | init_callback (void *cls, |
425 | enum GNUNET_ARM_RequestStatus rs, | 408 | enum GNUNET_ARM_RequestStatus rs, |
426 | const char *service, | ||
427 | enum GNUNET_ARM_Result result) | 409 | enum GNUNET_ARM_Result result) |
428 | { | 410 | { |
429 | char *msg; | 411 | char *msg; |
430 | 412 | ||
413 | op = NULL; | ||
431 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 414 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
432 | { | 415 | { |
433 | GNUNET_asprintf (&msg, | 416 | GNUNET_asprintf (&msg, |
@@ -441,9 +424,11 @@ init_callback (void *cls, | |||
441 | if ((GNUNET_ARM_RESULT_STARTING != result) && | 424 | if ((GNUNET_ARM_RESULT_STARTING != result) && |
442 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) | 425 | (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) |
443 | { | 426 | { |
444 | GNUNET_asprintf (&msg, _("Failed to start the `%s' service: %s\n"), | 427 | GNUNET_asprintf (&msg, |
445 | init, ret_string (result)); | 428 | _("Failed to start the `%s' service: %s\n"), |
446 | FPRINTF (stdout, msg, service); | 429 | init, |
430 | ret_string (result)); | ||
431 | FPRINTF (stdout, "%s", msg); | ||
447 | GNUNET_free (msg); | 432 | GNUNET_free (msg); |
448 | GNUNET_SCHEDULER_shutdown (); | 433 | GNUNET_SCHEDULER_shutdown (); |
449 | return; | 434 | return; |
@@ -465,17 +450,17 @@ init_callback (void *cls, | |||
465 | * | 450 | * |
466 | * @param cls closure unused | 451 | * @param cls closure unused |
467 | * @param rs what happened to our request | 452 | * @param rs what happened to our request |
468 | * @param service name of the service we tried to start | ||
469 | * @param result if the request was processed, this is the result | 453 | * @param result if the request was processed, this is the result |
470 | * according to ARM | 454 | * according to ARM |
471 | */ | 455 | */ |
472 | static void | 456 | static void |
473 | term_callback (void *cls, | 457 | term_callback (void *cls, |
474 | enum GNUNET_ARM_RequestStatus rs, | 458 | enum GNUNET_ARM_RequestStatus rs, |
475 | const char *service, | ||
476 | enum GNUNET_ARM_Result result) | 459 | enum GNUNET_ARM_Result result) |
477 | { | 460 | { |
478 | char *msg; | 461 | char *msg; |
462 | |||
463 | op = NULL; | ||
479 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 464 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
480 | { | 465 | { |
481 | GNUNET_asprintf (&msg, | 466 | GNUNET_asprintf (&msg, |
@@ -492,7 +477,7 @@ term_callback (void *cls, | |||
492 | GNUNET_asprintf (&msg, | 477 | GNUNET_asprintf (&msg, |
493 | _("Failed to kill the `%s' service: %s\n"), | 478 | _("Failed to kill the `%s' service: %s\n"), |
494 | term, ret_string (result)); | 479 | term, ret_string (result)); |
495 | FPRINTF (stdout, msg, service); | 480 | FPRINTF (stdout, "%s", msg); |
496 | GNUNET_free (msg); | 481 | GNUNET_free (msg); |
497 | GNUNET_SCHEDULER_shutdown (); | 482 | GNUNET_SCHEDULER_shutdown (); |
498 | return; | 483 | return; |
@@ -525,6 +510,7 @@ list_callback (void *cls, | |||
525 | { | 510 | { |
526 | unsigned int i; | 511 | unsigned int i; |
527 | 512 | ||
513 | op = NULL; | ||
528 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 514 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
529 | { | 515 | { |
530 | char *msg; | 516 | char *msg; |
@@ -573,9 +559,10 @@ action_loop (void *cls) | |||
573 | { | 559 | { |
574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
575 | "Termination action\n"); | 561 | "Termination action\n"); |
576 | GNUNET_ARM_request_service_stop (h, term, | 562 | op = GNUNET_ARM_request_service_stop (h, |
577 | (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout, | 563 | term, |
578 | &term_callback, NULL); | 564 | &term_callback, |
565 | NULL); | ||
579 | return; | 566 | return; |
580 | } | 567 | } |
581 | break; | 568 | break; |
@@ -584,9 +571,10 @@ action_loop (void *cls) | |||
584 | { | 571 | { |
585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
586 | "End action\n"); | 573 | "End action\n"); |
587 | GNUNET_ARM_request_service_stop (h, "arm", | 574 | op = GNUNET_ARM_request_service_stop (h, |
588 | (0 == timeout.rel_value_us) ? STOP_TIMEOUT_ARM : timeout, | 575 | "arm", |
589 | &stop_callback, NULL); | 576 | &stop_callback, |
577 | NULL); | ||
590 | return; | 578 | return; |
591 | } | 579 | } |
592 | break; | 580 | break; |
@@ -595,11 +583,11 @@ action_loop (void *cls) | |||
595 | { | 583 | { |
596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
597 | "Start action\n"); | 585 | "Start action\n"); |
598 | GNUNET_ARM_request_service_start (h, "arm", | 586 | op = GNUNET_ARM_request_service_start (h, "arm", |
599 | (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | | 587 | (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | |
600 | (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), | 588 | (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), |
601 | (0 == timeout.rel_value_us) ? START_TIMEOUT: timeout, | 589 | &start_callback, |
602 | start_callback, NULL); | 590 | NULL); |
603 | return; | 591 | return; |
604 | } | 592 | } |
605 | break; | 593 | break; |
@@ -608,10 +596,10 @@ action_loop (void *cls) | |||
608 | { | 596 | { |
609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
610 | "Initialization action\n"); | 598 | "Initialization action\n"); |
611 | GNUNET_ARM_request_service_start (h, init, | 599 | op = GNUNET_ARM_request_service_start (h, init, |
612 | GNUNET_OS_INHERIT_STD_NONE, | 600 | GNUNET_OS_INHERIT_STD_NONE, |
613 | (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout, | 601 | &init_callback, |
614 | &init_callback, NULL); | 602 | NULL); |
615 | return; | 603 | return; |
616 | } | 604 | } |
617 | break; | 605 | break; |
@@ -620,9 +608,9 @@ action_loop (void *cls) | |||
620 | { | 608 | { |
621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
622 | "Going to list all running services controlled by ARM.\n"); | 610 | "Going to list all running services controlled by ARM.\n"); |
623 | GNUNET_ARM_request_service_list (h, | 611 | op = GNUNET_ARM_request_service_list (h, |
624 | (0 == timeout.rel_value_us) ? LIST_TIMEOUT : timeout, | 612 | &list_callback, |
625 | &list_callback, &list); | 613 | &list); |
626 | return; | 614 | return; |
627 | } | 615 | } |
628 | break; | 616 | break; |
@@ -676,13 +664,21 @@ srv_status (void *cls, | |||
676 | break; | 664 | break; |
677 | } | 665 | } |
678 | if (! quiet) | 666 | if (! quiet) |
679 | { | 667 | { |
680 | if (NULL != msg) | 668 | if (NULL != msg) |
681 | FPRINTF (stderr, msg, service); | 669 | FPRINTF (stderr, |
682 | else | 670 | msg, |
683 | FPRINTF (stderr, _("Unknown status %u for service %s.\n"), status, service); | 671 | service); |
684 | } | 672 | else |
685 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got service %s status %d\n", service, (int) status); | 673 | FPRINTF (stderr, |
674 | _("Unknown status %u for service %s.\n"), | ||
675 | status, | ||
676 | service); | ||
677 | } | ||
678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
679 | "Got service %s status %d\n", | ||
680 | service, (int) | ||
681 | status); | ||
686 | } | 682 | } |
687 | 683 | ||
688 | 684 | ||
@@ -705,30 +701,44 @@ run (void *cls, | |||
705 | cfg = GNUNET_CONFIGURATION_dup (c); | 701 | cfg = GNUNET_CONFIGURATION_dup (c); |
706 | config_file = cfgfile; | 702 | config_file = cfgfile; |
707 | if (GNUNET_OK != | 703 | if (GNUNET_OK != |
708 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "GNUNET_HOME", &dir)) | 704 | GNUNET_CONFIGURATION_get_value_string (cfg, |
705 | "PATHS", | ||
706 | "GNUNET_HOME", | ||
707 | &dir)) | ||
709 | { | 708 | { |
710 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 709 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
711 | "PATHS", "GNUNET_HOME"); | 710 | "PATHS", |
711 | "GNUNET_HOME"); | ||
712 | return; | 712 | return; |
713 | } | 713 | } |
714 | if (NULL != cfgfile) | 714 | if (NULL != cfgfile) |
715 | { | 715 | { |
716 | if (GNUNET_OK != | 716 | if (GNUNET_OK != |
717 | GNUNET_CONFIGURATION_get_value_filename (cfg, "arm", "CONFIG", | 717 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
718 | "arm", | ||
719 | "CONFIG", | ||
718 | &armconfig)) | 720 | &armconfig)) |
719 | { | 721 | { |
720 | GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", | 722 | GNUNET_CONFIGURATION_set_value_string (cfg, |
723 | "arm", | ||
724 | "CONFIG", | ||
721 | cfgfile); | 725 | cfgfile); |
722 | } | 726 | } |
723 | else | 727 | else |
724 | GNUNET_free (armconfig); | 728 | GNUNET_free (armconfig); |
725 | } | 729 | } |
726 | if (NULL == (h = GNUNET_ARM_connect (cfg, &conn_status, NULL))) | 730 | if (NULL == (h = GNUNET_ARM_connect (cfg, |
731 | &conn_status, | ||
732 | NULL))) | ||
727 | return; | 733 | return; |
728 | if (monitor) | 734 | if (monitor) |
729 | m = GNUNET_ARM_monitor (cfg, &srv_status, NULL); | 735 | m = GNUNET_ARM_monitor_start (cfg, |
730 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL); | 736 | &srv_status, |
731 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 737 | NULL); |
738 | al_task = GNUNET_SCHEDULER_add_now (&action_loop, | ||
739 | NULL); | ||
740 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
741 | NULL); | ||
732 | } | 742 | } |
733 | 743 | ||
734 | 744 | ||
@@ -774,7 +784,8 @@ main (int argc, char *const *argv) | |||
774 | GNUNET_GETOPT_OPTION_END | 784 | GNUNET_GETOPT_OPTION_END |
775 | }; | 785 | }; |
776 | 786 | ||
777 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 787 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, |
788 | &argc, &argv)) | ||
778 | return 2; | 789 | return 2; |
779 | 790 | ||
780 | if (GNUNET_OK == | 791 | if (GNUNET_OK == |