aboutsummaryrefslogtreecommitdiff
path: root/example/hello_ll.c
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-02 20:52:33 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-02 21:09:37 -0700
commit425db842ff1155fcd3b40439fcd88248d45a5db7 (patch)
tree96615a1328c7a19b9c8c4c18d42fd6464cebe7f2 /example/hello_ll.c
parenta10ee045e76cec75f9d8c08f78f0acc994302305 (diff)
Don't handle --help and --version in fuse_session_new().
Help and version messages can be generated using the new fuse_lowlevel_help(), fuse_lowlevel_version(), fuse_mount_help(), and fuse_mount_version() functions. The fuse_parse_cmdline() function has been made more powerful to do this automatically, and is now explicitly intended only for low-level API users. This is a code simplication patch. We don't have to parse for --help and --version in quite as many places, and we no longer have a low-level initialization function be responsible for the (super-high level) task of printing a program usage message. In the high-level API, we can now handle the command line parsing earlier and avoid running other initialization code if we're just going to abort later on.
Diffstat (limited to 'example/hello_ll.c')
-rw-r--r--example/hello_ll.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/example/hello_ll.c b/example/hello_ll.c
index 07529d1..b7e77cd 100644
--- a/example/hello_ll.c
+++ b/example/hello_ll.c
@@ -187,35 +187,45 @@ int main(int argc, char *argv[])
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
struct fuse_session *se;
- char *mountpoint;
- int err = -1;
-
- if (fuse_parse_cmdline(&args, &mountpoint, NULL, NULL) != 0)
- goto err_out;
+ struct fuse_cmdline_opts opts;
+ int ret = -1;
+
+ if (fuse_parse_cmdline(&args, &opts) != 0)
+ return 1;
+ if (opts.show_help || opts.show_version) {
+ ret = 1;
+ goto err_out1;
+ }
+ if (!opts.foreground)
+ fprintf(stderr, "Warning: background operation "
+ "is not supported\n");
+ if (!opts.singlethread)
+ fprintf(stderr, "Warning: multithreading is not "
+ "supported\n");
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)
+ if (fuse_set_signal_handlers(se) != 0)
goto err_out2;
+ if (fuse_session_mount(se, opts.mountpoint) != 0)
+ goto err_out3;
+
/* Block until ctrl+c or fusermount -u */
- err = fuse_session_loop(se);
+ ret = fuse_session_loop(se);
fuse_session_unmount(se);
-err_out2:
+err_out3:
fuse_remove_signal_handlers(se);
-err_out1:
+err_out2:
fuse_session_destroy(se);
-err_out:
- free(mountpoint);
+err_out1:
+ free(opts.mountpoint);
+ fuse_opt_free_args(&args);
- return err ? 1 : 0;
+ return ret ? 1 : 0;
}
/*! [doxygen_fuse_lowlevel_usage] */