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 2, 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)
360 GNUNET_CONFIGURATION_get_value_string (cfg,
361 sl->name, "PREFIX", &loprefix))
362 loprefix = GNUNET_strdup (prefix_command);
364 GNUNET_CONFIGURATION_get_value_string (cfg,
365 sl->name, "OPTIONS", &options))
367 options = GNUNET_strdup (final_option);
368 if (NULL == strstr (options, "%"))
370 /* replace '{}' with service name */
371 while (NULL != (optpos = strstr (options, "{}")))
375 GNUNET_asprintf (&optpos,
378 GNUNET_free (options);
381 /* replace '$PATH' with value associated with "PATH" */
382 while (NULL != (optpos = strstr (options, "$")))
385 while (isupper (*optend)) optend++;
393 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
396 val = GNUNET_strdup ("");
398 GNUNET_asprintf (&optpos,
404 GNUNET_free (options);
410 use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
412 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"), sl->name);
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 (loprefix,
426 sl->pid = do_start_process (loprefix,
431 GNUNET_free (loprefix);
432 GNUNET_free (options);
433 /* FIXME: should check sl->pid */
438 * Start the specified service.
440 * @param client who is asking for this
441 * @param servicename name of the service to start
444 start_service (struct GNUNET_SERVER_Client *client, const char *servicename)
446 struct ServiceList *sl;
451 if (GNUNET_YES == in_shutdown)
453 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
454 _("ARM is shutting down, service `%s' not started.\n"),
456 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
459 sl = find_name (servicename);
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
463 _("Service `%s' already running.\n"), servicename);
466 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
470 GNUNET_CONFIGURATION_get_value_string (cfg,
471 servicename, "BINARY", &binary))
473 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
474 _("Binary implementing service `%s' not known!\n"),
476 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
480 GNUNET_CONFIGURATION_get_value_filename (cfg,
484 (0 != STAT (config, &sbuf)))
486 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
487 _("Configuration file `%s' for service `%s' not known!\n"),
488 config, servicename);
489 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
490 GNUNET_free (binary);
491 GNUNET_free_non_null (config);
494 (void) stop_listening (servicename);
495 sl = GNUNET_malloc (sizeof (struct ServiceList));
496 sl->name = GNUNET_strdup (servicename);
500 sl->mtime = sbuf.st_mtime;
501 sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
502 sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS;
507 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
512 * Stop the specified service.
514 * @param client who is asking for this
515 * @param servicename name of the service to stop
518 stop_service (struct GNUNET_SERVER_Client *client,
519 const char *servicename)
521 struct ServiceList *pos;
523 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
524 _("Preparing to stop `%s'\n"), servicename);
525 pos = find_name (servicename);
528 if (GNUNET_OK == stop_listening (servicename))
529 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
531 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
532 GNUNET_SERVER_receive_done (client, GNUNET_OK);
535 if (pos->killing_client != NULL)
537 /* killing already in progress */
539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
540 "Service `%s' is already down\n", servicename);
542 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
543 GNUNET_SERVER_receive_done (client, GNUNET_OK);
549 if (GNUNET_YES == in_shutdown)
552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
553 "Termination request already sent to `%s' (since ARM is in shutdown).\n",
556 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
557 GNUNET_SERVER_receive_done (client, GNUNET_OK);
564 /* process is in delayed restart, simply remove it! */
566 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
567 GNUNET_SERVER_receive_done (client, GNUNET_OK);
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Sending kill signal to service `%s', waiting for process to die.\n",
575 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
576 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
579 pos->killing_client = client;
580 GNUNET_SERVER_client_keep (client);
585 * Handle START-message.
587 * @param cls closure (always NULL)
588 * @param client identification of the client
589 * @param message the actual message
590 * @return GNUNET_OK to keep the connection open,
591 * GNUNET_SYSERR to close it (signal serious error)
594 handle_start (void *cls,
595 struct GNUNET_SERVER_Client *client,
596 const struct GNUNET_MessageHeader *message)
598 const char *servicename;
601 size = ntohs (message->size);
602 size -= sizeof (struct GNUNET_MessageHeader);
603 servicename = (const char *) &message[1];
604 if ((size == 0) || (servicename[size - 1] != '\0'))
607 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
610 start_service (client, servicename);
611 GNUNET_SERVER_receive_done (client, GNUNET_OK);
616 * Handle STOP-message.
618 * @param cls closure (always NULL)
619 * @param client identification of the client
620 * @param message the actual message
621 * @return GNUNET_OK to keep the connection open,
622 * GNUNET_SYSERR to close it (signal serious error)
625 handle_stop (void *cls,
626 struct GNUNET_SERVER_Client *client,
627 const struct GNUNET_MessageHeader *message)
629 const char *servicename;
632 size = ntohs (message->size);
633 size -= sizeof (struct GNUNET_MessageHeader);
634 servicename = (const char *) &message[1];
635 if ((size == 0) || (servicename[size - 1] != '\0'))
638 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
641 stop_service (client, servicename);
646 * Remove all entries for tasks that are not running
647 * (pid = 0) from the running list (they will no longer
648 * be restarted since we are shutting down).
653 struct ServiceList *pos;
654 struct ServiceList *next;
655 struct ServiceList *prev;
678 * We are done with everything. Stop remaining
679 * tasks, signal handler and the server.
684 GNUNET_SERVER_destroy (server);
686 GNUNET_SIGNAL_handler_uninstall (shc_chld);
688 GNUNET_SCHEDULER_cancel (sched, child_death_task);
689 child_death_task = GNUNET_SCHEDULER_NO_TASK;
694 * Dummy task to delay arm shutdown.
696 void dummy_task (void *cls,
697 const struct GNUNET_SCHEDULER_TaskContext * tc)
699 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Dummy task executing\n");
705 * Task run for shutdown.
707 * @param cls closure, NULL if we need to self-restart
711 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
713 struct ServiceList *pos;
716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
718 stop_listening (NULL);
719 in_shutdown = GNUNET_YES;
726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
727 "Sending SIGTERM to `%s'\n", pos->name);
729 if (0 != PLIBC_KILL (pos->pid, SIGTERM))
730 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
735 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &dummy_task, NULL);
743 * Task run whenever it is time to restart a child that died.
745 * @param cls closure, always NULL
749 delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
751 struct ServiceList *pos;
752 struct GNUNET_TIME_Relative lowestRestartDelay;
754 child_restart_task = GNUNET_SCHEDULER_NO_TASK;
755 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
762 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
764 /* check for services that need to be restarted due to
765 configuration changes or because the last restart failed */
769 if ( (pos->pid == 0) &&
770 (GNUNET_YES != in_shutdown) )
772 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).value == 0)
774 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
775 _("Restarting service `%s'.\n"), pos->name);
781 = GNUNET_TIME_relative_min (lowestRestartDelay,
782 GNUNET_TIME_absolute_get_remaining
788 if (lowestRestartDelay.value != GNUNET_TIME_UNIT_FOREVER_REL.value)
791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
792 "Will restart process in %llums\n",
793 (unsigned long long) lowestRestartDelay.value);
796 = GNUNET_SCHEDULER_add_delayed (sched,
798 &delayed_restart_task,
805 * Task triggered whenever we receive a SIGCHLD (child
808 * @param cls closure, NULL if we need to self-restart
812 maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
814 struct ServiceList *pos;
815 struct ServiceList *prev;
816 struct ServiceList *next;
821 enum GNUNET_OS_ProcessStatusType statusType;
822 unsigned long statusCode;
824 child_death_task = GNUNET_SCHEDULER_NO_TASK;
825 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
828 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
829 &maint_child_death, NULL);
832 /* consume the signal */
833 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
835 /* check for services that died (WAITPID) */
838 while (NULL != (pos = next))
846 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->pid,
849 ( (ret == GNUNET_NO) ||
850 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
851 (statusType == GNUNET_OS_PROCESS_RUNNING)) )
857 if (statusType == GNUNET_OS_PROCESS_EXITED)
859 statstr = _( /* process termination method */ "exit");
860 statcode = statusCode;
862 else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
864 statstr = _( /* process termination method */ "signal");
865 statcode = statusCode;
869 statstr = _( /* process termination method */ "unknown");
873 if (NULL != pos->killing_client)
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
880 _("Service `%s' stopped\n"),
882 signal_result (pos->killing_client,
883 pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
884 GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
885 GNUNET_SERVER_client_drop (pos->killing_client);
889 if (GNUNET_YES != in_shutdown)
891 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
893 ("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
894 pos->name, statstr, statcode);
895 /* schedule restart */
897 = GNUNET_TIME_relative_to_absolute (pos->backoff);
898 if (pos->backoff.value < EXPONENTIAL_BACKOFF_THRESHOLD)
900 = GNUNET_TIME_relative_multiply (pos->backoff, 2);
901 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
902 GNUNET_SCHEDULER_cancel (sched, child_restart_task);
904 = GNUNET_SCHEDULER_add_with_priority (sched,
905 GNUNET_SCHEDULER_PRIORITY_IDLE,
906 &delayed_restart_task,
911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
912 "Service `%s' terminated with status %s/%d\n",
913 pos->name, statstr, statcode);
919 if ( (running == NULL) &&
922 GNUNET_SERVER_destroy (server);
923 GNUNET_SIGNAL_handler_uninstall (shc_chld);
929 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
930 &maint_child_death, NULL);
936 transmit_shutdown_ack (void *cls, size_t size, void *buf)
938 struct GNUNET_SERVER_Client *client = cls;
939 struct GNUNET_MessageHeader *msg;
941 if (size < sizeof (struct GNUNET_MessageHeader))
943 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
944 _("Failed to transmit shutdown ACK.\n"));
945 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
946 return 0; /* client disconnected */
949 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
950 _("Transmitting shutdown ACK.\n"));
952 msg = (struct GNUNET_MessageHeader *) buf;
953 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
954 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
955 GNUNET_SERVER_receive_done (client, GNUNET_OK);
956 GNUNET_SERVER_client_drop(client);
957 return sizeof (struct GNUNET_MessageHeader);
961 * Handler for SHUTDOWN message.
963 * @param cls closure (refers to service)
964 * @param client identification of the client
965 * @param message the actual message
968 handle_shutdown (void *cls,
969 struct GNUNET_SERVER_Client *client,
970 const struct GNUNET_MessageHeader *message)
972 GNUNET_SERVER_client_keep(client);
973 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
974 _("Initiating shutdown as requested by client.\n"));
976 GNUNET_SERVER_notify_transmit_ready (client,
977 sizeof(struct GNUNET_MessageHeader),
978 GNUNET_TIME_UNIT_FOREVER_REL,
979 &transmit_shutdown_ack, client);
980 GNUNET_SERVER_client_persist_ (client);
981 GNUNET_SCHEDULER_shutdown (sched);
986 * List of handlers for the messages understood by this service.
988 static struct GNUNET_SERVER_MessageHandler handlers[] = {
989 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
990 {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
991 {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN,
992 sizeof (struct GNUNET_MessageHeader)},
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 char *defaultservices;
1031 GNUNET_assert (serv != NULL);
1032 shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
1033 GNUNET_assert (sigpipe == NULL);
1034 sigpipe = GNUNET_DISK_pipe (GNUNET_NO);
1035 GNUNET_assert (sigpipe != NULL);
1036 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
1037 GNUNET_assert (pr != NULL);
1038 GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
1039 GNUNET_SCHEDULER_add_delayed (sched,
1040 GNUNET_TIME_UNIT_FOREVER_REL,
1044 GNUNET_SCHEDULER_add_read_file (sched, GNUNET_TIME_UNIT_FOREVER_REL, pr,
1045 &maint_child_death, NULL);
1048 GNUNET_CONFIGURATION_get_value_string (cfg,
1052 prefix_command = GNUNET_strdup ("");
1054 GNUNET_CONFIGURATION_get_value_string (cfg,
1058 final_option = GNUNET_strdup ("");
1059 /* start default services... */
1061 GNUNET_CONFIGURATION_get_value_string (cfg,
1067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068 "Starting default services `%s'\n", defaultservices);
1070 if (0 < strlen (defaultservices))
1072 pos = strtok (defaultservices, " ");
1075 start_service (NULL, pos);
1076 pos = strtok (NULL, " ");
1079 GNUNET_free (defaultservices);
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1085 "No default services configured.\n");
1089 /* create listening sockets for future services*/
1090 prepareServices (cfg, sched);
1092 /* process client requests */
1093 GNUNET_SERVER_add_handlers (server, handlers);
1095 /* manage services */
1096 GNUNET_SCHEDULER_add_with_priority (sched,
1097 GNUNET_SCHEDULER_PRIORITY_IDLE,
1098 &config_change_task, NULL);
1103 * The main function for the arm service.
1105 * @param argc number of arguments from the command line
1106 * @param argv command line arguments
1107 * @return 0 ok, 1 on error
1110 main (int argc, char *const *argv)
1112 return (GNUNET_OK ==
1113 GNUNET_SERVICE_run (argc,
1114 argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
1117 /* end of gnunet-service-arm.c */