aboutsummaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorNikolaus Rath <Nikolaus@rath.org>2016-10-02 11:30:43 -0700
committerNikolaus Rath <Nikolaus@rath.org>2016-10-02 13:56:40 -0700
commit5698ee09cf7a8495da70659ffae1eaec9f57db27 (patch)
tree798a58a4f49d7f82e3f948463daad4405173483e /example
parentf164e9b8ca319dd1279384ff495b5fa91e778d9e (diff)
downloadlibfuse-5698ee09cf7a8495da70659ffae1eaec9f57db27.tar.gz
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 'example')
-rw-r--r--example/fuse_lo-plus.c40
-rwxr-xr-xexample/hello_ll.c46
2 files changed, 48 insertions, 38 deletions
diff --git a/example/fuse_lo-plus.c b/example/fuse_lo-plus.c
index e79c727..4171d3e 100644
--- a/example/fuse_lo-plus.c
+++ b/example/fuse_lo-plus.c
@@ -455,7 +455,7 @@ static const struct fuse_opt lo_opts[] = {
int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
- struct fuse_chan *ch;
+ struct fuse_session *se;
char *mountpoint;
int ret = -1;
struct lo_data lo = { .debug = 0 };
@@ -468,23 +468,29 @@ int main(int argc, char *argv[])
if (lo.root.fd == -1)
err(1, "open(\"/\", O_PATH)");
- if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 &&
- (ch = fuse_session_mount(mountpoint, &args)) != NULL) {
- struct fuse_session *se;
- se = fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo);
- if (se != NULL) {
- if (fuse_set_signal_handlers(se) != -1) {
- fuse_session_add_chan(se, ch);
- ret = fuse_session_loop(se);
- fuse_remove_signal_handlers(se);
- fuse_session_remove_chan(ch);
- }
- fuse_session_destroy(se);
- }
- fuse_session_unmount(mountpoint, ch);
- free(mountpoint);
- }
+ if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != 0)
+ goto err_out;
+
+ se = fuse_session_new(&args, &lo_oper, sizeof(lo_oper), &lo);
fuse_opt_free_args(&args);
+ if (se == NULL)
+ goto err_out;
+
+ if (fuse_set_signal_handlers(se) != 0)
+ goto err_out1;
+
+ if (fuse_session_mount(se, mountpoint) != 0)
+ goto err_out2;
+
+ ret = fuse_session_loop(se);
+
+ fuse_session_unmount(se);
+err_out2:
+ fuse_remove_signal_handlers(se);
+err_out1:
+ fuse_session_destroy(se);
+err_out:
+ free(mountpoint);
while (lo.root.next != &lo.root)
lo_free(lo.root.next);
diff --git a/example/hello_ll.c b/example/hello_ll.c
index 528b216..07529d1 100755
--- a/example/hello_ll.c
+++ b/example/hello_ll.c
@@ -186,31 +186,35 @@ static struct fuse_lowlevel_ops hello_ll_oper = {
int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
- struct fuse_chan *ch;
+ struct fuse_session *se;
char *mountpoint;
int err = -1;
- if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != -1 &&
- (ch = fuse_session_mount(mountpoint, &args)) != NULL) {
- struct fuse_session *se;
-
- se = fuse_session_new(&args, &hello_ll_oper,
- sizeof(hello_ll_oper), NULL);
- if (se != NULL) {
- if (fuse_set_signal_handlers(se) != -1) {
- fuse_session_add_chan(se, ch);
-
- /* Block until ctrl+c or fusermount -u */
- err = fuse_session_loop(se);
-
- fuse_remove_signal_handlers(se);
- fuse_session_remove_chan(ch);
- }
- fuse_session_destroy(se);
- }
- fuse_session_unmount(mountpoint, ch);
- }
+ if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != 0)
+ goto err_out;
+
+ se = fuse_session_new(&args, &hello_ll_oper,
+ sizeof(hello_ll_oper), NULL);
fuse_opt_free_args(&args);
+ if (se == NULL)
+ goto err_out;
+
+ if (fuse_set_signal_handlers(se) != 0)
+ goto err_out1;
+
+ if (fuse_session_mount(se, mountpoint) != 0)
+ goto err_out2;
+
+ /* Block until ctrl+c or fusermount -u */
+ err = fuse_session_loop(se);
+
+ fuse_session_unmount(se);
+err_out2:
+ fuse_remove_signal_handlers(se);
+err_out1:
+ fuse_session_destroy(se);
+err_out:
+ free(mountpoint);
return err ? 1 : 0;
}