/**
* Our configuration
*/
-static struct GNUNET_CONFIGURATION_Handle *cfg;
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Our scheduler.
{
uint16_t *res;
+ if (NULL == client)
+ return;
#if DEBUG_ARM
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Telling client that service `%s' is now %s\n",
sl->mtime = sbuf.st_mtime;
running = sl;
start_process (sl);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
+ if (NULL != client)
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP);
}
{
struct GNUNET_SERVER_Client *client = cls;
/* find_name will remove "pos" from the list! */
- GNUNET_assert (pos == find_name (pos->name));
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Service `%s' stopped\n", pos->name);
signal_result (client, pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
{
struct ServiceList *pos;
struct GNUNET_CLIENT_Connection *sc;
+ unsigned long long port;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Preparing to stop `%s'\n", servicename);
}
else
{
- sc = GNUNET_CLIENT_connect (sched, servicename, cfg);
- GNUNET_CLIENT_service_shutdown (sc);
- GNUNET_CLIENT_disconnect (sc);
- signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ if ( (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ servicename,
+ "PORT",
+ &port)) &&
+ (NULL != (sc = GNUNET_CLIENT_connect (sched, servicename, cfg))) )
+ {
+ GNUNET_CLIENT_service_shutdown (sc);
+ GNUNET_CLIENT_disconnect (sc);
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN);
+ }
+ else
+ {
+ signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN);
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
}
maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ServiceList *pos;
+ struct ServiceList *prev;
+ struct ServiceList *next;
const char *statstr;
int statcode;
struct stat sbuf;
GNUNET_SCHEDULER_add_delayed (tc->sched,
GNUNET_YES,
GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
- MAINT_FREQUENCY, &maint, cfg);
+ GNUNET_SCHEDULER_NO_TASK,
+ MAINT_FREQUENCY, &maint, NULL);
/* check for services that died (WAITPID) */
- for (pos = running; pos != NULL; pos = pos->next)
+ prev = NULL;
+ next = running;
+ while (NULL != (pos = next))
{
enum GNUNET_OS_ProcessStatusType statusType;
unsigned long statusCode;
-
- if (GNUNET_SYSERR == (ret = GNUNET_OS_process_status(pos->pid, &statusType, &statusCode)))
- continue;
- if ( (ret == GNUNET_NO) ||
- (statusType == GNUNET_OS_PROCESS_STOPPED) ||
- (statusType == GNUNET_OS_PROCESS_RUNNING) )
- continue;
+
+ next = pos->next;
+ if (pos->pid == 0)
+ {
+ if (NULL != pos->kill_continuation)
+ {
+ if (prev == NULL)
+ running = next;
+ else
+ prev->next = next;
+ pos->kill_continuation (pos->kill_continuation_cls, pos);
+ }
+ continue;
+ }
+ if ( (GNUNET_SYSERR == (ret = GNUNET_OS_process_status(pos->pid,
+ &statusType,
+ &statusCode))) ||
+ ( (ret == GNUNET_NO) ||
+ (statusType == GNUNET_OS_PROCESS_STOPPED) ||
+ (statusType == GNUNET_OS_PROCESS_RUNNING) ) )
+ {
+ prev = pos;
+ continue;
+ }
if (statusType == GNUNET_OS_PROCESS_EXITED)
- {
- statstr = _( /* process termination method */ "exit");
- statcode = statusCode;
- }
+ {
+ statstr = _( /* process termination method */ "exit");
+ statcode = statusCode;
+ }
else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
- {
- statstr = _( /* process termination method */ "signal");
- statcode = statusCode;
- }
+ {
+ statstr = _( /* process termination method */ "signal");
+ statcode = statusCode;
+ }
else
- {
- statstr = _( /* process termination method */ "unknown");
- statcode = 0;
- }
+ {
+ statstr = _( /* process termination method */ "unknown");
+ statcode = 0;
+ }
if (NULL != pos->kill_continuation)
{
- pos->kill_continuation (pos->kill_continuation_cls, pos);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
- pos->name, statstr, statcode);
- /* schedule restart */
- pos->pid = 0;
+ if (prev == NULL)
+ running = next;
+ else
+ prev->next = next;
+ pos->kill_continuation (pos->kill_continuation_cls, pos);
+ continue;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Service `%s' terminated with status %s/%d, will try to restart it!\n"),
+ pos->name, statstr, statcode);
+ /* schedule restart */
+ pos->pid = 0;
+ prev = pos;
}
/* check for services that need to be restarted due to
if ((0 == STAT (pos->config, &sbuf)) && (pos->mtime < sbuf.st_mtime))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _
- ("Restarting service `%s' due to configuration file change.\n"));
+ _("Restarting service `%s' due to configuration file change.\n"));
if (0 != PLIBC_KILL (pos->pid, SIGTERM))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
}
run (void *cls,
struct GNUNET_SCHEDULER_Handle *s,
struct GNUNET_SERVER_Handle *server,
- struct GNUNET_CONFIGURATION_Handle *c)
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
char *defaultservices;
char *pos;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting...\n");
cfg = c;
sched = s;
if (GNUNET_OK !=
GNUNET_SCHEDULER_add_delayed (sched,
GNUNET_YES,
GNUNET_SCHEDULER_PRIORITY_IDLE,
- GNUNET_SCHEDULER_NO_PREREQUISITE_TASK,
+ GNUNET_SCHEDULER_NO_TASK,
MAINT_FREQUENCY, &maint, NULL);
}