/*
This file is part of GNUnet.
- (C) 2009, 2012 Christian Grothoff (and other contributing authors)
+ (C) 2009, 2012, 2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
/**
* Our configuration.
*/
-static const struct GNUNET_CONFIGURATION_Handle *cfg;
+static struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Processing stage that we are in. Simple counter.
/**
* Do we want to give our stdout to gnunet-service-arm?
*/
-static unsigned int no_stdout = 0;
+static unsigned int no_stdout;
/**
* Do we want to give our stderr to gnunet-service-arm?
*/
-static unsigned int no_stderr = 0;
+static unsigned int no_stderr;
/**
FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n"));
break;
}
- GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
}
}
+/**
+ * Attempts to delete configuration file and SERVICEHOME
+ * on arm shutdown provided the end and delete options
+ * were specified when gnunet-arm was run.
+ */
+static void
+delete_files ()
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Will attempt to remove configuration file %s and service directory %s\n",
+ config_file, dir);
+
+ if (UNLINK (config_file) != 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to remove configuration file %s\n"), config_file);
+ }
+
+ if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to remove servicehome directory %s\n"), dir);
+
+ }
+}
+
+
+/**
+ * Main continuation-passing-style loop. Runs the various
+ * jobs that we've been asked to do in order.
+ *
+ * @param cls closure, unused
+ * @param tc context, unused
+ */
+static void
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_ARM_disconnect (h);
+ h = NULL;
+ if ((end == GNUNET_YES) && (delete == GNUNET_YES))
+ delete_files ();
+ GNUNET_CONFIGURATION_destroy (cfg);
+ cfg = NULL;
+}
+
+
/**
* Main function that will be run by the scheduler.
*
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- cfg = c;
+ char *armconfig;
+
+ cfg = GNUNET_CONFIGURATION_dup (c);
config_file = cfgfile;
if (GNUNET_CONFIGURATION_get_value_string
(cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK)
"PATHS", "SERVICEHOME");
return;
}
+ if (NULL != cfgfile)
+ {
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg, "arm", "CONFIG",
+ &armconfig))
+ {
+ GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
+ cfgfile);
+ }
+ else
+ GNUNET_free (armconfig);
+ }
if (NULL == (h = GNUNET_ARM_connect (cfg, NULL)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Fatal error initializing ARM API.\n"));
ret = 1;
+ GNUNET_CONFIGURATION_destroy (cfg);
+ cfg = NULL;
return;
}
- GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-}
-
-
-/**
- * Attempts to delete configuration file and SERVICEHOME
- * on arm shutdown provided the end and delete options
- * were specified when gnunet-arm was run.
- */
-static void
-delete_files ()
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Will attempt to remove configuration file %s and service directory %s\n",
- config_file, dir);
-
- if (UNLINK (config_file) != 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove configuration file %s\n"), config_file);
- }
-
- if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to remove servicehome directory %s\n"), dir);
-
- }
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
}
static void
cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ if (NULL == h)
+ return;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
while (1)
{
switch (phase++)
}
/* Fall through */
default: /* last phase */
- GNUNET_ARM_disconnect (h);
- if ((end == GNUNET_YES) && (delete == GNUNET_YES))
- delete_files ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}