From: Nathan S. Evans Date: Mon, 29 Mar 2010 16:32:38 +0000 (+0000) Subject: gnunet-arm option to delete configuration file and servicehome directory, tailored... X-Git-Tag: initial-import-from-subversion-38251~22358 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c06f823b912709d2d30a8e5329f669916bce7ae6;p=oweals%2Fgnunet.git gnunet-arm option to delete configuration file and servicehome directory, tailored only for testcases as users probably won't want to delete their configuration file whenever shutting down gnunet (unless they really hate it) --- diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 73aaf8f2a..55178843a 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -45,6 +45,11 @@ static int end; */ static int start; +/** + * Set if we should delete configuration and temp directory on exit. + */ +static int delete; + /** * Set to the name of a service to start. */ @@ -60,6 +65,16 @@ static char *term; */ static char *test; +/** + * Set to the name of the config file used. + */ +static const char *config_file; + +/** + * Set to the directory where runtime files are stored. + */ +static char *dir; + /** * Final status code. */ @@ -89,7 +104,7 @@ static unsigned int phase; /** * 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 */ @@ -165,11 +180,17 @@ static void run (void *cls, struct GNUNET_SCHEDULER_Handle *s, char *const *args, - const char *cfgfile, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { sched = s; cfg = c; + config_file = cfgfile; + if (GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK) + { + dir = NULL; + } + h = GNUNET_ARM_connect (cfg, sched, NULL); if (h == NULL) { @@ -184,11 +205,33 @@ run (void *cls, 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() +{ + fprintf(stderr, "Will attempt to remove configuration file %s and service directory %s\n", config_file, dir); + + if (UNLINK(config_file) != 0) + { + fprintf (stderr, + _("Failed to remove configuration file %s\n"), config_file); + } + + if (GNUNET_DISK_directory_remove(dir) != GNUNET_OK) + { + fprintf (stderr, + _("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 */ @@ -237,6 +280,8 @@ cps_loop (void *cls, break; default: /* last phase */ GNUNET_ARM_disconnect (h); + if ((end == GNUNET_YES) && (delete == GNUNET_YES)) + delete_files(); return; } } @@ -258,6 +303,8 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { {'t', "test", "SERVICE", gettext_noop ("test if a particular service is running"), GNUNET_YES, &GNUNET_GETOPT_set_string, &test}, + {'d', "delete", NULL, gettext_noop ("delete config file and directory on exit"), + GNUNET_NO, &GNUNET_GETOPT_set_one, &delete}, GNUNET_GETOPT_OPTION_END };