aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-arm.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-12-06 13:53:33 +0000
committerChristian Grothoff <christian@grothoff.org>2012-12-06 13:53:33 +0000
commit4127ea5df52dafca5538d2f9b74b0bec0c18bb8d (patch)
tree09ecd26d65c0d5c639df6a8c285b6ccbc06d37ad /src/arm/gnunet-arm.c
parenteb7221b4ca8db6152240b4f71b35ef7296795532 (diff)
downloadgnunet-4127ea5df52dafca5538d2f9b74b0bec0c18bb8d.tar.gz
gnunet-4127ea5df52dafca5538d2f9b74b0bec0c18bb8d.zip
-improving shutdown behavior
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r--src/arm/gnunet-arm.c91
1 files changed, 55 insertions, 36 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index a37a78a26..ca4193837 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -128,12 +128,12 @@ static struct GNUNET_TIME_Relative timeout;
128/** 128/**
129 * Do we want to give our stdout to gnunet-service-arm? 129 * Do we want to give our stdout to gnunet-service-arm?
130 */ 130 */
131static unsigned int no_stdout = 0; 131static unsigned int no_stdout;
132 132
133/** 133/**
134 * Do we want to give our stderr to gnunet-service-arm? 134 * Do we want to give our stderr to gnunet-service-arm?
135 */ 135 */
136static unsigned int no_stderr = 0; 136static unsigned int no_stderr;
137 137
138 138
139/** 139/**
@@ -206,8 +206,7 @@ confirm_cb (void *cls,
206 FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n")); 206 FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n"));
207 break; 207 break;
208 } 208 }
209 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, 209 GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
210 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
211} 210}
212 211
213 212
@@ -237,6 +236,50 @@ list_cb (void *cls, int result, unsigned int count, const char *const*list)
237 236
238 237
239/** 238/**
239 * Attempts to delete configuration file and SERVICEHOME
240 * on arm shutdown provided the end and delete options
241 * were specified when gnunet-arm was run.
242 */
243static void
244delete_files ()
245{
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Will attempt to remove configuration file %s and service directory %s\n",
248 config_file, dir);
249
250 if (UNLINK (config_file) != 0)
251 {
252 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
253 _("Failed to remove configuration file %s\n"), config_file);
254 }
255
256 if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
257 {
258 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
259 _("Failed to remove servicehome directory %s\n"), dir);
260
261 }
262}
263
264
265/**
266 * Main continuation-passing-style loop. Runs the various
267 * jobs that we've been asked to do in order.
268 *
269 * @param cls closure, unused
270 * @param tc context, unused
271 */
272static void
273shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
274{
275 GNUNET_ARM_disconnect (h);
276 h = NULL;
277 if ((end == GNUNET_YES) && (delete == GNUNET_YES))
278 delete_files ();
279}
280
281
282/**
240 * Main function that will be run by the scheduler. 283 * Main function that will be run by the scheduler.
241 * 284 *
242 * @param cls closure 285 * @param cls closure
@@ -264,35 +307,9 @@ run (void *cls, char *const *args, const char *cfgfile,
264 ret = 1; 307 ret = 1;
265 return; 308 return;
266 } 309 }
267 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, 310 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
268 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 311 &shutdown_task, NULL);
269} 312 GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
270
271
272/**
273 * Attempts to delete configuration file and SERVICEHOME
274 * on arm shutdown provided the end and delete options
275 * were specified when gnunet-arm was run.
276 */
277static void
278delete_files ()
279{
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281 "Will attempt to remove configuration file %s and service directory %s\n",
282 config_file, dir);
283
284 if (UNLINK (config_file) != 0)
285 {
286 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
287 _("Failed to remove configuration file %s\n"), config_file);
288 }
289
290 if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
291 {
292 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
293 _("Failed to remove servicehome directory %s\n"), dir);
294
295 }
296} 313}
297 314
298 315
@@ -306,6 +323,10 @@ delete_files ()
306static void 323static void
307cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 324cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
308{ 325{
326 if (NULL == h)
327 return;
328 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
329 return;
309 while (1) 330 while (1)
310 { 331 {
311 switch (phase++) 332 switch (phase++)
@@ -393,9 +414,7 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
393 } 414 }
394 /* Fall through */ 415 /* Fall through */
395 default: /* last phase */ 416 default: /* last phase */
396 GNUNET_ARM_disconnect (h); 417 GNUNET_SCHEDULER_shutdown ();
397 if ((end == GNUNET_YES) && (delete == GNUNET_YES))
398 delete_files ();
399 return; 418 return;
400 } 419 }
401 } 420 }