gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10709 - gnunet/src/arm


From: gnunet
Subject: [GNUnet-SVN] r10709 - gnunet/src/arm
Date: Mon, 29 Mar 2010 18:32:38 +0200

Author: nevans
Date: 2010-03-29 18:32:38 +0200 (Mon, 29 Mar 2010)
New Revision: 10709

Modified:
   gnunet/src/arm/gnunet-arm.c
Log:
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)

Modified: gnunet/src/arm/gnunet-arm.c
===================================================================
--- gnunet/src/arm/gnunet-arm.c 2010-03-29 16:31:23 UTC (rev 10708)
+++ gnunet/src/arm/gnunet-arm.c 2010-03-29 16:32:38 UTC (rev 10709)
@@ -46,6 +46,11 @@
 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.
  */
 static char *init;
@@ -61,6 +66,16 @@
 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.
  */
 static int ret;
@@ -89,7 +104,7 @@
 /**
  * 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 @@
 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 @@
                                     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 @@
          break;
        default: /* last phase */
          GNUNET_ARM_disconnect (h);
+         if ((end == GNUNET_YES) && (delete == GNUNET_YES))
+           delete_files();
          return;
        }
     }
@@ -258,6 +303,8 @@
   {'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
 };
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]