time_t mtime;
/**
- * Process exponential backoff time
+ * Process exponential backoff time
*/
struct GNUNET_TIME_Relative backoff;
/**
- * Absolute time at which the process is scheduled to restart in case of death
+ * Absolute time at which the process is scheduled to restart in case of death
*/
struct GNUNET_TIME_Absolute restartAt;
while (pos != NULL)
{
/* FIXME: this test for config change may be a bit too coarse grained */
- if ((0 == STAT (pos->config, &sbuf)) &&
- (pos->mtime < sbuf.st_mtime) && (pos->proc != NULL))
+ if ((0 == STAT (pos->config, &sbuf)) && (pos->mtime < sbuf.st_mtime) &&
+ (pos->proc != NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_
return 0; /* error, not much we can do */
}
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending status response %u to client\n", (unsigned int) *res);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending status response %u to client\n",
+ (unsigned int) *res);
#endif
GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
msg = buf;
* @return NULL if it was not found
*/
static void
-signal_result (struct GNUNET_SERVER_Client *client,
- const char *name, uint16_t result)
+signal_result (struct GNUNET_SERVER_Client *client, const char *name,
+ uint16_t result)
{
uint16_t *res;
}
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Telling client that service `%s' is now %s\n",
- name, result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
+ "Telling client that service `%s' is now %s\n", name,
+ result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up");
#endif
res = GNUNET_malloc (sizeof (uint16_t));
*res = result;
/* start service */
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name, "PREFIX", &loprefix))
+ GNUNET_CONFIGURATION_get_value_string (cfg, sl->name, "PREFIX",
+ &loprefix))
loprefix = GNUNET_strdup (prefix_command);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- sl->name, "OPTIONS", &options))
+ GNUNET_CONFIGURATION_get_value_string (cfg, sl->name, "OPTIONS",
+ &options))
{
options = GNUNET_strdup (final_option);
if (NULL == strstr (options, "%"))
next = optend + 1;
*optend = '\0';
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS",
- optpos + 1, &val))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", optpos + 1,
+ &val))
val = GNUNET_strdup ("");
*optpos = '\0';
GNUNET_asprintf (&optpos, "%s%s%c%s", options, val, b, next);
sl->name, sl->binary, sl->config);
#endif
if (GNUNET_YES == use_debug)
- sl->proc = do_start_process (lsocks,
- loprefix,
- sl->binary,
- "-c", sl->config,
- "-L", "DEBUG", options, NULL);
+ sl->proc =
+ do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config, "-L",
+ "DEBUG", options, NULL);
else
- sl->proc = do_start_process (lsocks,
- loprefix,
- sl->binary, "-c", sl->config, options, NULL);
+ sl->proc =
+ do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config,
+ options, NULL);
if (sl->proc == NULL)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to start service `%s'\n"), sl->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start service `%s'\n"),
+ sl->name);
else
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"), sl->name);
GNUNET_free (loprefix);
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
int
-start_service (struct GNUNET_SERVER_Client *client,
- const char *servicename, const int *lsocks)
+start_service (struct GNUNET_SERVER_Client *client, const char *servicename,
+ const int *lsocks)
{
struct ServiceList *sl;
char *binary;
sl = find_service (servicename);
if (sl != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Service `%s' already running.\n"), servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Service `%s' already running.\n"),
+ servicename);
signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- servicename, "BINARY", &binary))
+ GNUNET_CONFIGURATION_get_value_string (cfg, servicename, "BINARY",
+ &binary))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Binary implementing service `%s' not known!\n"),
return GNUNET_SYSERR;
}
if ((GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- servicename,
- "CONFIG",
+ GNUNET_CONFIGURATION_get_value_filename (cfg, servicename, "CONFIG",
&config)) ||
(0 != STAT (config, &sbuf)))
{
{
struct ServiceList *pos;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Preparing to stop `%s'\n"), servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Preparing to stop `%s'\n"),
+ servicename);
pos = find_service (servicename);
if (pos == NULL)
{
{
/* killing already in progress */
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' is already down\n", servicename);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' is already down\n",
+ servicename);
#endif
signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
* GNUNET_SYSERR to close it (signal serious error)
*/
static void
-handle_start (void *cls,
- struct GNUNET_SERVER_Client *client,
+handle_start (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const char *servicename;
* GNUNET_SYSERR to close it (signal serious error)
*/
static void
-handle_stop (void *cls,
- struct GNUNET_SERVER_Client *client,
+handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const char *servicename;
/**
- * We are done with everything. Stop remaining
- * tasks, signal handler and the server.
+ * We are done with everything. Stop remaining
+ * tasks, signal handler and the server.
*/
static void
do_shutdown ()
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
+ struct ServiceList *nxt;
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n"));
pos = running_head;
while (NULL != pos)
{
+ nxt = pos->next;
if (pos->proc != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name);
if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
}
- pos = pos->next;
+ else
+ {
+ free_service (pos);
+ }
+ pos = nxt;
}
if (running_head == NULL)
do_shutdown ();
{
if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Restarting service `%s'.\n"), pos->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Restarting service `%s'.\n"),
+ pos->name);
start_process (pos, NULL);
}
else
{
- lowestRestartDelay
- = GNUNET_TIME_relative_min (lowestRestartDelay,
- GNUNET_TIME_absolute_get_remaining
- (pos->restartAt));
+ lowestRestartDelay =
+ GNUNET_TIME_relative_min (lowestRestartDelay,
+ GNUNET_TIME_absolute_get_remaining
+ (pos->restartAt));
}
}
pos = pos->next;
if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
{
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will restart process in %llums\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will restart process in %llums\n",
(unsigned long long) lowestRestartDelay.rel_value);
#endif
- child_restart_task
- = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay,
- &delayed_restart_task, NULL);
+ child_restart_task =
+ GNUNET_SCHEDULER_add_delayed (lowestRestartDelay, &delayed_restart_task,
+ NULL);
}
}
/**
* Task triggered whenever we receive a SIGCHLD (child
- * process died).
+ * process died).
*
* @param cls closure, NULL if we need to self-restart
* @param tc context
next = pos->next;
if (pos->proc == NULL)
continue;
- if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
- &statusType,
- &statusCode))) ||
- ((ret == GNUNET_NO) ||
- (statusType == GNUNET_OS_PROCESS_STOPPED) ||
- (statusType == GNUNET_OS_PROCESS_RUNNING)))
+ if ((GNUNET_SYSERR ==
+ (ret = GNUNET_OS_process_status (pos->proc, &statusType, &statusCode)))
+ || ((ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) ||
+ (statusType == GNUNET_OS_PROCESS_RUNNING)))
continue;
if (statusType == GNUNET_OS_PROCESS_EXITED)
pos->proc = NULL;
if (NULL != pos->killing_client)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' stopped\n"), pos->name);
- signal_result (pos->killing_client,
- pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Service `%s' stopped\n"),
+ pos->name);
+ signal_result (pos->killing_client, pos->name,
+ GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK);
GNUNET_SERVER_client_drop (pos->killing_client);
free_service (pos);
pos->backoff = GNUNET_TIME_relative_multiply (pos->backoff, 2);
if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
GNUNET_SCHEDULER_cancel (child_restart_task);
- child_restart_task
- = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &delayed_restart_task, NULL);
+ child_restart_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &delayed_restart_task, NULL);
}
#if DEBUG_ARM
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Service `%s' terminated with status %s/%d\n",
- pos->name, statstr, statcode);
+ "Service `%s' terminated with status %s/%d\n", pos->name,
+ statstr, statcode);
#endif
}
child_death_task =
* @param message the actual message
*/
static void
-handle_shutdown (void *cls,
- struct GNUNET_SERVER_Client *client,
+handle_shutdown (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
GNUNET_SERVER_client_keep (client);
* @param c configuration to use
*/
static void
-run (void *cls,
- struct GNUNET_SERVER_Handle *serv,
+run (void *cls, struct GNUNET_SERVER_Handle *serv,
const struct GNUNET_CONFIGURATION_Handle *c)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
GNUNET_assert (pr != NULL);
GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+ NULL);
child_death_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr,
&maint_child_death, NULL);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_PREFIX", &prefix_command))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_PREFIX",
+ &prefix_command))
prefix_command = GNUNET_strdup ("");
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "GLOBAL_POSTFIX", &final_option))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_POSTFIX",
+ &final_option))
final_option = GNUNET_strdup ("");
/* start default services... */
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "ARM",
- "DEFAULTSERVICES",
+ GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "DEFAULTSERVICES",
&defaultservices))
{
#if DEBUG_ARM
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting default services `%s'\n", defaultservices);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting default services `%s'\n",
+ defaultservices);
#endif
if (0 < strlen (defaultservices))
{