diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-15 18:12:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-15 18:12:19 +0000 |
commit | a0c94d4eb2f763009cd0479e9b8a7da97a0bd650 (patch) | |
tree | 269aca985cae19d38f39f40141c0067cf08895d3 /src/arm | |
parent | 40f30cc7674b97ad4961b1afc45c5e802b83e32f (diff) | |
download | gnunet-a0c94d4eb2f763009cd0479e9b8a7da97a0bd650.tar.gz gnunet-a0c94d4eb2f763009cd0479e9b8a7da97a0bd650.zip |
cleaner handling of clients and service processes, ignore shutdown
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/arm_api.c | 4 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.c | 88 |
2 files changed, 46 insertions, 46 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 6e4a90103..256df3320 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -265,7 +265,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
265 | } | 265 | } |
266 | #if DEBUG_ARM | 266 | #if DEBUG_ARM |
267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
268 | "Received response from ARM for service `%s': %u\n", | 268 | "Received response from ARM for service `%s': %u\n", |
269 | (const char*) &sc[1], | 269 | (const char*) &sc[1], |
270 | ntohs(msg->type)); | 270 | ntohs(msg->type)); |
271 | #endif | 271 | #endif |
@@ -379,7 +379,7 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | |||
379 | size_t slen; | 379 | size_t slen; |
380 | 380 | ||
381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
382 | _("Asked to starting service `%s' within %llu ms\n"), service_name, | 382 | _("Asked to start service `%s' within %llu ms\n"), service_name, |
383 | (unsigned long long) timeout.value); | 383 | (unsigned long long) timeout.value); |
384 | if (0 == strcasecmp ("arm", service_name)) | 384 | if (0 == strcasecmp ("arm", service_name)) |
385 | { | 385 | { |
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index d48df260c..cc9e2cd27 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -194,7 +194,11 @@ write_result (void *cls, size_t size, void *buf) | |||
194 | struct GNUNET_MessageHeader *msg; | 194 | struct GNUNET_MessageHeader *msg; |
195 | 195 | ||
196 | if (buf == NULL) | 196 | if (buf == NULL) |
197 | return 0; /* error, not much we can do */ | 197 | { |
198 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
199 | _("Could not send status result to client\n")); | ||
200 | return 0; /* error, not much we can do */ | ||
201 | } | ||
198 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 202 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
199 | msg = buf; | 203 | msg = buf; |
200 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 204 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -221,7 +225,11 @@ signal_result (struct GNUNET_SERVER_Client *client, | |||
221 | uint16_t *res; | 225 | uint16_t *res; |
222 | 226 | ||
223 | if (NULL == client) | 227 | if (NULL == client) |
224 | return; | 228 | { |
229 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
230 | _("Not sending status result to client: no client known\n")); | ||
231 | return; | ||
232 | } | ||
225 | #if DEBUG_ARM | 233 | #if DEBUG_ARM |
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
227 | "Telling client that service `%s' is now %s\n", | 235 | "Telling client that service `%s' is now %s\n", |
@@ -493,25 +501,17 @@ stop_service (struct GNUNET_SERVER_Client *client, | |||
493 | const char *servicename) | 501 | const char *servicename) |
494 | { | 502 | { |
495 | struct ServiceList *pos; | 503 | struct ServiceList *pos; |
496 | struct GNUNET_CLIENT_Connection *sc; | ||
497 | unsigned long long port; | ||
498 | 504 | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 505 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
500 | _("Preparing to stop `%s'\n"), servicename); | 506 | _("Preparing to stop `%s'\n"), servicename); |
501 | pos = find_name (servicename); | 507 | pos = find_name (servicename); |
502 | if ( (pos != NULL) && | 508 | if (pos == NULL) |
503 | ( (pos->kill_continuation != NULL) || | ||
504 | (GNUNET_YES == in_shutdown) ) ) | ||
505 | { | 509 | { |
506 | /* killing already in progress */ | 510 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN); |
507 | #if DEBUG_ARM | 511 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
509 | "Service `%s' is already down\n", servicename); | ||
510 | #endif | ||
511 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | ||
512 | return; | 512 | return; |
513 | } | 513 | } |
514 | if ((pos != NULL) && (pos->rc > 1)) | 514 | if (pos->rc > 1) |
515 | { | 515 | { |
516 | /* RC>1, just decrement RC */ | 516 | /* RC>1, just decrement RC */ |
517 | pos->rc--; | 517 | pos->rc--; |
@@ -527,48 +527,47 @@ stop_service (struct GNUNET_SERVER_Client *client, | |||
527 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 527 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
528 | return; | 528 | return; |
529 | } | 529 | } |
530 | if (pos != NULL) | 530 | if (pos->rc == 1) |
531 | pos->rc--; /* decrement RC to zero */ | ||
532 | if (pos->kill_continuation != NULL) | ||
531 | { | 533 | { |
534 | /* killing already in progress */ | ||
532 | #if DEBUG_ARM | 535 | #if DEBUG_ARM |
533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
534 | "Sending kill signal to service `%s', waiting for process to die.\n", | 537 | "Service `%s' is already down\n", servicename); |
535 | servicename); | ||
536 | #endif | 538 | #endif |
537 | if (0 != PLIBC_KILL (pos->pid, SIGTERM)) | 539 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
538 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 540 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
539 | pos->next = running; | 541 | return; |
540 | running = pos; | ||
541 | pos->kill_continuation = &free_and_signal; | ||
542 | pos->kill_continuation_cls = client; | ||
543 | GNUNET_SERVER_client_keep (client); | ||
544 | GNUNET_SCHEDULER_add_delayed (sched, | ||
545 | MAINT_FAST_FREQUENCY, &maint, "non-null"); | ||
546 | } | 542 | } |
547 | else | 543 | |
544 | if (GNUNET_YES == in_shutdown) | ||
548 | { | 545 | { |
549 | if (GNUNET_YES == in_shutdown) | ||
550 | return; | ||
551 | #if DEBUG_ARM | 546 | #if DEBUG_ARM |
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
553 | "Sending termination request to service `%s'.\n", | 548 | "Termination request already sent to `%s' (since ARM is in shutdown).\n", |
554 | servicename); | 549 | servicename); |
555 | #endif | 550 | #endif |
556 | if ( (GNUNET_OK == | 551 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
557 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
558 | servicename, | ||
559 | "PORT", | ||
560 | &port)) && | ||
561 | (NULL != (sc = GNUNET_CLIENT_connect (sched, servicename, cfg))) ) | ||
562 | { | ||
563 | GNUNET_CLIENT_service_shutdown (sc); | ||
564 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | ||
565 | } | ||
566 | else | ||
567 | { | ||
568 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN); | ||
569 | } | ||
570 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 552 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
553 | return; | ||
571 | } | 554 | } |
555 | |||
556 | |||
557 | #if DEBUG_ARM | ||
558 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
559 | "Sending kill signal to service `%s', waiting for process to die.\n", | ||
560 | servicename); | ||
561 | #endif | ||
562 | if (0 != PLIBC_KILL (pos->pid, SIGTERM)) | ||
563 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
564 | pos->next = running; | ||
565 | running = pos; | ||
566 | pos->kill_continuation = &free_and_signal; | ||
567 | pos->kill_continuation_cls = client; | ||
568 | GNUNET_SERVER_client_keep (client); | ||
569 | GNUNET_SCHEDULER_add_delayed (sched, | ||
570 | MAINT_FAST_FREQUENCY, &maint, "non-null"); | ||
572 | } | 571 | } |
573 | 572 | ||
574 | 573 | ||
@@ -807,6 +806,7 @@ run (void *cls, | |||
807 | char *defaultservices; | 806 | char *defaultservices; |
808 | char *pos; | 807 | char *pos; |
809 | 808 | ||
809 | GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES); | ||
810 | GNUNET_assert (serv != NULL); | 810 | GNUNET_assert (serv != NULL); |
811 | cfg = c; | 811 | cfg = c; |
812 | sched = s; | 812 | sched = s; |