diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-02-06 12:51:24 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-02-06 12:51:24 +0000 |
commit | ffe595aa89fb7fb782800c3507762cb726de322f (patch) | |
tree | 19c04edf72b115944fbb0e54e381c10cb8e80c88 /src | |
parent | 2a37056aa302c9534dc0da3101e3065bd0c1df48 (diff) | |
download | gnunet-ffe595aa89fb7fb782800c3507762cb726de322f.tar.gz gnunet-ffe595aa89fb7fb782800c3507762cb726de322f.zip |
simplify
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/gnunet-service-arm.c | 64 |
1 files changed, 18 insertions, 46 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 4de34ea28..c7d5a62d2 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -61,15 +61,6 @@ | |||
61 | struct ServiceList; | 61 | struct ServiceList; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Function to call if waitpid informs us that | ||
65 | * a process has died. | ||
66 | * | ||
67 | * @param cls closure | ||
68 | * @param pos entry in the service list of the process that died | ||
69 | */ | ||
70 | typedef void (*CleanCallback) (void *cls, struct ServiceList * pos); | ||
71 | |||
72 | /** | ||
73 | * List of our services. | 64 | * List of our services. |
74 | */ | 65 | */ |
75 | struct ServiceList | 66 | struct ServiceList |
@@ -95,15 +86,10 @@ struct ServiceList | |||
95 | char *config; | 86 | char *config; |
96 | 87 | ||
97 | /** | 88 | /** |
98 | * Function to call upon kill completion (waitpid), NULL | 89 | * Client to notify upon kill completion (waitpid), NULL |
99 | * if we should simply restart the process. | 90 | * if we should simply restart the process. |
100 | */ | 91 | */ |
101 | CleanCallback kill_continuation; | 92 | struct GNUNET_SERVER_Client *killing_client; |
102 | |||
103 | /** | ||
104 | * Closure for kill_continuation. | ||
105 | */ | ||
106 | void *kill_continuation_cls; | ||
107 | 93 | ||
108 | /** | 94 | /** |
109 | * Process ID of the child. | 95 | * Process ID of the child. |
@@ -528,26 +514,6 @@ start_service (struct GNUNET_SERVER_Client *client, const char *servicename) | |||
528 | 514 | ||
529 | 515 | ||
530 | /** | 516 | /** |
531 | * Free the given entry in the service list and signal | ||
532 | * the given client that the service is now down. | ||
533 | * | ||
534 | * @param cls pointer to the client ("struct GNUNET_SERVER_Client*") | ||
535 | * @param pos entry for the service | ||
536 | */ | ||
537 | static void | ||
538 | free_and_signal (void *cls, struct ServiceList *pos) | ||
539 | { | ||
540 | struct GNUNET_SERVER_Client *client = cls; | ||
541 | /* find_name will remove "pos" from the list! */ | ||
542 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Service `%s' stopped\n", pos->name); | ||
543 | signal_result (client, pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | ||
544 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
545 | GNUNET_SERVER_client_drop (client); | ||
546 | free_entry (pos); | ||
547 | } | ||
548 | |||
549 | |||
550 | /** | ||
551 | * Stop the specified service. | 517 | * Stop the specified service. |
552 | * | 518 | * |
553 | * @param client who is asking for this | 519 | * @param client who is asking for this |
@@ -584,7 +550,7 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename) | |||
584 | } | 550 | } |
585 | if (pos->rc == 1) | 551 | if (pos->rc == 1) |
586 | pos->rc--; /* decrement RC to zero */ | 552 | pos->rc--; /* decrement RC to zero */ |
587 | if (pos->kill_continuation != NULL) | 553 | if (pos->killing_client != NULL) |
588 | { | 554 | { |
589 | /* killing already in progress */ | 555 | /* killing already in progress */ |
590 | #if DEBUG_ARM | 556 | #if DEBUG_ARM |
@@ -607,8 +573,6 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename) | |||
607 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 573 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
608 | return; | 574 | return; |
609 | } | 575 | } |
610 | |||
611 | |||
612 | #if DEBUG_ARM | 576 | #if DEBUG_ARM |
613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
614 | "Sending kill signal to service `%s', waiting for process to die.\n", | 578 | "Sending kill signal to service `%s', waiting for process to die.\n", |
@@ -618,8 +582,7 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename) | |||
618 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 582 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
619 | pos->next = running; | 583 | pos->next = running; |
620 | running = pos; | 584 | running = pos; |
621 | pos->kill_continuation = &free_and_signal; | 585 | pos->killing_client = client; |
622 | pos->kill_continuation_cls = client; | ||
623 | GNUNET_SERVER_client_keep (client); | 586 | GNUNET_SERVER_client_keep (client); |
624 | } | 587 | } |
625 | 588 | ||
@@ -830,7 +793,8 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
830 | 793 | ||
831 | 794 | ||
832 | /** | 795 | /** |
833 | * | 796 | * Task triggered whenever we receive a SIGCHLD (child |
797 | * process died). | ||
834 | * | 798 | * |
835 | * @param cls closure, NULL if we need to self-restart | 799 | * @param cls closure, NULL if we need to self-restart |
836 | * @param tc context | 800 | * @param tc context |
@@ -844,7 +808,7 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
844 | const char *statstr; | 808 | const char *statstr; |
845 | int statcode; | 809 | int statcode; |
846 | int ret; | 810 | int ret; |
847 | char c; | 811 | char c[16]; |
848 | 812 | ||
849 | child_death_task = GNUNET_SCHEDULER_NO_TASK; | 813 | child_death_task = GNUNET_SCHEDULER_NO_TASK; |
850 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 814 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
@@ -897,13 +861,20 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
897 | statcode = 0; | 861 | statcode = 0; |
898 | } | 862 | } |
899 | pos->pid = 0; | 863 | pos->pid = 0; |
900 | if (NULL != pos->kill_continuation) | 864 | if (NULL != pos->killing_client) |
901 | { | 865 | { |
902 | if (prev == NULL) | 866 | if (prev == NULL) |
903 | running = next; | 867 | running = next; |
904 | else | 868 | else |
905 | prev->next = next; | 869 | prev->next = next; |
906 | pos->kill_continuation (pos->kill_continuation_cls, pos); | 870 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
871 | "Service `%s' stopped\n", | ||
872 | pos->name); | ||
873 | signal_result (pos->killing_client, | ||
874 | pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | ||
875 | GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK); | ||
876 | GNUNET_SERVER_client_drop (pos->killing_client); | ||
877 | free_entry (pos); | ||
907 | continue; | 878 | continue; |
908 | } | 879 | } |
909 | if (GNUNET_YES != in_shutdown) | 880 | if (GNUNET_YES != in_shutdown) |
@@ -962,7 +933,8 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
962 | }; | 933 | }; |
963 | 934 | ||
964 | /** | 935 | /** |
965 | * Signal handler called for signals that should cause us to shutdown. | 936 | * Signal handler called for SIGCHLD. Triggers the |
937 | * respective handler by writing to the trigger pipe. | ||
966 | */ | 938 | */ |
967 | static void | 939 | static void |
968 | sighandler_child_death () | 940 | sighandler_child_death () |