aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-arm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r--src/arm/gnunet-arm.c53
1 files changed, 50 insertions, 3 deletions
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
@@ -46,6 +46,11 @@ static int end;
46static int start; 46static int start;
47 47
48/** 48/**
49 * Set if we should delete configuration and temp directory on exit.
50 */
51static int delete;
52
53/**
49 * Set to the name of a service to start. 54 * Set to the name of a service to start.
50 */ 55 */
51static char *init; 56static char *init;
@@ -61,6 +66,16 @@ static char *term;
61static char *test; 66static char *test;
62 67
63/** 68/**
69 * Set to the name of the config file used.
70 */
71static const char *config_file;
72
73/**
74 * Set to the directory where runtime files are stored.
75 */
76static char *dir;
77
78/**
64 * Final status code. 79 * Final status code.
65 */ 80 */
66static int ret; 81static int ret;
@@ -89,7 +104,7 @@ static unsigned int phase;
89/** 104/**
90 * Main continuation-passing-style loop. Runs the various 105 * Main continuation-passing-style loop. Runs the various
91 * jobs that we've been asked to do in order. 106 * jobs that we've been asked to do in order.
92 * 107 *
93 * @param cls closure, unused 108 * @param cls closure, unused
94 * @param tc context, unused 109 * @param tc context, unused
95 */ 110 */
@@ -165,11 +180,17 @@ static void
165run (void *cls, 180run (void *cls,
166 struct GNUNET_SCHEDULER_Handle *s, 181 struct GNUNET_SCHEDULER_Handle *s,
167 char *const *args, 182 char *const *args,
168 const char *cfgfile, 183 const char *cfgfile,
169 const struct GNUNET_CONFIGURATION_Handle *c) 184 const struct GNUNET_CONFIGURATION_Handle *c)
170{ 185{
171 sched = s; 186 sched = s;
172 cfg = c; 187 cfg = c;
188 config_file = cfgfile;
189 if (GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK)
190 {
191 dir = NULL;
192 }
193
173 h = GNUNET_ARM_connect (cfg, sched, NULL); 194 h = GNUNET_ARM_connect (cfg, sched, NULL);
174 if (h == NULL) 195 if (h == NULL)
175 { 196 {
@@ -184,11 +205,33 @@ run (void *cls,
184 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 205 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
185} 206}
186 207
208/**
209 * Attempts to delete configuration file and SERVICEHOME
210 * on arm shutdown provided the end and delete options
211 * were specified when gnunet-arm was run.
212 */
213static void delete_files()
214{
215 fprintf(stderr, "Will attempt to remove configuration file %s and service directory %s\n", config_file, dir);
216
217 if (UNLINK(config_file) != 0)
218 {
219 fprintf (stderr,
220 _("Failed to remove configuration file %s\n"), config_file);
221 }
222
223 if (GNUNET_DISK_directory_remove(dir) != GNUNET_OK)
224 {
225 fprintf (stderr,
226 _("Failed to remove servicehome directory %s\n"), dir);
227
228 }
229}
187 230
188/** 231/**
189 * Main continuation-passing-style loop. Runs the various 232 * Main continuation-passing-style loop. Runs the various
190 * jobs that we've been asked to do in order. 233 * jobs that we've been asked to do in order.
191 * 234 *
192 * @param cls closure, unused 235 * @param cls closure, unused
193 * @param tc context, unused 236 * @param tc context, unused
194 */ 237 */
@@ -237,6 +280,8 @@ cps_loop (void *cls,
237 break; 280 break;
238 default: /* last phase */ 281 default: /* last phase */
239 GNUNET_ARM_disconnect (h); 282 GNUNET_ARM_disconnect (h);
283 if ((end == GNUNET_YES) && (delete == GNUNET_YES))
284 delete_files();
240 return; 285 return;
241 } 286 }
242 } 287 }
@@ -258,6 +303,8 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
258 {'t', "test", "SERVICE", 303 {'t', "test", "SERVICE",
259 gettext_noop ("test if a particular service is running"), 304 gettext_noop ("test if a particular service is running"),
260 GNUNET_YES, &GNUNET_GETOPT_set_string, &test}, 305 GNUNET_YES, &GNUNET_GETOPT_set_string, &test},
306 {'d', "delete", NULL, gettext_noop ("delete config file and directory on exit"),
307 GNUNET_NO, &GNUNET_GETOPT_set_one, &delete},
261 GNUNET_GETOPT_OPTION_END 308 GNUNET_GETOPT_OPTION_END
262}; 309};
263 310