gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r21756 - gnunet-fuse/src/fuse


From: gnunet
Subject: [GNUnet-SVN] r21756 - gnunet-fuse/src/fuse
Date: Mon, 4 Jun 2012 15:24:43 +0200

Author: grothoff
Date: 2012-06-04 15:24:43 +0200 (Mon, 04 Jun 2012)
New Revision: 21756

Modified:
   gnunet-fuse/src/fuse/gfs_download.c
Log:
-fixes

Modified: gnunet-fuse/src/fuse/gfs_download.c
===================================================================
--- gnunet-fuse/src/fuse/gfs_download.c 2012-06-04 13:03:36 UTC (rev 21755)
+++ gnunet-fuse/src/fuse/gfs_download.c 2012-06-04 13:24:43 UTC (rev 21756)
@@ -25,21 +25,40 @@
 #include "gfs_download.h"
 
 
+/**
+ * Context for a download operation.
+ */
 struct Context
 {
 
+  /**
+   * Information about the file we are downloading.
+   */
   struct GNUNET_FUSE_PathInfo *path_info;
 
+  /**
+   * Download handle.
+   */
   struct GNUNET_FS_DownloadContext *dc;
 
+  /**
+   * FS handle.
+   */
   struct GNUNET_FS_Handle *fs;
 
-  char *emsg;
-
+  /**
+   * Start offset.
+   */
   off_t start_offset;
 
+  /**
+   * Number of bytes to download.
+   */
   uint64_t length;
 
+  /**
+   * Return value for the operation, 0 on success.
+   */
   int ret;
 
 };
@@ -47,6 +66,9 @@
 
 /**
  * Task run when we shut down.
+ *
+ * @param cls our 'struct Context'
+ * @param tc scheduler context (unused)
  */
 static void
 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -189,10 +211,14 @@
   int status;
   int ret;
 
+  /* lock to prevent two processes from downloading / manipulating the
+     same file at the same time */
+  GNUNET_mutex_lock (path_info->lock);
   pid = fork ();
   if (-1 == pid)
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
+    GNUNET_mutex_unlock (path_info->lock);
     return GNUNET_SYSERR;
   }
   if (0 != pid)
@@ -204,8 +230,10 @@
       GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "waitpid");
       (void) kill (pid, SIGKILL);
       (void) waitpid (pid, &status, 0);
+      GNUNET_mutex_unlock (path_info->lock);
       return GNUNET_SYSERR;
     }
+    GNUNET_mutex_unlock (path_info->lock);
     if ( (WIFEXITED (status)) &&
         (0 == WEXITSTATUS (status)) )
       return GNUNET_OK;
@@ -217,7 +245,7 @@
   ctx.start_offset = start_offset;
   ctx.length = length;
   GNUNET_SCHEDULER_run (&download_task, &ctx);
-  _exit (ret);
+  _exit (ctx.ret);
 }
 
-/* end of fs_download.c */
+/* end of gfs_download.c */




reply via email to

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