gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36250 - in gnunet/src: fs include


From: gnunet
Subject: [GNUnet-SVN] r36250 - in gnunet/src: fs include
Date: Tue, 18 Aug 2015 19:51:07 +0200

Author: grothoff
Date: 2015-08-18 19:51:07 +0200 (Tue, 18 Aug 2015)
New Revision: 36250

Modified:
   gnunet/src/fs/gnunet-auto-share.c
   gnunet/src/include/gnunet_strings_lib.h
Log:
adding some assertions to ensure we only start one gnunet-publish

Modified: gnunet/src/fs/gnunet-auto-share.c
===================================================================
--- gnunet/src/fs/gnunet-auto-share.c   2015-08-17 20:36:05 UTC (rev 36249)
+++ gnunet/src/fs/gnunet-auto-share.c   2015-08-18 17:51:07 UTC (rev 36250)
@@ -97,12 +97,12 @@
 /**
  * Handle for the 'shutdown' task.
  */
-static struct GNUNET_SCHEDULER_Task * kill_task;
+static struct GNUNET_SCHEDULER_Task *kill_task;
 
 /**
  * Handle for the main task that does scanning and working.
  */
-static struct GNUNET_SCHEDULER_Task * run_task;
+static struct GNUNET_SCHEDULER_Task *run_task;
 
 /**
  * Anonymity level option to use for publishing.
@@ -135,13 +135,13 @@
 static struct WorkItem *work_tail;
 
 /**
- * Map from the hash of the filename (!) to a 'struct WorkItem'
+ * Map from the hash of the filename (!) to a `struct WorkItem`
  * that was finished.
  */
 static struct GNUNET_CONTAINER_MultiHashMap *work_finished;
 
 /**
- * Set to GNUNET_YES if we are shutting down.
+ * Set to #GNUNET_YES if we are shutting down.
  */
 static int do_shutdown;
 
@@ -180,7 +180,7 @@
 
 
 /**
- * Load the set of 'work_finished' items from disk.
+ * Load the set of #work_finished items from disk.
  */
 static void
 load_state ()
@@ -241,12 +241,12 @@
 
 
 /**
- * Write work item from the work_finished map to the given write handle.
+ * Write work item from the #work_finished map to the given write handle.
  *
- * @param cls the 'struct GNUNET_BIO_WriteHandle*'
+ * @param cls the `struct GNUNET_BIO_WriteHandle *`
  * @param key key of the item in the map (unused)
- * @param value the 'struct WorkItem' to write
- * @return GNUNET_OK to continue to iterate (if write worked)
+ * @param value the `struct WorkItem` to write
+ * @return #GNUNET_OK to continue to iterate (if write worked)
  */
 static int
 write_item (void *cls,
@@ -272,7 +272,7 @@
 
 
 /**
- * Save the set of 'work_finished' items on disk.
+ * Save the set of #work_finished items on disk.
  */
 static void
 save_state ()
@@ -320,13 +320,15 @@
  * @param tc scheduler context, unused
  */
 static void
-do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_stop_task (void *cls, 
+             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   kill_task = NULL;
   do_shutdown = GNUNET_YES;
   if (NULL != publish_proc)
   {
-    GNUNET_OS_process_kill (publish_proc, SIGKILL);
+    GNUNET_OS_process_kill (publish_proc, 
+                           SIGKILL);
     return;
   }
   if (NULL != run_task)
@@ -348,11 +350,12 @@
  * Task triggered whenever we receive a SIGCHLD (child
  * process died).
  *
- * @param cls the 'struct WorkItem' we were working on
+ * @param cls the `struct WorkItem` we were working on
  * @param tc context
  */
 static void
-maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+maint_child_death (void *cls, 
+                  const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct WorkItem *wi = cls;
   struct GNUNET_HashCode key;
@@ -362,15 +365,17 @@
   char c;
   const struct GNUNET_DISK_FileHandle *pr;
 
-
   run_task = NULL;
-  pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+  pr = GNUNET_DISK_pipe_handle (sigpipe,
+                               GNUNET_DISK_PIPE_END_READ);
   if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
   {
-    /* shutdown scheduled us, ignore! */
+    /* shutdown scheduled us, someone else will kill child,
+       we should just try again */
     run_task =
       GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
-                                     pr, &maint_child_death, wi);
+                                     pr,
+                                     &maint_child_death, wi);
     return;
   }
 
@@ -380,10 +385,17 @@
   GNUNET_assert (GNUNET_SYSERR != ret);
   if (GNUNET_NO == ret)
   {
+    /* process still running? Well, how did we get here?
+       Anyway, answer is to kill it! */
     GNUNET_break (0);
-    GNUNET_OS_process_kill (publish_proc, SIGKILL);
-    type = GNUNET_OS_PROCESS_SIGNALED;
+    GNUNET_OS_process_kill (publish_proc, 
+                           SIGKILL);
+    ret = GNUNET_OS_process_status (publish_proc,
+                                   &type,
+                                   &code);
   }
+  GNUNET_assert (GNUNET_OK == ret);
+  
   GNUNET_OS_process_destroy (publish_proc);
   publish_proc = NULL;
   /* consume the signal */
@@ -433,7 +445,8 @@
 
   GNUNET_break (1 ==
                GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
-                                       (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
+                                       (sigpipe,
+                                        GNUNET_DISK_PIPE_END_WRITE),
                                        &c, sizeof (c)));
   errno = old_errno;           /* restore errno */
 }
@@ -489,6 +502,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              _("Publishing `%s'\n"),
              wi->filename);
+  GNUNET_assert (NULL == publish_proc);
   publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES,
                                               0, NULL, NULL, NULL,
                                              "gnunet-publish",
@@ -506,10 +520,12 @@
                                             NULL);
     return;
   }
-  pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+  pr = GNUNET_DISK_pipe_handle (sigpipe, 
+                               GNUNET_DISK_PIPE_END_READ);
   run_task =
     GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
-                                   pr, &maint_child_death, wi);
+                                   pr,
+                                   &maint_child_death, wi);
 }
 
 
@@ -519,7 +535,7 @@
  *
  * @param cls where to store the unique ID we are computing
  * @param filename file to scan
- * @return GNUNET_OK (always)
+ * @return #GNUNET_OK (always)
  */
 static int
 determine_id (void *cls,
@@ -532,10 +548,14 @@
 
   if (0 != STAT (filename, &sbuf))
   {
-    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "stat", filename);
+    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 
+                             "stat", 
+                             filename);
     return GNUNET_OK;
   }
-  GNUNET_CRYPTO_hash (filename, strlen (filename), &fx[0]);
+  GNUNET_CRYPTO_hash (filename, 
+                     strlen (filename), 
+                     &fx[0]);
   if (!S_ISDIR (sbuf.st_mode))
   {
     uint64_t fattr[2];
@@ -543,11 +563,15 @@
     fattr[0] = GNUNET_htonll (sbuf.st_size);
     fattr[0] = GNUNET_htonll (sbuf.st_mtime);
 
-    GNUNET_CRYPTO_hash (fattr, sizeof (fattr), &fx[1]);
+    GNUNET_CRYPTO_hash (fattr, 
+                       sizeof (fattr), 
+                       &fx[1]);
   }
   else
   {
-    memset (&fx[1], 1, sizeof (struct GNUNET_HashCode));
+    memset (&fx[1],
+           1,
+           sizeof (struct GNUNET_HashCode));
     GNUNET_DISK_directory_scan (filename,
                                &determine_id,
                                &fx[1]);
@@ -554,10 +578,14 @@
   }
   /* use hash here to make hierarchical structure distinct from
      all files on the same level */
-  GNUNET_CRYPTO_hash (fx, sizeof (fx), &ft);
+  GNUNET_CRYPTO_hash (fx, 
+                     sizeof (fx),
+                     &ft);
   /* use XOR here so that order of the files in the directory
      does not matter! */
-  GNUNET_CRYPTO_hash_xor (&ft, id, id);
+  GNUNET_CRYPTO_hash_xor (&ft,
+                         id,
+                         id);
   return GNUNET_OK;
 }
 
@@ -569,7 +597,7 @@
  *
  * @param cls closure, NULL
  * @param filename complete filename (absolute path)
- * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR during shutdown
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR during shutdown
  */
 static int
 add_file (void *cls,
@@ -627,7 +655,8 @@
  * @param tc scheduler context, unused
  */
 static void
-scan (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+scan (void *cls, 
+      const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   run_task = NULL;
   start_time = GNUNET_TIME_absolute_get ();
@@ -648,6 +677,7 @@
 
   if (GNUNET_YES == do_shutdown)
     return;
+  GNUNET_assert (NULL == run_task);
   if (NULL == work_head)
   {
     /* delay by at most 4h, at least 1s, and otherwise in between depending
@@ -664,7 +694,8 @@
   }
   else
   {
-    run_task = GNUNET_SCHEDULER_add_now (&work, NULL);
+    run_task = GNUNET_SCHEDULER_add_now (&work, 
+                                        NULL);
   }
 }
 
@@ -678,12 +709,17 @@
  * @param c configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls, 
+     char *const *args, 
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   /* check arguments */
-  if ((args[0] == NULL) || (args[1] != NULL) ||
-      (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES)))
+  if ( (NULL == args[0]) || 
+       (NULL != args[1]) ||
+       (GNUNET_YES != 
+       GNUNET_DISK_directory_test (args[0],
+                                   GNUNET_YES)) )
   {
     printf (_("You must specify one and only one directory name for automatic 
publication.\n"));
     ret = -1;
@@ -692,13 +728,15 @@
   cfg_filename = GNUNET_strdup (cfgfile);
   cfg = c;
   dir_name = args[0];
-  work_finished = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
+  work_finished = GNUNET_CONTAINER_multihashmap_create (1024, 
+                                                       GNUNET_NO);
   load_state ();
   run_task = GNUNET_SCHEDULER_add_with_priority 
(GNUNET_SCHEDULER_PRIORITY_IDLE,
-                                                &scan, NULL);
-
+                                                &scan, 
+                                                NULL);
   kill_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 
&do_stop_task,
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 
+                                   &do_stop_task,
                                     NULL);
 }
 
@@ -708,8 +746,8 @@
  *
  * @param cls NULL (unused)
  * @param key key of the item in the map (unused)
- * @param value the 'struct WorkItem' to free
- * @return GNUNET_OK to continue to iterate
+ * @param value the `struct WorkItem` to free
+ * @return #GNUNET_OK to continue to iterate
  */
 static int
 free_item (void *cls,
@@ -760,14 +798,18 @@
   int ok;
   struct GNUNET_SIGNAL_Context *shc_chld;
 
-  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+  if (GNUNET_OK != 
+      GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
-  sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO);
-  GNUNET_assert (sigpipe != NULL);
+  sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 
+                             GNUNET_NO, GNUNET_NO);
+  GNUNET_assert (NULL != sigpipe);
   shc_chld =
-    GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
+    GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD,
+                                  &sighandler_child_death);
   ok = (GNUNET_OK ==
-       GNUNET_PROGRAM_run (argc, argv, "gnunet-auto-share [OPTIONS] FILENAME",
+       GNUNET_PROGRAM_run (argc, argv, 
+                           "gnunet-auto-share [OPTIONS] FILENAME",
                            gettext_noop
                            ("Automatically publish files from a directory on 
GNUnet"),
                            options, &run, NULL)) ? ret : 1;
@@ -780,7 +822,9 @@
   }
   while (NULL != (wi = work_head))
   {
-    GNUNET_CONTAINER_DLL_remove (work_head, work_tail, wi);
+    GNUNET_CONTAINER_DLL_remove (work_head, 
+                                work_tail,
+                                wi);
     GNUNET_free (wi->filename);
     GNUNET_free (wi);
   }

Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h     2015-08-17 20:36:05 UTC (rev 
36249)
+++ gnunet/src/include/gnunet_strings_lib.h     2015-08-18 17:51:07 UTC (rev 
36250)
@@ -302,8 +302,8 @@
  * The returned string will be freshly allocated, and must be free'd
  * with #GNUNET_free().
  *
- * @param buffer with data
- * @param size size of the buffer
+ * @param buf buffer with data
+ * @param size size of the buffer @a buf
  * @return freshly allocated, null-terminated string
  */
 char *




reply via email to

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