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.
691 GNUNET_SERVER_destroy (server);
693 GNUNET_SCHEDULER_cancel (child_death_task);
694 child_death_task = GNUNET_SCHEDULER_NO_TASK;
699 * Dummy task to delay arm shutdown.
701 void dummy_task (void *cls,
702 const struct GNUNET_SCHEDULER_TaskContext * tc)
704 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Dummy task executing\n");
710 * Task run for shutdown.
712 * @param cls closure, NULL if we need to self-restart
716 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
718 struct ServiceList *pos;
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
723 stop_listening (NULL);
724 in_shutdown = GNUNET_YES;
728 if (pos->proc != NULL)
730 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
731 "Stopping service `%s'\n",
733 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
734 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
739 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &dummy_task, NULL);
747 * Task run whenever it is time to restart a child that died.
749 * @param cls closure, always NULL
753 delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
755 struct ServiceList *pos;
756 struct GNUNET_TIME_Relative lowestRestartDelay;
758 child_restart_task = GNUNET_SCHEDULER_NO_TASK;
759 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
766 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
768 /* check for services that need to be restarted due to
769 configuration changes or because the last restart failed */
773 if ( (pos->proc == NULL) &&
774 (GNUNET_YES != in_shutdown) )
776 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
778 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
779 _("Restarting service `%s'.\n"), pos->name);
780 start_process (pos, NULL);
785 = GNUNET_TIME_relative_min (lowestRestartDelay,
786 GNUNET_TIME_absolute_get_remaining
792 if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
796 "Will restart process in %llums\n",
797 (unsigned long long) lowestRestartDelay.rel_value);
800 = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
801 &delayed_restart_task,
808 * Task triggered whenever we receive a SIGCHLD (child
811 * @param cls closure, NULL if we need to self-restart
815 maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
817 struct ServiceList *pos;
818 struct ServiceList *prev;
819 struct ServiceList *next;
824 enum GNUNET_OS_ProcessStatusType statusType;
825 unsigned long statusCode;
827 child_death_task = GNUNET_SCHEDULER_NO_TASK;
828 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
831 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
832 &maint_child_death, NULL);
835 /* consume the signal */
836 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
838 /* check for services that died (WAITPID) */
841 while (NULL != (pos = next))
844 if (pos->proc == NULL)
849 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
852 ( (ret == GNUNET_NO) ||
853 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
854 (statusType == GNUNET_OS_PROCESS_RUNNING)) )
860 if (statusType == GNUNET_OS_PROCESS_EXITED)
862 statstr = _( /* process termination method */ "exit");
863 statcode = statusCode;
865 else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
867 statstr = _( /* process termination method */ "signal");
868 statcode = statusCode;
872 statstr = _( /* process termination method */ "unknown");
875 GNUNET_OS_process_close (pos->proc);
877 if (NULL != pos->killing_client)
883 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
884 _("Service `%s' stopped\n"),
886 signal_result (pos->killing_client,
887 pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
888 GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
889 GNUNET_SERVER_client_drop (pos->killing_client);
893 if (GNUNET_YES != in_shutdown)
895 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
897 ("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
898 pos->name, statstr, statcode);
899 /* schedule restart */
901 = GNUNET_TIME_relative_to_absolute (pos->backoff);
902 if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD)
904 = GNUNET_TIME_relative_multiply (pos->backoff, 2);
905 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
906 GNUNET_SCHEDULER_cancel (child_restart_task);
908 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
909 &delayed_restart_task,
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
915 "Service `%s' terminated with status %s/%d\n",
916 pos->name, statstr, statcode);
922 if ( (running == NULL) &&
925 GNUNET_SERVER_destroy (server);
930 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
931 &maint_child_death, NULL);
937 transmit_shutdown_ack (void *cls, size_t size, void *buf)
939 struct GNUNET_SERVER_Client *client = cls;
940 struct GNUNET_MessageHeader *msg;
942 if (size < sizeof (struct GNUNET_MessageHeader))
944 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
945 _("Failed to transmit shutdown ACK.\n"));
946 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
947 return 0; /* client disconnected */
950 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
951 _("Transmitting shutdown ACK.\n"));
953 msg = (struct GNUNET_MessageHeader *) buf;
954 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK);
955 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
956 GNUNET_SERVER_receive_done (client, GNUNET_OK);
957 GNUNET_SERVER_client_drop(client);
958 return sizeof (struct GNUNET_MessageHeader);
962 * Handler for SHUTDOWN message.
964 * @param cls closure (refers to service)
965 * @param client identification of the client
966 * @param message the actual message
969 handle_shutdown (void *cls,
970 struct GNUNET_SERVER_Client *client,
971 const struct GNUNET_MessageHeader *message)
973 GNUNET_SERVER_client_keep(client);
974 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
975 _("Initiating shutdown as requested by client.\n"));
977 GNUNET_SERVER_notify_transmit_ready (client,
978 sizeof(struct GNUNET_MessageHeader),
979 GNUNET_TIME_UNIT_FOREVER_REL,
980 &transmit_shutdown_ack, client);
981 GNUNET_SERVER_client_persist_ (client);
982 GNUNET_SCHEDULER_shutdown ();
987 * Signal handler called for SIGCHLD. Triggers the
988 * respective handler by writing to the trigger pipe.
991 sighandler_child_death ()
994 int old_errno = errno; /* back-up errno */
996 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
997 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
999 errno = old_errno; /* restore errno */
1004 * Process arm requests.
1006 * @param cls closure
1007 * @param serv the initialized server
1008 * @param c configuration to use
1012 struct GNUNET_SERVER_Handle *serv,
1013 const struct GNUNET_CONFIGURATION_Handle *c)
1015 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1016 {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
1017 {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
1018 {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN,
1019 sizeof (struct GNUNET_MessageHeader)},
1022 char *defaultservices;
1027 GNUNET_assert (serv != NULL);
1028 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
1029 GNUNET_assert (pr != NULL);
1030 GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
1031 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1035 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
1036 &maint_child_death, NULL);
1039 GNUNET_CONFIGURATION_get_value_string (cfg,
1043 prefix_command = GNUNET_strdup ("");
1045 GNUNET_CONFIGURATION_get_value_string (cfg,
1049 final_option = GNUNET_strdup ("");
1050 /* start default services... */
1052 GNUNET_CONFIGURATION_get_value_string (cfg,
1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1059 "Starting default services `%s'\n", defaultservices);
1061 if (0 < strlen (defaultservices))
1063 pos = strtok (defaultservices, " ");
1066 start_service (NULL, pos, NULL);
1067 pos = strtok (NULL, " ");
1070 GNUNET_free (defaultservices);
1075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1076 "No default services configured.\n");
1080 /* create listening sockets for future services*/
1081 prepareServices (cfg);
1083 /* process client requests */
1084 GNUNET_SERVER_add_handlers (server, handlers);
1086 /* manage services */
1087 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1088 &config_change_task, NULL);
1093 * The main function for the arm service.
1095 * @param argc number of arguments from the command line
1096 * @param argv command line arguments
1097 * @return 0 ok, 1 on error
1100 main (int argc, char *const *argv)
1103 struct GNUNET_SIGNAL_Context *shc_chld;
1105 sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO);
1106 GNUNET_assert (sigpipe != NULL);
1107 shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
1109 GNUNET_SERVICE_run (argc,
1110 argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1;
1111 GNUNET_SIGNAL_handler_uninstall (shc_chld);
1113 GNUNET_DISK_pipe_close (sigpipe);
1122 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1124 void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
1126 mallopt (M_TRIM_THRESHOLD, 4*1024);
1127 mallopt (M_TOP_PAD, 1*1024);
1133 /* end of gnunet-service-arm.c */