2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file arm/gnunet-service-arm.c
23 * @brief the automated restart manager service
24 * @author Christian Grothoff
27 * - need to test auto-restart code on configuration changes;
28 * - should refine restart code to check if *relevant* parts of the
29 * configuration were changed (anything in the section for the service)
30 * - should have a way to specify dependencies between services and
31 * manage restarts of groups of services
34 #include "gnunet_client_lib.h"
35 #include "gnunet_getopt_lib.h"
36 #include "gnunet_os_lib.h"
37 #include "gnunet_protocols.h"
38 #include "gnunet_service_lib.h"
39 #include "gnunet_signal_lib.h"
40 #include "gnunet-service-arm.h"
45 * Check for configuration file changes every 5s.
47 #define MAINT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
50 * Threshold after which exponential backoff shouldn't increase (in ms); 30m
52 #define EXPONENTIAL_BACKOFF_THRESHOLD (1000 * 60 * 30)
54 #define DELAY_SHUTDOWN GNUNET_NO
57 * List of our services.
63 * List of our services.
68 * This is a linked list.
70 struct ServiceList *next;
73 * Name of the service.
78 * Name of the binary used.
83 * Name of the configuration file used.
88 * Client to notify upon kill completion (waitpid), NULL
89 * if we should simply restart the process.
91 struct GNUNET_SERVER_Client *killing_client;
94 * Process ID of the child.
99 * Last time the config of this service was
105 * Process exponential backoff time
107 struct GNUNET_TIME_Relative backoff;
110 * Absolute time at which the process is scheduled to restart in case of death
112 struct GNUNET_TIME_Absolute restartAt;
117 * List of running services.
119 static struct ServiceList *running;
124 static const struct GNUNET_CONFIGURATION_Handle *cfg;
129 static struct GNUNET_SCHEDULER_Handle *sched;
132 * Command to prepend to each actual command.
134 static char *prefix_command;
137 * Option to append to each actual command.
139 static char *final_option;
142 * ID of task called whenever we get a SIGCHILD.
144 static GNUNET_SCHEDULER_TaskIdentifier child_death_task;
147 * ID of task called whenever the timeout for restarting a child
150 static GNUNET_SCHEDULER_TaskIdentifier child_restart_task;
153 * Context for our SIGCHILD handler.
155 static struct GNUNET_SIGNAL_Context *shc_chld;
158 * Pipe used to communicate shutdown via signal.
160 static struct GNUNET_DISK_PipeHandle *sigpipe;
163 * Reading end of the signal pipe.
165 static const struct GNUNET_DISK_FileHandle *pr;
168 * Are we in shutdown mode?
170 static int in_shutdown;
174 * Handle to our server instance. Our server is a bit special in that
175 * its service is not immediately stopped once we get a shutdown
176 * request (since we need to continue service until all of our child
177 * processes are dead). This handle is used to shut down the server
178 * (and thus trigger process termination) once all child processes are
179 * also dead. A special option in the ARM configuration modifies the
180 * behaviour of the service implementation to not do the shutdown
183 static struct GNUNET_SERVER_Handle *server;
187 * If the configuration file changes, restart tasks that depended on that
190 * @param cls closure, NULL if we need to self-restart
194 config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
196 struct ServiceList *pos;
202 /* FIXME: this test for config change is a bit too coarse grained */
203 if ( (0 == STAT (pos->config, &sbuf)) &&
204 (pos->mtime < sbuf.st_mtime) &&
207 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
208 _("Restarting service `%s' due to configuration file change.\n"));
209 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
210 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
212 pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
221 * Transmit a status result message.
223 * @param cls pointer to "unit16_t*" with message type
224 * @param size number of bytes available in buf
225 * @param buf where to copy the message, NULL on error
226 * @return number of bytes copied to buf
229 write_result (void *cls, size_t size, void *buf)
232 struct GNUNET_MessageHeader *msg;
236 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
237 _("Could not send status result to client\n"));
238 return 0; /* error, not much we can do */
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Sending status response %u to client\n",
243 (unsigned int) *res);
245 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
247 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
248 msg->type = htons (*res);
250 return sizeof (struct GNUNET_MessageHeader);
256 * Signal our client that we will start or stop the
259 * @param client who is being signalled
260 * @param name name of the service
261 * @param result message type to send
262 * @return NULL if it was not found
265 signal_result (struct GNUNET_SERVER_Client *client,
266 const char *name, uint16_t result)
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
274 ("Not sending status result to client: no client known\n"));
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
279 "Telling client that service `%s' is now %s\n",
281 result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
283 res = GNUNET_malloc (sizeof (uint16_t));
285 GNUNET_SERVER_notify_transmit_ready (client,
286 sizeof (struct GNUNET_MessageHeader),
287 GNUNET_TIME_UNIT_FOREVER_REL,
293 * Find the process with the given service
294 * name in the given list, remove it and return it.
296 * @param name which service entry to look up
297 * @return NULL if it was not found
299 static struct ServiceList *
300 find_name (const char *name)
302 struct ServiceList *pos;
303 struct ServiceList *prev;
309 if (0 == strcmp (pos->name, name))
314 prev->next = pos->next;
326 * Free an entry in the service list.
328 * @param pos entry to free
331 free_entry (struct ServiceList *pos)
333 GNUNET_free_non_null (pos->config);
334 GNUNET_free_non_null (pos->binary);
335 GNUNET_free (pos->name);
339 #include "do_start_process.c"
342 * Actually start the process for the given service.
344 * @param sl identifies service to start
345 * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL
348 start_process (struct ServiceList *sl,
362 GNUNET_CONFIGURATION_get_value_string (cfg,
363 sl->name, "PREFIX", &loprefix))
364 loprefix = GNUNET_strdup (prefix_command);
366 GNUNET_CONFIGURATION_get_value_string (cfg,
367 sl->name, "OPTIONS", &options))
369 options = GNUNET_strdup (final_option);
370 if (NULL == strstr (options, "%"))
372 /* replace '{}' with service name */
373 while (NULL != (optpos = strstr (options, "{}")))
377 GNUNET_asprintf (&optpos,
380 GNUNET_free (options);
383 /* replace '$PATH' with value associated with "PATH" */
384 while (NULL != (optpos = strstr (options, "$")))
387 while (isupper ( (unsigned char) *optend)) optend++;
395 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
398 val = GNUNET_strdup ("");
400 GNUNET_asprintf (&optpos,
406 GNUNET_free (options);
412 use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
416 "Starting service `%s' using binary `%s' and configuration `%s'\n",
417 sl->name, sl->binary, sl->config);
419 if (GNUNET_YES == use_debug)
420 sl->pid = do_start_process (lsocks,
428 sl->pid = do_start_process (lsocks,
434 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
435 _("Starting service `%s' (PID: %d)\n"),
438 GNUNET_free (loprefix);
439 GNUNET_free (options);
440 /* FIXME: should check sl->pid */
445 * Start the specified service.
447 * @param client who is asking for this
448 * @param servicename name of the service to start
449 * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL
450 * @return GNUNET_OK on success, GNUNET_SYSERR on error
453 start_service (struct GNUNET_SERVER_Client *client,
454 const char *servicename,
457 struct ServiceList *sl;
462 if (GNUNET_YES == in_shutdown)
464 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
465 _("ARM is shutting down, service `%s' not started.\n"),
467 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
468 return GNUNET_SYSERR;
470 sl = find_name (servicename);
473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
474 _("Service `%s' already running.\n"), servicename);
477 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
478 return GNUNET_SYSERR;
481 GNUNET_CONFIGURATION_get_value_string (cfg,
482 servicename, "BINARY", &binary))
484 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
485 _("Binary implementing service `%s' not known!\n"),
487 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
488 return GNUNET_SYSERR;
491 GNUNET_CONFIGURATION_get_value_filename (cfg,
495 (0 != STAT (config, &sbuf)))
497 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
498 _("Configuration file `%s' for service `%s' not known!\n"),
499 config, servicename);
500 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
501 GNUNET_free (binary);
502 GNUNET_free_non_null (config);
503 return GNUNET_SYSERR;
505 (void) stop_listening (servicename);
506 sl = GNUNET_malloc (sizeof (struct ServiceList));
507 sl->name = GNUNET_strdup (servicename);
511 sl->mtime = sbuf.st_mtime;
512 sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
513 sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS;
516 start_process (sl, lsocks);
518 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
524 * Stop the specified service.
526 * @param client who is asking for this
527 * @param servicename name of the service to stop
530 stop_service (struct GNUNET_SERVER_Client *client,
531 const char *servicename)
533 struct ServiceList *pos;
535 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
536 _("Preparing to stop `%s'\n"), servicename);
537 pos = find_name (servicename);
540 if (GNUNET_OK == stop_listening (servicename))
541 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
543 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
544 GNUNET_SERVER_receive_done (client, GNUNET_OK);
547 if (pos->killing_client != NULL)
549 /* killing already in progress */
551 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
552 "Service `%s' is already down\n", servicename);
554 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
555 GNUNET_SERVER_receive_done (client, GNUNET_OK);
561 if (GNUNET_YES == in_shutdown)
564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
565 "Termination request already sent to `%s' (since ARM is in shutdown).\n",
568 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
569 GNUNET_SERVER_receive_done (client, GNUNET_OK);
576 /* process is in delayed restart, simply remove it! */
578 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
579 GNUNET_SERVER_receive_done (client, GNUNET_OK);
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
584 "Sending kill signal to service `%s', waiting for process to die.\n",
587 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
588 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
591 pos->killing_client = client;
592 GNUNET_SERVER_client_keep (client);
597 * Handle START-message.
599 * @param cls closure (always NULL)
600 * @param client identification of the client
601 * @param message the actual message
602 * @return GNUNET_OK to keep the connection open,
603 * GNUNET_SYSERR to close it (signal serious error)
606 handle_start (void *cls,
607 struct GNUNET_SERVER_Client *client,
608 const struct GNUNET_MessageHeader *message)
610 const char *servicename;
613 size = ntohs (message->size);
614 size -= sizeof (struct GNUNET_MessageHeader);
615 servicename = (const char *) &message[1];
616 if ((size == 0) || (servicename[size - 1] != '\0'))
619 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
622 start_service (client, servicename, NULL);
623 GNUNET_SERVER_receive_done (client, GNUNET_OK);
628 * Handle STOP-message.
630 * @param cls closure (always NULL)
631 * @param client identification of the client
632 * @param message the actual message
633 * @return GNUNET_OK to keep the connection open,
634 * GNUNET_SYSERR to close it (signal serious error)
637 handle_stop (void *cls,
638 struct GNUNET_SERVER_Client *client,
639 const struct GNUNET_MessageHeader *message)
641 const char *servicename;
644 size = ntohs (message->size);
645 size -= sizeof (struct GNUNET_MessageHeader);
646 servicename = (const char *) &message[1];
647 if ((size == 0) || (servicename[size - 1] != '\0'))
650 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
653 stop_service (client, servicename);
658 * Remove all entries for tasks that are not running
659 * (pid = 0) from the running list (they will no longer
660 * be restarted since we are shutting down).
665 struct ServiceList *pos;
666 struct ServiceList *next;
667 struct ServiceList *prev;
690 * We are done with everything. Stop remaining
691 * tasks, signal handler and the server.
696 GNUNET_SERVER_destroy (server);
698 GNUNET_SIGNAL_handler_uninstall (shc_chld);
700 GNUNET_SCHEDULER_cancel (sched, child_death_task);
701 child_death_task = GNUNET_SCHEDULER_NO_TASK;
706 * Dummy task to delay arm shutdown.
708 void dummy_task (void *cls,
709 const struct GNUNET_SCHEDULER_TaskContext * tc)
711 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Dummy task executing\n");
717 * Task run for shutdown.
719 * @param cls closure, NULL if we need to self-restart
723 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
725 struct ServiceList *pos;
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
730 stop_listening (NULL);
731 in_shutdown = GNUNET_YES;
737 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
738 "Stopping service `%s' (PID: %d)\n",
741 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
742 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
747 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &dummy_task, NULL);
755 * Task run whenever it is time to restart a child that died.
757 * @param cls closure, always NULL
761 delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
763 struct ServiceList *pos;
764 struct GNUNET_TIME_Relative lowestRestartDelay;
766 child_restart_task = GNUNET_SCHEDULER_NO_TASK;
767 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
774 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
776 /* check for services that need to be restarted due to
777 configuration changes or because the last restart failed */
781 if ( (pos->pid == 0) &&
782 (GNUNET_YES != in_shutdown) )
784 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).value == 0)
786 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
787 _("Restarting service `%s'.\n"), pos->name);
788 start_process (pos, NULL);
793 = GNUNET_TIME_relative_min (lowestRestartDelay,
794 GNUNET_TIME_absolute_get_remaining
800 if (lowestRestartDelay.value != GNUNET_TIME_UNIT_FOREVER_REL.value)
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
804 "Will restart process in %llums\n",
805 (unsigned long long) lowestRestartDelay.value);
808 = GNUNET_SCHEDULER_add_delayed (sched,
810 &delayed_restart_task,
817 * Task triggered whenever we receive a SIGCHLD (child
820 * @param cls closure, NULL if we need to self-restart
824 maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
826 struct ServiceList *pos;
827 struct ServiceList *prev;
828 struct ServiceList *next;
833 enum GNUNET_OS_ProcessStatusType statusType;
834 unsigned long statusCode;
836 child_death_task = GNUNET_SCHEDULER_NO_TASK;
837 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
840 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
841 &maint_child_death, NULL);
844 /* consume the signal */
845 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
847 /* check for services that died (WAITPID) */
850 while (NULL != (pos = next))
858 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->pid,
861 ( (ret == GNUNET_NO) ||
862 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
863 (statusType == GNUNET_OS_PROCESS_RUNNING)) )
869 if (statusType == GNUNET_OS_PROCESS_EXITED)
871 statstr = _( /* process termination method */ "exit");
872 statcode = statusCode;
874 else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
876 statstr = _( /* process termination method */ "signal");
877 statcode = statusCode;
881 statstr = _( /* process termination method */ "unknown");
885 if (NULL != pos->killing_client)
891 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
892 _("Service `%s' stopped\n"),
894 signal_result (pos->killing_client,
895 pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
896 GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
897 GNUNET_SERVER_client_drop (pos->killing_client);
901 if (GNUNET_YES != in_shutdown)
903 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
905 ("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
906 pos->name, statstr, statcode);
907 /* schedule restart */
909 = GNUNET_TIME_relative_to_absolute (pos->backoff);
910 if (pos->backoff.value < EXPONENTIAL_BACKOFF_THRESHOLD)
912 = GNUNET_TIME_relative_multiply (pos->backoff, 2);
913 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
914 GNUNET_SCHEDULER_cancel (sched, child_restart_task);
916 = GNUNET_SCHEDULER_add_with_priority (sched,
917 GNUNET_SCHEDULER_PRIORITY_IDLE,
918 &delayed_restart_task,
923 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
924 "Service `%s' terminated with status %s/%d\n",
925 pos->name, statstr, statcode);
931 if ( (running == NULL) &&
934 GNUNET_SERVER_destroy (server);
935 GNUNET_SIGNAL_handler_uninstall (shc_chld);
941 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
942 &maint_child_death, NULL);
948 transmit_shutdown_ack (void *cls, size_t size, void *buf)
950 struct GNUNET_SERVER_Client *client = cls;
951 struct GNUNET_MessageHeader *msg;
953 if (size < sizeof (struct GNUNET_MessageHeader))
955 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
956 _("Failed to transmit shutdown ACK.\n"));
957 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
958 return 0; /* client disconnected */
961 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
962 _("Transmitting shutdown ACK.\n"));
964 msg = (struct GNUNET_MessageHeader *) buf;
965 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
966 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
967 GNUNET_SERVER_receive_done (client, GNUNET_OK);
968 GNUNET_SERVER_client_drop(client);
969 return sizeof (struct GNUNET_MessageHeader);
973 * Handler for SHUTDOWN message.
975 * @param cls closure (refers to service)
976 * @param client identification of the client
977 * @param message the actual message
980 handle_shutdown (void *cls,
981 struct GNUNET_SERVER_Client *client,
982 const struct GNUNET_MessageHeader *message)
984 GNUNET_SERVER_client_keep(client);
985 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
986 _("Initiating shutdown as requested by client.\n"));
988 GNUNET_SERVER_notify_transmit_ready (client,
989 sizeof(struct GNUNET_MessageHeader),
990 GNUNET_TIME_UNIT_FOREVER_REL,
991 &transmit_shutdown_ack, client);
992 GNUNET_SERVER_client_persist_ (client);
993 GNUNET_SCHEDULER_shutdown (sched);
998 * Signal handler called for SIGCHLD. Triggers the
999 * respective handler by writing to the trigger pipe.
1002 sighandler_child_death ()
1005 int old_errno = errno; /* back-up errno */
1007 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
1008 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
1010 errno = old_errno; /* restore errno */
1015 * Process arm requests.
1017 * @param cls closure
1018 * @param s scheduler to use
1019 * @param serv the initialized server
1020 * @param c configuration to use
1024 struct GNUNET_SCHEDULER_Handle *s,
1025 struct GNUNET_SERVER_Handle *serv,
1026 const struct GNUNET_CONFIGURATION_Handle *c)
1028 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1029 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
1030 {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
1031 {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN,
1032 sizeof (struct GNUNET_MessageHeader)},
1035 char *defaultservices;
1041 GNUNET_assert (serv != NULL);
1042 shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
1043 GNUNET_assert (sigpipe == NULL);
1044 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
1045 GNUNET_assert (sigpipe != NULL);
1046 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
1047 GNUNET_assert (pr != NULL);
1048 GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
1049 GNUNET_SCHEDULER_add_delayed (sched,
1050 GNUNET_TIME_UNIT_FOREVER_REL,
1054 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
1055 &maint_child_death, NULL);
1058 GNUNET_CONFIGURATION_get_value_string (cfg,
1062 prefix_command = GNUNET_strdup ("");
1064 GNUNET_CONFIGURATION_get_value_string (cfg,
1068 final_option = GNUNET_strdup ("");
1069 /* start default services... */
1071 GNUNET_CONFIGURATION_get_value_string (cfg,
1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1078 "Starting default services `%s'\n", defaultservices);
1080 if (0 < strlen (defaultservices))
1082 pos = strtok (defaultservices, " ");
1085 start_service (NULL, pos, NULL);
1086 pos = strtok (NULL, " ");
1089 GNUNET_free (defaultservices);
1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1095 "No default services configured.\n");
1099 /* create listening sockets for future services*/
1100 prepareServices (cfg, sched);
1102 /* process client requests */
1103 GNUNET_SERVER_add_handlers (server, handlers);
1105 /* manage services */
1106 GNUNET_SCHEDULER_add_with_priority (sched,
1107 GNUNET_SCHEDULER_PRIORITY_IDLE,
1108 &config_change_task, NULL);
1113 * The main function for the arm service.
1115 * @param argc number of arguments from the command line
1116 * @param argv command line arguments
1117 * @return 0 ok, 1 on error
1120 main (int argc, char *const *argv)
1122 return (GNUNET_OK ==
1123 GNUNET_SERVICE_run (argc,
1124 argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
1127 /* end of gnunet-service-arm.c */