From 425db842ff1155fcd3b40439fcd88248d45a5db7 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Sun, 2 Oct 2016 20:52:33 -0700 Subject: 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. --- example/hello_ll.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'example/hello_ll.c') 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] */ -- cgit v1.2.3