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
347 start_process (struct ServiceList *sl,
361 GNUNET_CONFIGURATION_get_value_string (cfg,
362 sl->name, "PREFIX", &loprefix))
363 loprefix = GNUNET_strdup (prefix_command);
365 GNUNET_CONFIGURATION_get_value_string (cfg,
366 sl->name, "OPTIONS", &options))
368 options = GNUNET_strdup (final_option);
369 if (NULL == strstr (options, "%"))
371 /* replace '{}' with service name */
372 while (NULL != (optpos = strstr (options, "{}")))
376 GNUNET_asprintf (&optpos,
379 GNUNET_free (options);
382 /* replace '$PATH' with value associated with "PATH" */
383 while (NULL != (optpos = strstr (options, "$")))
386 while (isupper ( (unsigned char) *optend)) optend++;
394 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
397 val = GNUNET_strdup ("");
399 GNUNET_asprintf (&optpos,
405 GNUNET_free (options);
411 use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
415 "Starting service `%s' using binary `%s' and configuration `%s'\n",
416 sl->name, sl->binary, sl->config);
418 if (GNUNET_YES == use_debug)
419 sl->pid = do_start_process (lsocks,
427 sl->pid = do_start_process (lsocks,
433 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
434 _("Starting service `%s' (PID: %d)\n"),
437 GNUNET_free (loprefix);
438 GNUNET_free (options);
439 /* FIXME: should check sl->pid */
444 * Start the specified service.
446 * @param client who is asking for this
447 * @param servicename name of the service to start
448 * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL
449 * @return GNUNET_OK on success, GNUNET_SYSERR on error
452 start_service (struct GNUNET_SERVER_Client *client,
453 const char *servicename,
456 struct ServiceList *sl;
461 if (GNUNET_YES == in_shutdown)
463 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
464 _("ARM is shutting down, service `%s' not started.\n"),
466 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
467 return GNUNET_SYSERR;
469 sl = find_name (servicename);
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 _("Service `%s' already running.\n"), servicename);
476 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
477 return GNUNET_SYSERR;
480 GNUNET_CONFIGURATION_get_value_string (cfg,
481 servicename, "BINARY", &binary))
483 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
484 _("Binary implementing service `%s' not known!\n"),
486 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
487 return GNUNET_SYSERR;
490 GNUNET_CONFIGURATION_get_value_filename (cfg,
494 (0 != STAT (config, &sbuf)))
496 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
497 _("Configuration file `%s' for service `%s' not known!\n"),
498 config, servicename);
499 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
500 GNUNET_free (binary);
501 GNUNET_free_non_null (config);
502 return GNUNET_SYSERR;
504 (void) stop_listening (servicename);
505 sl = GNUNET_malloc (sizeof (struct ServiceList));
506 sl->name = GNUNET_strdup (servicename);
510 sl->mtime = sbuf.st_mtime;
511 sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
512 sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS;
515 start_process (sl, lsocks);
517 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
523 * Stop the specified service.
525 * @param client who is asking for this
526 * @param servicename name of the service to stop
529 stop_service (struct GNUNET_SERVER_Client *client,
530 const char *servicename)
532 struct ServiceList *pos;
534 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
535 _("Preparing to stop `%s'\n"), servicename);
536 pos = find_name (servicename);
539 if (GNUNET_OK == stop_listening (servicename))
540 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
542 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
543 GNUNET_SERVER_receive_done (client, GNUNET_OK);
546 if (pos->killing_client != NULL)
548 /* killing already in progress */
550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
551 "Service `%s' is already down\n", servicename);
553 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
554 GNUNET_SERVER_receive_done (client, GNUNET_OK);
560 if (GNUNET_YES == in_shutdown)
563 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
564 "Termination request already sent to `%s' (since ARM is in shutdown).\n",
567 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
568 GNUNET_SERVER_receive_done (client, GNUNET_OK);
575 /* process is in delayed restart, simply remove it! */
577 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
578 GNUNET_SERVER_receive_done (client, GNUNET_OK);
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 "Sending kill signal to service `%s', waiting for process to die.\n",
586 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
587 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
590 pos->killing_client = client;
591 GNUNET_SERVER_client_keep (client);
596 * Handle START-message.
598 * @param cls closure (always NULL)
599 * @param client identification of the client
600 * @param message the actual message
601 * @return GNUNET_OK to keep the connection open,
602 * GNUNET_SYSERR to close it (signal serious error)
605 handle_start (void *cls,
606 struct GNUNET_SERVER_Client *client,
607 const struct GNUNET_MessageHeader *message)
609 const char *servicename;
612 size = ntohs (message->size);
613 size -= sizeof (struct GNUNET_MessageHeader);
614 servicename = (const char *) &message[1];
615 if ((size == 0) || (servicename[size - 1] != '\0'))
618 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
621 start_service (client, servicename, NULL);
622 GNUNET_SERVER_receive_done (client, GNUNET_OK);
627 * Handle STOP-message.
629 * @param cls closure (always NULL)
630 * @param client identification of the client
631 * @param message the actual message
632 * @return GNUNET_OK to keep the connection open,
633 * GNUNET_SYSERR to close it (signal serious error)
636 handle_stop (void *cls,
637 struct GNUNET_SERVER_Client *client,
638 const struct GNUNET_MessageHeader *message)
640 const char *servicename;
643 size = ntohs (message->size);
644 size -= sizeof (struct GNUNET_MessageHeader);
645 servicename = (const char *) &message[1];
646 if ((size == 0) || (servicename[size - 1] != '\0'))
649 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
652 stop_service (client, servicename);
657 * Remove all entries for tasks that are not running
658 * (pid = 0) from the running list (they will no longer
659 * be restarted since we are shutting down).
664 struct ServiceList *pos;
665 struct ServiceList *next;
666 struct ServiceList *prev;
689 * We are done with everything. Stop remaining
690 * tasks, signal handler and the server.
695 GNUNET_SERVER_destroy (server);
697 GNUNET_SIGNAL_handler_uninstall (shc_chld);
699 GNUNET_SCHEDULER_cancel (sched, child_death_task);
700 child_death_task = GNUNET_SCHEDULER_NO_TASK;
705 * Dummy task to delay arm shutdown.
707 void dummy_task (void *cls,
708 const struct GNUNET_SCHEDULER_TaskContext * tc)
710 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Dummy task executing\n");
716 * Task run for shutdown.
718 * @param cls closure, NULL if we need to self-restart
722 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
724 struct ServiceList *pos;
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
729 stop_listening (NULL);
730 in_shutdown = GNUNET_YES;
736 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
737 "Stopping service `%s' (PID: %d)\n",
740 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
741 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
746 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &dummy_task, NULL);
754 * Task run whenever it is time to restart a child that died.
756 * @param cls closure, always NULL
760 delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
762 struct ServiceList *pos;
763 struct GNUNET_TIME_Relative lowestRestartDelay;
765 child_restart_task = GNUNET_SCHEDULER_NO_TASK;
766 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
773 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
775 /* check for services that need to be restarted due to
776 configuration changes or because the last restart failed */
780 if ( (pos->pid == 0) &&
781 (GNUNET_YES != in_shutdown) )
783 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).value == 0)
785 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
786 _("Restarting service `%s'.\n"), pos->name);
787 start_process (pos, NULL);
792 = GNUNET_TIME_relative_min (lowestRestartDelay,
793 GNUNET_TIME_absolute_get_remaining
799 if (lowestRestartDelay.value != GNUNET_TIME_UNIT_FOREVER_REL.value)
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
803 "Will restart process in %llums\n",
804 (unsigned long long) lowestRestartDelay.value);
807 = GNUNET_SCHEDULER_add_delayed (sched,
809 &delayed_restart_task,
816 * Task triggered whenever we receive a SIGCHLD (child
819 * @param cls closure, NULL if we need to self-restart
823 maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
825 struct ServiceList *pos;
826 struct ServiceList *prev;
827 struct ServiceList *next;
832 enum GNUNET_OS_ProcessStatusType statusType;
833 unsigned long statusCode;
835 child_death_task = GNUNET_SCHEDULER_NO_TASK;
836 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
839 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
840 &maint_child_death, NULL);
843 /* consume the signal */
844 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
846 /* check for services that died (WAITPID) */
849 while (NULL != (pos = next))
857 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->pid,
860 ( (ret == GNUNET_NO) ||
861 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
862 (statusType == GNUNET_OS_PROCESS_RUNNING)) )
868 if (statusType == GNUNET_OS_PROCESS_EXITED)
870 statstr = _( /* process termination method */ "exit");
871 statcode = statusCode;
873 else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
875 statstr = _( /* process termination method */ "signal");
876 statcode = statusCode;
880 statstr = _( /* process termination method */ "unknown");
884 if (NULL != pos->killing_client)
890 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
891 _("Service `%s' stopped\n"),
893 signal_result (pos->killing_client,
894 pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
895 GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
896 GNUNET_SERVER_client_drop (pos->killing_client);
900 if (GNUNET_YES != in_shutdown)
902 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
904 ("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
905 pos->name, statstr, statcode);
906 /* schedule restart */
908 = GNUNET_TIME_relative_to_absolute (pos->backoff);
909 if (pos->backoff.value < EXPONENTIAL_BACKOFF_THRESHOLD)
911 = GNUNET_TIME_relative_multiply (pos->backoff, 2);
912 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
913 GNUNET_SCHEDULER_cancel (sched, child_restart_task);
915 = GNUNET_SCHEDULER_add_with_priority (sched,
916 GNUNET_SCHEDULER_PRIORITY_IDLE,
917 &delayed_restart_task,
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
923 "Service `%s' terminated with status %s/%d\n",
924 pos->name, statstr, statcode);
930 if ( (running == NULL) &&
933 GNUNET_SERVER_destroy (server);
934 GNUNET_SIGNAL_handler_uninstall (shc_chld);
940 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
941 &maint_child_death, NULL);
947 transmit_shutdown_ack (void *cls, size_t size, void *buf)
949 struct GNUNET_SERVER_Client *client = cls;
950 struct GNUNET_MessageHeader *msg;
952 if (size < sizeof (struct GNUNET_MessageHeader))
954 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
955 _("Failed to transmit shutdown ACK.\n"));
956 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
957 return 0; /* client disconnected */
960 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
961 _("Transmitting shutdown ACK.\n"));
963 msg = (struct GNUNET_MessageHeader *) buf;
964 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
965 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
966 GNUNET_SERVER_receive_done (client, GNUNET_OK);
967 GNUNET_SERVER_client_drop(client);
968 return sizeof (struct GNUNET_MessageHeader);
972 * Handler for SHUTDOWN message.
974 * @param cls closure (refers to service)
975 * @param client identification of the client
976 * @param message the actual message
979 handle_shutdown (void *cls,
980 struct GNUNET_SERVER_Client *client,
981 const struct GNUNET_MessageHeader *message)
983 GNUNET_SERVER_client_keep(client);
984 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
985 _("Initiating shutdown as requested by client.\n"));
987 GNUNET_SERVER_notify_transmit_ready (client,
988 sizeof(struct GNUNET_MessageHeader),
989 GNUNET_TIME_UNIT_FOREVER_REL,
990 &transmit_shutdown_ack, client);
991 GNUNET_SERVER_client_persist_ (client);
992 GNUNET_SCHEDULER_shutdown (sched);
997 * Signal handler called for SIGCHLD. Triggers the
998 * respective handler by writing to the trigger pipe.
1001 sighandler_child_death ()
1005 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
1006 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
1012 * Process arm requests.
1014 * @param cls closure
1015 * @param s scheduler to use
1016 * @param serv the initialized server
1017 * @param c configuration to use
1021 struct GNUNET_SCHEDULER_Handle *s,
1022 struct GNUNET_SERVER_Handle *serv,
1023 const struct GNUNET_CONFIGURATION_Handle *c)
1025 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1026 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
1027 {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
1028 {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN,
1029 sizeof (struct GNUNET_MessageHeader)},
1032 char *defaultservices;
1038 GNUNET_assert (serv != NULL);
1039 shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
1040 GNUNET_assert (sigpipe == NULL);
1041 sigpipe = GNUNET_DISK_pipe (GNUNET_NO);
1042 GNUNET_assert (sigpipe != NULL);
1043 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
1044 GNUNET_assert (pr != NULL);
1045 GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
1046 GNUNET_SCHEDULER_add_delayed (sched,
1047 GNUNET_TIME_UNIT_FOREVER_REL,
1051 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
1052 &maint_child_death, NULL);
1055 GNUNET_CONFIGURATION_get_value_string (cfg,
1059 prefix_command = GNUNET_strdup ("");
1061 GNUNET_CONFIGURATION_get_value_string (cfg,
1065 final_option = GNUNET_strdup ("");
1066 /* start default services... */
1068 GNUNET_CONFIGURATION_get_value_string (cfg,
1074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1075 "Starting default services `%s'\n", defaultservices);
1077 if (0 < strlen (defaultservices))
1079 pos = strtok (defaultservices, " ");
1082 start_service (NULL, pos, NULL);
1083 pos = strtok (NULL, " ");
1086 GNUNET_free (defaultservices);
1091 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1092 "No default services configured.\n");
1096 /* create listening sockets for future services*/
1097 prepareServices (cfg, sched);
1099 /* process client requests */
1100 GNUNET_SERVER_add_handlers (server, handlers);
1102 /* manage services */
1103 GNUNET_SCHEDULER_add_with_priority (sched,
1104 GNUNET_SCHEDULER_PRIORITY_IDLE,
1105 &config_change_task, NULL);
1110 * The main function for the arm service.
1112 * @param argc number of arguments from the command line
1113 * @param argv command line arguments
1114 * @return 0 ok, 1 on error
1117 main (int argc, char *const *argv)
1119 return (GNUNET_OK ==
1120 GNUNET_SERVICE_run (argc,
1121 argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
1124 /* end of gnunet-service-arm.c */