aboutsummaryrefslogtreecommitdiff
path: root/lib/helper.c
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-02 11:30:43 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-02 13:56:40 -0700
commit5698ee09cf7a8495da70659ffae1eaec9f57db27 (patch)
tree798a58a4f49d7f82e3f948463daad4405173483e /lib/helper.c
parentf164e9b8ca319dd1279384ff495b5fa91e778d9e (diff)
Turn struct fuse_chan into an implementation detail
The only struct fuse_chan that's accessible to the user application is the "master" channel that is returned by fuse_mount and stored in struct fuse_session. When using the multi-threaded main loop with the "clone_fd" option, each worker thread gets its own struct fuse_chan. However, none of these are available to the user application, nor do they hold references to struct fuse_session (the pointer is always null). Therefore, any presence of struct fuse_chan can be removed without loss of functionality by relying on struct fuse_session instead. This reduces the number of API functions and removes a potential source of confusion (since the new API no longer looks as if it might be possible to add multiple channels to one session, or to share one channel between multiple sessions). Fixes issue #17.
Diffstat (limited to 'lib/helper.c')
-rw-r--r--lib/helper.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/lib/helper.c b/lib/helper.c
index cd1a54b..7ee767b 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -227,30 +227,32 @@ int fuse_daemonize(int foreground)
return 0;
}
+
static struct fuse *fuse_setup(int argc, char *argv[],
- const struct fuse_operations *op, size_t op_size,
- char **mountpoint, int *multithreaded, void *user_data)
+ const struct fuse_operations *op, size_t op_size,
+ int *multithreaded, void *user_data)
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
- struct fuse_chan *ch;
struct fuse *fuse;
+ char *mountpoint;
int foreground;
int res;
- res = fuse_parse_cmdline(&args, mountpoint, multithreaded, &foreground);
+ res = fuse_parse_cmdline(&args, &mountpoint, multithreaded, &foreground);
if (res == -1)
return NULL;
- ch = fuse_mount(*mountpoint, &args);
- if (!ch) {
+ fuse = fuse_new(&args, op, op_size, user_data);
+ if (fuse == NULL) {
fuse_opt_free_args(&args);
- goto err_free;
+ free(mountpoint);
+ return NULL;
}
- fuse = fuse_new(ch, &args, op, op_size, user_data);
- fuse_opt_free_args(&args);
- if (fuse == NULL)
- goto err_unmount;
+ res = fuse_mount(fuse, mountpoint);
+ free(mountpoint);
+ if (res != 0)
+ goto err_out1;
res = fuse_daemonize(foreground);
if (res == -1)
@@ -263,33 +265,29 @@ static struct fuse *fuse_setup(int argc, char *argv[],
return fuse;
err_unmount:
- fuse_unmount(*mountpoint, ch);
- if (fuse)
- fuse_destroy(fuse);
-err_free:
- free(*mountpoint);
+ fuse_unmount(fuse);
+err_out1:
+ fuse_destroy(fuse);
+ fuse_opt_free_args(&args);
return NULL;
}
-static void fuse_teardown(struct fuse *fuse, char *mountpoint)
+static void fuse_teardown(struct fuse *fuse)
{
struct fuse_session *se = fuse_get_session(fuse);
- struct fuse_chan *ch = fuse_session_chan(se);
fuse_remove_signal_handlers(se);
- fuse_unmount(mountpoint, ch);
+ fuse_unmount(fuse);
fuse_destroy(fuse);
- free(mountpoint);
}
int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
size_t op_size, void *user_data)
{
struct fuse *fuse;
- char *mountpoint;
int multithreaded;
int res;
- fuse = fuse_setup(argc, argv, op, op_size, &mountpoint,
+ fuse = fuse_setup(argc, argv, op, op_size,
&multithreaded, user_data);
if (fuse == NULL)
return 1;
@@ -299,7 +297,7 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
else
res = fuse_loop(fuse);
- fuse_teardown(fuse, mountpoint);
+ fuse_teardown(fuse);
if (res == -1)
return 1;