gnunet-fuse

GNUnet file-sharing directory mounting via FUSE
Log | Files | Refs | Submodules | README | LICENSE

commit fa70db10422acfea0368b664acde9e735206dde7
parent c2327e49d957b9579de5b2cf8c51027df8eedaac
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  4 Jun 2012 13:24:43 +0000

-fixes

Diffstat:
Msrc/fuse/gfs_download.c | 36++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/src/fuse/gfs_download.c b/src/fuse/gfs_download.c @@ -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 @@ struct Context /** * 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 @@ GNUNET_FUSE_download_file (struct GNUNET_FUSE_PathInfo *path_info, 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_FUSE_download_file (struct GNUNET_FUSE_PathInfo *path_info, 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 @@ GNUNET_FUSE_download_file (struct GNUNET_FUSE_PathInfo *path_info, 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 */