aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-service-arm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/gnunet-service-arm.c')
-rw-r--r--src/arm/gnunet-service-arm.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index f907d944f..4a30848eb 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -157,6 +157,17 @@ static char *prefix_command;
157 */ 157 */
158static int in_shutdown; 158static int in_shutdown;
159 159
160/**
161 * Handle to our server instance. Our server is a bit special in that
162 * its service is not immediately stopped once we get a shutdown
163 * request (since we need to continue service until all of our child
164 * processes are dead). This handle is used to shut down the server
165 * (and thus trigger process termination) once all child processes are
166 * also dead. A special option in the ARM configuration modifies the
167 * behaviour of the service implementation to not do the shutdown
168 * immediately.
169 */
170static struct GNUNET_SERVER_Handle *server;
160 171
161/** 172/**
162 * Background task doing maintenance. 173 * Background task doing maintenance.
@@ -646,9 +657,16 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
646 pos = running; 657 pos = running;
647 while (NULL != pos) 658 while (NULL != pos)
648 { 659 {
649 if ( (pos->pid != 0) && 660 if (pos->pid != 0)
650 (0 != PLIBC_KILL (pos->pid, SIGTERM)) ) 661 {
651 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 662#if DEBUG_ARM
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
664 "Sending SIGTERM to `%s'\n",
665 pos->name);
666#endif
667 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
668 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
669 }
652 pos = pos->next; 670 pos = pos->next;
653 } 671 }
654 } 672 }
@@ -656,7 +674,14 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
656 { 674 {
657 if ( (in_shutdown == GNUNET_YES) && 675 if ( (in_shutdown == GNUNET_YES) &&
658 (running == NULL) ) 676 (running == NULL) )
659 return; /* we are done! */ 677 {
678#if DEBUG_ARM
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "ARM service terminates.\n");
681#endif
682 GNUNET_SERVER_destroy (server);
683 return; /* we are done! */
684 }
660 GNUNET_SCHEDULER_add_delayed (tc->sched, 685 GNUNET_SCHEDULER_add_delayed (tc->sched,
661 (in_shutdown == GNUNET_YES) 686 (in_shutdown == GNUNET_YES)
662 ? MAINT_FAST_FREQUENCY 687 ? MAINT_FAST_FREQUENCY
@@ -716,6 +741,12 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
716 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 741 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
717 _("Service `%s' terminated with status %s/%d, will try to restart it!\n"), 742 _("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
718 pos->name, statstr, statcode); 743 pos->name, statstr, statcode);
744#if DEBUG_ARM
745 else
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
747 "Service `%s' terminated with status %s/%d\n",
748 pos->name, statstr, statcode);
749#endif
719 /* schedule restart */ 750 /* schedule restart */
720 pos->pid = 0; 751 pos->pid = 0;
721 prev = pos; 752 prev = pos;
@@ -762,20 +793,22 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = {
762 * 793 *
763 * @param cls closure 794 * @param cls closure
764 * @param s scheduler to use 795 * @param s scheduler to use
765 * @param server the initialized server 796 * @param serv the initialized server
766 * @param c configuration to use 797 * @param c configuration to use
767 */ 798 */
768static void 799static void
769run (void *cls, 800run (void *cls,
770 struct GNUNET_SCHEDULER_Handle *s, 801 struct GNUNET_SCHEDULER_Handle *s,
771 struct GNUNET_SERVER_Handle *server, 802 struct GNUNET_SERVER_Handle *serv,
772 const struct GNUNET_CONFIGURATION_Handle *c) 803 const struct GNUNET_CONFIGURATION_Handle *c)
773{ 804{
774 char *defaultservices; 805 char *defaultservices;
775 char *pos; 806 char *pos;
776 807
808 GNUNET_assert (serv != NULL);
777 cfg = c; 809 cfg = c;
778 sched = s; 810 sched = s;
811 server = serv;
779 if (GNUNET_OK != 812 if (GNUNET_OK !=
780 GNUNET_CONFIGURATION_get_value_string (cfg, 813 GNUNET_CONFIGURATION_get_value_string (cfg,
781 "ARM", 814 "ARM",
@@ -831,7 +864,9 @@ main (int argc, char *const *argv)
831{ 864{
832 return (GNUNET_OK == 865 return (GNUNET_OK ==
833 GNUNET_SERVICE_run (argc, 866 GNUNET_SERVICE_run (argc,
834 argv, "arm", &run, NULL)) ? 0 : 1; 867 argv, "arm",
868 GNUNET_YES,
869 &run, NULL)) ? 0 : 1;
835} 870}
836 871
837/* end of gnunet-service-arm.c */ 872/* end of gnunet-service-arm.c */