diff options
author | Nikolaus Rath <Nikolaus@rath.org> | 2017-08-03 17:19:22 +0200 |
---|---|---|
committer | Nikolaus Rath <Nikolaus@rath.org> | 2017-08-03 17:21:06 +0200 |
commit | 5459e87fe6515c421186851c1e71773154bcd7e2 (patch) | |
tree | c990990c62118c4836af7475471423c0b88b9710 /lib | |
parent | cbf19044da93e550b559639271c56f5c17c2172f (diff) |
Simplify and fix FreeBSD fsname handling
This should simplify the code a lot. It also corrects a bug in
that the (former) add_default_fsname() function actually set
the -osubtype option.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helper.c | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/lib/helper.c b/lib/helper.c index c562c43..9abc6dd 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -41,14 +41,10 @@ static const struct fuse_opt fuse_helper_opts[] = { FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP), FUSE_HELPER_OPT("-f", foreground), FUSE_HELPER_OPT("-s", singlethread), -#ifdef __FreeBSD__ - FUSE_HELPER_OPT("fsname=", fsname), -#else FUSE_HELPER_OPT("fsname=", nodefault_subtype), - FUSE_HELPER_OPT("subtype=", nodefault_subtype), -#endif FUSE_OPT_KEY("fsname=", FUSE_OPT_KEY_KEEP), #ifndef __FreeBSD__ + FUSE_HELPER_OPT("subtype=", nodefault_subtype), FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_KEEP), #endif FUSE_HELPER_OPT("clone_fd", clone_fd), @@ -167,43 +163,31 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key, } } -#ifdef __FreeBSD__ -static int add_default_fsname(const char *progname, struct fuse_args *args) -#else +/* Under FreeBSD, there is no subtype option so this + function actually sets the fsname */ static int add_default_subtype(const char *progname, struct fuse_args *args) -#endif { int res; -#ifdef __FreeBSD__ - char *fsname_opt; -#else char *subtype_opt; -#endif + const char *basename = strrchr(progname, '/'); if (basename == NULL) basename = progname; else if (basename[1] != '\0') basename++; -#ifdef __FreeBSD__ - fsname_opt = (char *) malloc(strlen(basename) + 64); - if (fsname_opt == NULL) { -#else subtype_opt = (char *) malloc(strlen(basename) + 64); if (subtype_opt == NULL) { -#endif fprintf(stderr, "fuse: memory allocation failed\n"); return -1; } #ifdef __FreeBSD__ - sprintf(fsname_opt, "-osubtype=%s", basename); - res = fuse_opt_add_arg(args, fsname_opt); - free(fsname_opt); + sprintf(subtype_opt, "-ofsname=%s", basename); #else sprintf(subtype_opt, "-osubtype=%s", basename); +#endif res = fuse_opt_add_arg(args, subtype_opt); free(subtype_opt); -#endif return res; } @@ -215,15 +199,12 @@ int fuse_parse_cmdline(struct fuse_args *args, fuse_helper_opt_proc) == -1) return -1; - /* If neither -o subtype nor -o fsname are specified, - set subtype to program's basename */ -#ifdef __FreeBSD__ - if (!opts->fsname) - if (add_default_fsname(args->argv[0], args) == -1) -#else + /* *Linux*: if neither -o subtype nor -o fsname are specified, + set subtype to program's basename. + *FreeBSD*: if fsname is not specified, set to program's + basename. */ if (!opts->nodefault_subtype) if (add_default_subtype(args->argv[0], args) == -1) -#endif return -1; return 0; |