gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36170 - gnunet/src/fs


From: gnunet
Subject: [GNUnet-SVN] r36170 - gnunet/src/fs
Date: Mon, 3 Aug 2015 10:25:37 +0200

Author: grothoff
Date: 2015-08-03 10:25:37 +0200 (Mon, 03 Aug 2015)
New Revision: 36170

Modified:
   gnunet/src/fs/gnunet-publish.c
Log:
fix #3904, also simplify and clean up gnunet-publish shutdown logic in general

Modified: gnunet/src/fs/gnunet-publish.c
===================================================================
--- gnunet/src/fs/gnunet-publish.c      2015-08-03 08:18:52 UTC (rev 36169)
+++ gnunet/src/fs/gnunet-publish.c      2015-08-03 08:25:37 UTC (rev 36170)
@@ -30,9 +30,9 @@
 #include "gnunet_identity_service.h"
 
 /**
- * Global return value from 'main'.
+ * Global return value from #main().
  */
-static int ret = 1;
+static int ret;
 
 /**
  * Command line option 'verbose' set
@@ -125,11 +125,6 @@
 static int do_disable_creation_time;
 
 /**
- * Task run on CTRL-C to kill everything nicely.
- */
-static struct GNUNET_SCHEDULER_Task * kill_task;
-
-/**
  * Handle to the directory scanner (for recursive insertions).
  */
 static struct GNUNET_FS_DirScanner *ds;
@@ -159,7 +154,11 @@
 {
   struct GNUNET_FS_PublishContext *p;
 
-  kill_task = NULL;
+  if (NULL != ds)
+  {
+    GNUNET_FS_directory_scan_abort (ds);
+    ds = NULL;
+  }
   if (NULL != identity)
   {
     GNUNET_IDENTITY_disconnect (identity);
@@ -171,37 +170,21 @@
     pc = NULL;
     GNUNET_FS_publish_stop (p);
   }
+  if (NULL != ctx)
+  {
+    GNUNET_FS_stop (ctx);
+    ctx = NULL;
+  }
   if (NULL != meta)
   {
     GNUNET_CONTAINER_meta_data_destroy (meta);
     meta = NULL;
   }
-}
-
-
-/**
- * Stop the directory scanner (we had an error).
- *
- * @param cls closure
- * @param tc scheduler context
- */
-static void
-stop_scanner_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  kill_task = NULL;
-  if (NULL != ds)
+  if (NULL != uri)
   {
-    GNUNET_FS_directory_scan_abort (ds);
-    ds = NULL;
+    GNUNET_FS_uri_destroy (uri);
+    uri = NULL;
   }
-  if (NULL != identity)
-  {
-    GNUNET_IDENTITY_disconnect (identity);
-    identity = NULL;
-  }
-  GNUNET_FS_stop (ctx);
-  ctx = NULL;
-  ret = 1;
 }
 
 
@@ -254,14 +237,11 @@
     }
     break;
   case GNUNET_FS_STATUS_PUBLISH_ERROR:
-    FPRINTF (stderr, _("Error publishing: %s.\n"),
+    FPRINTF (stderr,
+             _("Error publishing: %s.\n"),
              info->value.publish.specifics.error.message);
-    if (kill_task != NULL)
-    {
-      GNUNET_SCHEDULER_cancel (kill_task);
-      kill_task = NULL;
-    }
-    kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL);
+    ret = 1;
+    GNUNET_SCHEDULER_shutdown ();
     break;
   case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
     FPRINTF (stdout,
@@ -284,11 +264,9 @@
     }
     if (NULL == info->value.publish.pctx)
     {
-      if (NULL != kill_task)
-        GNUNET_SCHEDULER_cancel (kill_task);
-      kill_task = GNUNET_SCHEDULER_add_now (&do_stop_task, NULL);
+      ret = 0;
+      GNUNET_SCHEDULER_shutdown ();
     }
-    ret = 0;
     break;
   case GNUNET_FS_STATUS_PUBLISH_STOPPED:
     GNUNET_break (NULL == pc);
@@ -351,9 +329,15 @@
   if (EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME == type)
     return 0;
 #if HAVE_LIBEXTRACTOR
-  FPRINTF (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data);
+  FPRINTF (stdout,
+           "\t%s - %s\n",
+           EXTRACTOR_metatype_to_string (type),
+           data);
 #else
-  FPRINTF (stdout, "\t%d - %s\n", type, data);
+  FPRINTF (stdout,
+           "\t%d - %s\n",
+           type,
+           data);
 #endif
   return 0;
 }
@@ -444,17 +428,26 @@
     fn = GNUNET_CONTAINER_meta_data_get_by_type (m,
                                                  
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
     fs = GNUNET_STRINGS_byte_size_fancy (length);
-    FPRINTF (stdout, _("Meta data for file `%s' (%s)\n"), fn, fs);
+    FPRINTF (stdout,
+             _("Meta data for file `%s' (%s)\n"),
+             fn,
+             fs);
     GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL);
-    FPRINTF (stdout, _("Keywords for file `%s' (%s)\n"), fn, fs);
+    FPRINTF (stdout,
+             _("Keywords for file `%s' (%s)\n"),
+             fn,
+             fs);
     GNUNET_free (fn);
     GNUNET_free (fs);
     if (NULL != *uri)
       GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL);
-    FPRINTF (stdout, "%s",  "\n");
+    FPRINTF (stdout,
+             "%s",
+             "\n");
   }
   if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m))
-    GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi);
+    GNUNET_FS_file_information_inspect (fi,
+                                        &publish_inspector, fi);
   return GNUNET_OK;
 }
 
@@ -475,13 +468,12 @@
 {
   if (NULL != emsg)
   {
-    FPRINTF (stderr, "%s\n", emsg);
+    FPRINTF (stderr,
+             "%s\n",
+             emsg);
     ret = 1;
   }
-  GNUNET_FS_uri_destroy (uri);
-  uri = NULL;
-  GNUNET_FS_stop (ctx);
-  ctx = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -503,21 +495,26 @@
 
   if (NULL != emsg)
   {
-    FPRINTF (stderr, "%s\n", emsg);
+    FPRINTF (stderr,
+             "%s\n",
+             emsg);
     ret = 1;
   }
   if (NULL != namespace)
   {
     priv = GNUNET_IDENTITY_ego_get_private_key (namespace);
-    GNUNET_FS_publish_sks (ctx, priv, this_id, next_id, meta, uri, &bo,
+    GNUNET_FS_publish_sks (ctx,
+                           priv,
+                           this_id,
+                           next_id,
+                           meta,
+                           uri,
+                           &bo,
                           GNUNET_FS_PUBLISH_OPTION_NONE,
                           &uri_sks_continuation, NULL);
     return;
   }
-  GNUNET_FS_uri_destroy (uri);
-  uri = NULL;
-  GNUNET_FS_stop (ctx);
-  ctx = NULL;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -592,8 +589,8 @@
     FPRINTF (stderr,
              "%s",
              _("Could not publish\n"));
+    ret = 1;
     GNUNET_SCHEDULER_shutdown ();
-    ret = 1;
     return;
   }
   GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL);
@@ -617,8 +614,8 @@
     FPRINTF (stderr,
              "%s",
              _("Could not start publishing.\n"));
+    ret = 1;
     GNUNET_SCHEDULER_shutdown ();
-    ret = 1;
     return;
   }
 }
@@ -689,12 +686,8 @@
     FPRINTF (stdout,
              "%s",
              _("Internal error scanning directory.\n"));
-    if (kill_task != NULL)
-    {
-      GNUNET_SCHEDULER_cancel (kill_task);
-      kill_task = NULL;
-    }
-    kill_task = GNUNET_SCHEDULER_add_now (&stop_scanner_task, NULL);
+    ret = 1;
+    GNUNET_SCHEDULER_shutdown ();
     break;
   default:
     GNUNET_assert (0);
@@ -722,6 +715,7 @@
     FPRINTF (stderr,
              _("Selected pseudonym `%s' unknown\n"),
              pseudonym);
+    ret = 1;
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
@@ -734,8 +728,8 @@
                _("Failed to parse URI: %s\n"),
                emsg);
       GNUNET_free (emsg);
+      ret = 1;
       GNUNET_SCHEDULER_shutdown ();
-      ret = 1;
       return;
     }
     GNUNET_FS_publish_ksk (ctx, topKeywords,
@@ -880,10 +874,9 @@
     ret = 1;
     return;
   }
-  kill_task =
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                  &do_stop_task,
-                                  NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                &do_stop_task,
+                                NULL);
   if (NULL != pseudonym)
     identity = GNUNET_IDENTITY_connect (cfg,
                                        &identity_cb,




reply via email to

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