diff options
author | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-02 20:52:33 -0700 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2016-10-02 21:09:37 -0700 |
commit | 425db842ff1155fcd3b40439fcd88248d45a5db7 (patch) | |
tree | 96615a1328c7a19b9c8c4c18d42fd6464cebe7f2 /lib/fuse.c | |
parent | a10ee045e76cec75f9d8c08f78f0acc994302305 (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 'lib/fuse.c')
-rw-r--r-- | lib/fuse.c | 74 |
1 files changed, 34 insertions, 40 deletions
@@ -77,7 +77,7 @@ struct fuse_config { int auto_cache; int intr; int intr_signal; - int help; + int show_help; char *modules; }; @@ -4410,15 +4410,11 @@ int fuse_interrupted(void) return 0; } -enum { - KEY_HELP, -}; - #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } static const struct fuse_opt fuse_lib_opts[] = { - FUSE_OPT_KEY("-h", KEY_HELP), - FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_LIB_OPT("-h", show_help, 1), + FUSE_LIB_OPT("--help", show_help, 1), FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP), FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP), FUSE_LIB_OPT("debug", debug, 1), @@ -4499,14 +4495,9 @@ static void fuse_lib_help_modules(void) static int fuse_lib_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { - (void) arg; (void) outargs; - - if (key == KEY_HELP) { - struct fuse_config *conf = (struct fuse_config *) data; - fuse_lib_help(); - conf->help = 1; - } + (void) arg; (void) outargs; (void) data; (void) key; + /* Pass through unknown options */ return 1; } @@ -4641,6 +4632,25 @@ struct fuse *fuse_new(struct fuse_args *args, struct fuse_fs *fs; struct fuse_lowlevel_ops llop = fuse_path_ops; + f = (struct fuse *) calloc(1, sizeof(struct fuse)); + if (f == NULL) { + fprintf(stderr, "fuse: failed to allocate fuse object\n"); + goto out; + } + + /* Parse options */ + if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, + fuse_lib_opt_proc) == -1) + goto out_free; + + if (f->conf.show_help) { + fuse_lib_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + /* Defer printing module help until modules + have been loaded */ + } + pthread_mutex_lock(&fuse_context_lock); static int builtin_modules_registered = 0; /* Have the builtin modules already been registered? */ @@ -4652,19 +4662,12 @@ struct fuse *fuse_new(struct fuse_args *args, } pthread_mutex_unlock(&fuse_context_lock); - if (fuse_create_context_key() == -1) - goto out; - - f = (struct fuse *) calloc(1, sizeof(struct fuse)); - if (f == NULL) { - fprintf(stderr, "fuse: failed to allocate fuse object\n"); - goto out_delete_context_key; - } + goto out_free; fs = fuse_fs_new(op, op_size, user_data); if (!fs) - goto out_free; + goto out_delete_context_key; f->fs = fs; f->conf.nopath = fs->op.flag_nopath; @@ -4685,13 +4688,6 @@ struct fuse *fuse_new(struct fuse_args *args, init_list_head(&f->full_slabs); init_list_head(&f->lru_table); - /* When --help or --version are specified, we print messages - to stderr but continue for now (and keep the arguments in - `args` for use below */ - if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, - fuse_lib_opt_proc) == -1) - goto out_free_fs; - if (f->conf.modules) { char *module; char *next; @@ -4707,6 +4703,11 @@ struct fuse *fuse_new(struct fuse_args *args, } } + if(f->conf.show_help) { + fuse_lib_help_modules(); + goto out_free_fs; + } + if (!f->conf.ac_attr_timeout_set) f->conf.ac_attr_timeout = f->conf.attr_timeout; @@ -4718,16 +4719,9 @@ struct fuse *fuse_new(struct fuse_args *args, f->conf.readdir_ino = 1; #endif - /* This function will return NULL if there is an --help - or --version argument in `args` */ f->se = fuse_session_new(args, &llop, sizeof(llop), f); - if (f->se == NULL) { - /* If we've printed help before, add module help at - * the end */ - if (f->conf.help) - fuse_lib_help_modules(); + if (f->se == NULL) goto out_free_fs; - } if (f->conf.debug) { fprintf(stderr, "nopath: %i\n", f->conf.nopath); @@ -4783,10 +4777,10 @@ out_free_fs: fuse_put_module(f->fs->m); free(f->fs); free(f->conf.modules); -out_free: - free(f); out_delete_context_key: fuse_delete_context_key(); +out_free: + free(f); out: return NULL; } |