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 structure pointer of the child.
96 struct GNUNET_OS_Process *proc;
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;
127 * Command to prepend to each actual command.
129 static char *prefix_command;
132 * Option to append to each actual command.
134 static char *final_option;
137 * ID of task called whenever we get a SIGCHILD.
139 static GNUNET_SCHEDULER_TaskIdentifier child_death_task;
142 * ID of task called whenever the timeout for restarting a child
145 static GNUNET_SCHEDULER_TaskIdentifier child_restart_task;
150 * Pipe used to communicate shutdown via signal.
152 static struct GNUNET_DISK_PipeHandle *sigpipe;
155 * Reading end of the signal pipe.
157 static const struct GNUNET_DISK_FileHandle *pr;
160 * Are we in shutdown mode?
162 static int in_shutdown;
166 * Handle to our server instance. Our server is a bit special in that
167 * its service is not immediately stopped once we get a shutdown
168 * request (since we need to continue service until all of our child
169 * processes are dead). This handle is used to shut down the server
170 * (and thus trigger process termination) once all child processes are
171 * also dead. A special option in the ARM configuration modifies the
172 * behaviour of the service implementation to not do the shutdown
175 static struct GNUNET_SERVER_Handle *server;
179 * If the configuration file changes, restart tasks that depended on that
182 * @param cls closure, NULL if we need to self-restart
186 config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
188 struct ServiceList *pos;
194 /* FIXME: this test for config change is a bit too coarse grained */
195 if ( (0 == STAT (pos->config, &sbuf)) &&
196 (pos->mtime < sbuf.st_mtime) &&
197 (pos->proc != NULL) )
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
200 _("Restarting service `%s' due to configuration file change.\n"));
201 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
202 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
204 pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
213 * Transmit a status result message.
215 * @param cls pointer to "unit16_t*" with message type
216 * @param size number of bytes available in buf
217 * @param buf where to copy the message, NULL on error
218 * @return number of bytes copied to buf
221 write_result (void *cls, size_t size, void *buf)
224 struct GNUNET_MessageHeader *msg;
228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
229 _("Could not send status result to client\n"));
230 return 0; /* error, not much we can do */
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
234 "Sending status response %u to client\n",
235 (unsigned int) *res);
237 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
239 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
240 msg->type = htons (*res);
242 return sizeof (struct GNUNET_MessageHeader);
248 * Signal our client that we will start or stop the
251 * @param client who is being signalled
252 * @param name name of the service
253 * @param result message type to send
254 * @return NULL if it was not found
257 signal_result (struct GNUNET_SERVER_Client *client,
258 const char *name, uint16_t result)
264 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
266 ("Not sending status result to client: no client known\n"));
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271 "Telling client that service `%s' is now %s\n",
273 result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
275 res = GNUNET_malloc (sizeof (uint16_t));
277 GNUNET_SERVER_notify_transmit_ready (client,
278 sizeof (struct GNUNET_MessageHeader),
279 GNUNET_TIME_UNIT_FOREVER_REL,
285 * Find the process with the given service
286 * name in the given list, remove it and return it.
288 * @param name which service entry to look up
289 * @return NULL if it was not found
291 static struct ServiceList *
292 find_name (const char *name)
294 struct ServiceList *pos;
295 struct ServiceList *prev;
301 if (0 == strcmp (pos->name, name))
306 prev->next = pos->next;
318 * Free an entry in the service list.
320 * @param pos entry to free
323 free_entry (struct ServiceList *pos)
325 GNUNET_free_non_null (pos->config);
326 GNUNET_free_non_null (pos->binary);
327 GNUNET_free (pos->name);
331 #include "do_start_process.c"
334 * Actually start the process for the given service.
336 * @param sl identifies service to start
337 * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL
340 start_process (struct ServiceList *sl,
354 GNUNET_CONFIGURATION_get_value_string (cfg,
355 sl->name, "PREFIX", &loprefix))
356 loprefix = GNUNET_strdup (prefix_command);
358 GNUNET_CONFIGURATION_get_value_string (cfg,
359 sl->name, "OPTIONS", &options))
361 options = GNUNET_strdup (final_option);
362 if (NULL == strstr (options, "%"))
364 /* replace '{}' with service name */
365 while (NULL != (optpos = strstr (options, "{}")))
369 GNUNET_asprintf (&optpos,
372 GNUNET_free (options);
375 /* replace '$PATH' with value associated with "PATH" */
376 while (NULL != (optpos = strstr (options, "$")))
379 while (isupper ( (unsigned char) *optend)) optend++;
387 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
390 val = GNUNET_strdup ("");
392 GNUNET_asprintf (&optpos,
398 GNUNET_free (options);
404 use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "Starting service `%s' using binary `%s' and configuration `%s'\n",
409 sl->name, sl->binary, sl->config);
411 if (GNUNET_YES == use_debug)
412 sl->proc = do_start_process (lsocks,
420 sl->proc = do_start_process (lsocks,
426 if (sl->proc == NULL)
427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
428 _("Failed to start service `%s'\n"),
431 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
432 _("Starting service `%s'\n"),
434 GNUNET_free (loprefix);
435 GNUNET_free (options);
440 * Start the specified service.
442 * @param client who is asking for this
443 * @param servicename name of the service to start
444 * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL
445 * @return GNUNET_OK on success, GNUNET_SYSERR on error
448 start_service (struct GNUNET_SERVER_Client *client,
449 const char *servicename,
452 struct ServiceList *sl;
457 if (GNUNET_YES == in_shutdown)
459 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
460 _("ARM is shutting down, service `%s' not started.\n"),
462 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
463 return GNUNET_SYSERR;
465 sl = find_name (servicename);
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 _("Service `%s' already running.\n"), servicename);
472 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
473 return GNUNET_SYSERR;
476 GNUNET_CONFIGURATION_get_value_string (cfg,
477 servicename, "BINARY", &binary))
479 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
480 _("Binary implementing service `%s' not known!\n"),
482 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
483 return GNUNET_SYSERR;
486 GNUNET_CONFIGURATION_get_value_filename (cfg,
490 (0 != STAT (config, &sbuf)))
492 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
493 _("Configuration file `%s' for service `%s' not known!\n"),
494 config, servicename);
495 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
496 GNUNET_free (binary);
497 GNUNET_free_non_null (config);
498 return GNUNET_SYSERR;
500 (void) stop_listening (servicename);
501 sl = GNUNET_malloc (sizeof (struct ServiceList));
502 sl->name = GNUNET_strdup (servicename);
506 sl->mtime = sbuf.st_mtime;
507 sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
508 sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS;
511 start_process (sl, lsocks);
513 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
519 * Stop the specified service.
521 * @param client who is asking for this
522 * @param servicename name of the service to stop
525 stop_service (struct GNUNET_SERVER_Client *client,
526 const char *servicename)
528 struct ServiceList *pos;
530 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
531 _("Preparing to stop `%s'\n"), servicename);
532 pos = find_name (servicename);
535 if (GNUNET_OK == stop_listening (servicename))
536 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
538 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
539 GNUNET_SERVER_receive_done (client, GNUNET_OK);
542 if (pos->killing_client != NULL)
544 /* killing already in progress */
546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
547 "Service `%s' is already down\n", servicename);
549 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
550 GNUNET_SERVER_receive_done (client, GNUNET_OK);
556 if (GNUNET_YES == in_shutdown)
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 "Termination request already sent to `%s' (since ARM is in shutdown).\n",
563 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
564 GNUNET_SERVER_receive_done (client, GNUNET_OK);
569 if (pos->proc == NULL)
571 /* process is in delayed restart, simply remove it! */
573 signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
574 GNUNET_SERVER_receive_done (client, GNUNET_OK);
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "Sending kill signal to service `%s', waiting for process to die.\n",
582 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
583 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
586 pos->killing_client = client;
587 GNUNET_SERVER_client_keep (client);
592 * Handle START-message.
594 * @param cls closure (always NULL)
595 * @param client identification of the client
596 * @param message the actual message
597 * @return GNUNET_OK to keep the connection open,
598 * GNUNET_SYSERR to close it (signal serious error)
601 handle_start (void *cls,
602 struct GNUNET_SERVER_Client *client,
603 const struct GNUNET_MessageHeader *message)
605 const char *servicename;
608 size = ntohs (message->size);
609 size -= sizeof (struct GNUNET_MessageHeader);
610 servicename = (const char *) &message[1];
611 if ((size == 0) || (servicename[size - 1] != '\0'))
614 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
617 start_service (client, servicename, NULL);
618 GNUNET_SERVER_receive_done (client, GNUNET_OK);
623 * Handle STOP-message.
625 * @param cls closure (always NULL)
626 * @param client identification of the client
627 * @param message the actual message
628 * @return GNUNET_OK to keep the connection open,
629 * GNUNET_SYSERR to close it (signal serious error)
632 handle_stop (void *cls,
633 struct GNUNET_SERVER_Client *client,
634 const struct GNUNET_MessageHeader *message)
636 const char *servicename;
639 size = ntohs (message->size);
640 size -= sizeof (struct GNUNET_MessageHeader);
641 servicename = (const char *) &message[1];
642 if ((size == 0) || (servicename[size - 1] != '\0'))
645 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
648 stop_service (client, servicename);
653 * Remove all entries for tasks that are not running
654 * (proc = NULL) from the running list (they will no longer
655 * be restarted since we are shutting down).
660 struct ServiceList *pos;
661 struct ServiceList *next;
662 struct ServiceList *prev;
669 if (pos->proc == NULL)
685 * We are done with everything. Stop remaining
686 * tasks, signal handler and the server.
693 GNUNET_SERVER_destroy (server);
696 if (GNUNET_SCHEDULER_NO_TASK != child_death_task)
698 GNUNET_SCHEDULER_cancel (child_death_task);
699 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;
734 if (pos->proc != NULL)
736 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
737 "Stopping service `%s'\n",
739 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
740 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
745 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &dummy_task, NULL);
753 * Task run whenever it is time to restart a child that died.
755 * @param cls closure, always NULL
759 delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
761 struct ServiceList *pos;
762 struct GNUNET_TIME_Relative lowestRestartDelay;
764 child_restart_task = GNUNET_SCHEDULER_NO_TASK;
765 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
772 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
774 /* check for services that need to be restarted due to
775 configuration changes or because the last restart failed */
779 if ( (pos->proc == NULL) &&
780 (GNUNET_YES != in_shutdown) )
782 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
784 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
785 _("Restarting service `%s'.\n"), pos->name);
786 start_process (pos, NULL);
791 = GNUNET_TIME_relative_min (lowestRestartDelay,
792 GNUNET_TIME_absolute_get_remaining
798 if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802 "Will restart process in %llums\n",
803 (unsigned long long) lowestRestartDelay.rel_value);
806 = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
807 &delayed_restart_task,
814 * Task triggered whenever we receive a SIGCHLD (child
817 * @param cls closure, NULL if we need to self-restart
821 maint_child_death (void *cls,
822 const struct GNUNET_SCHEDULER_TaskContext *tc)
824 struct ServiceList *pos;
825 struct ServiceList *prev;
826 struct ServiceList *next;
831 enum GNUNET_OS_ProcessStatusType statusType;
832 unsigned long statusCode;
834 child_death_task = GNUNET_SCHEDULER_NO_TASK;
835 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
838 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
839 &maint_child_death, NULL);
842 /* consume the signal */
843 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
845 /* check for services that died (WAITPID) */
848 while (NULL != (pos = next))
851 if (pos->proc == NULL)
856 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
859 ( (ret == GNUNET_NO) ||
860 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
861 (statusType == GNUNET_OS_PROCESS_RUNNING)) )
867 if (statusType == GNUNET_OS_PROCESS_EXITED)
869 statstr = _( /* process termination method */ "exit");
870 statcode = statusCode;
872 else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
874 statstr = _( /* process termination method */ "signal");
875 statcode = statusCode;
879 statstr = _( /* process termination method */ "unknown");
882 GNUNET_OS_process_close (pos->proc);
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) &&
901 (0 == (tc->reason & GNUNET_SCHEDULER_REASON_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.rel_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 (child_restart_task);
916 = GNUNET_SCHEDULER_add_with_priority (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);
938 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
939 &maint_child_death, NULL);
945 transmit_shutdown_ack (void *cls, size_t size, void *buf)
947 struct GNUNET_SERVER_Client *client = cls;
948 struct GNUNET_MessageHeader *msg;
950 if (size < sizeof (struct GNUNET_MessageHeader))
952 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
953 _("Failed to transmit shutdown ACK.\n"));
954 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
955 return 0; /* client disconnected */
958 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
959 _("Transmitting shutdown ACK.\n"));
961 msg = (struct GNUNET_MessageHeader *) buf;
962 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
963 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
964 GNUNET_SERVER_receive_done (client, GNUNET_OK);
965 GNUNET_SERVER_client_drop(client);
966 return sizeof (struct GNUNET_MessageHeader);
970 * Handler for SHUTDOWN message.
972 * @param cls closure (refers to service)
973 * @param client identification of the client
974 * @param message the actual message
977 handle_shutdown (void *cls,
978 struct GNUNET_SERVER_Client *client,
979 const struct GNUNET_MessageHeader *message)
981 GNUNET_SERVER_client_keep(client);
982 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
983 _("Initiating shutdown as requested by client.\n"));
985 GNUNET_SERVER_notify_transmit_ready (client,
986 sizeof(struct GNUNET_MessageHeader),
987 GNUNET_TIME_UNIT_FOREVER_REL,
988 &transmit_shutdown_ack, client);
989 GNUNET_SERVER_client_persist_ (client);
990 GNUNET_SCHEDULER_shutdown ();
995 * Signal handler called for SIGCHLD. Triggers the
996 * respective handler by writing to the trigger pipe.
999 sighandler_child_death ()
1002 int old_errno = errno; /* back-up errno */
1004 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
1005 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
1007 errno = old_errno; /* restore errno */
1012 * Process arm requests.
1014 * @param cls closure
1015 * @param serv the initialized server
1016 * @param c configuration to use
1020 struct GNUNET_SERVER_Handle *serv,
1021 const struct GNUNET_CONFIGURATION_Handle *c)
1023 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1024 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
1025 {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
1026 {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN,
1027 sizeof (struct GNUNET_MessageHeader)},
1030 char *defaultservices;
1035 GNUNET_assert (serv != 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 (GNUNET_TIME_UNIT_FOREVER_REL,
1043 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
1044 &maint_child_death, NULL);
1047 GNUNET_CONFIGURATION_get_value_string (cfg,
1051 prefix_command = GNUNET_strdup ("");
1053 GNUNET_CONFIGURATION_get_value_string (cfg,
1057 final_option = GNUNET_strdup ("");
1058 /* start default services... */
1060 GNUNET_CONFIGURATION_get_value_string (cfg,
1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1067 "Starting default services `%s'\n", defaultservices);
1069 if (0 < strlen (defaultservices))
1071 pos = strtok (defaultservices, " ");
1074 start_service (NULL, pos, NULL);
1075 pos = strtok (NULL, " ");
1078 GNUNET_free (defaultservices);
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1084 "No default services configured.\n");
1088 /* create listening sockets for future services*/
1089 prepareServices (cfg);
1091 /* process client requests */
1092 GNUNET_SERVER_add_handlers (server, handlers);
1094 /* manage services */
1095 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1096 &config_change_task, NULL);
1101 * The main function for the arm service.
1103 * @param argc number of arguments from the command line
1104 * @param argv command line arguments
1105 * @return 0 ok, 1 on error
1108 main (int argc, char *const *argv)
1111 struct GNUNET_SIGNAL_Context *shc_chld;
1113 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
1114 GNUNET_assert (sigpipe != NULL);
1115 shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
1117 GNUNET_SERVICE_run (argc,
1118 argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
1119 GNUNET_SIGNAL_handler_uninstall (shc_chld);
1121 GNUNET_DISK_pipe_close (sigpipe);
1130 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1132 void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
1134 mallopt (M_TRIM_THRESHOLD, 4*1024);
1135 mallopt (M_TOP_PAD, 1*1024);
1141 /* end of gnunet-service-arm.c */