This patch adds support for the -f option, which forces the FUSE file system to run in the foreground. This is useful for debugging and adds a missing feature to the library.
ok? Index: fuse.c =================================================================== RCS file: /cvs/src/lib/libfuse/fuse.c,v retrieving revision 1.35 diff -u -p -u -p -r1.35 fuse.c --- fuse.c 17 Nov 2017 15:56:12 -0000 1.35 +++ fuse.c 26 Nov 2017 08:27:39 -0000 @@ -37,6 +37,7 @@ static struct fuse_context *ictx = NULL; static int max_read = FUSEBUFMAXSIZE; enum { + KEY_FOREGROUND, KEY_HELP, KEY_HELP_WITHOUT_HEADER, KEY_VERSION, @@ -53,7 +54,7 @@ static struct fuse_opt fuse_core_opts[] FUSE_OPT_KEY("max_read=", KEY_MAXREAD), FUSE_OPT_KEY("debug", KEY_STUB), FUSE_OPT_KEY("-d", KEY_STUB), - FUSE_OPT_KEY("-f", KEY_STUB), + FUSE_OPT_KEY("-f", KEY_FOREGROUND), FUSE_OPT_KEY("-s", KEY_STUB), FUSE_OPT_KEY("use_ino", KEY_STUB), FUSE_OPT_KEY("big_writes", KEY_STUB), @@ -342,13 +343,12 @@ fuse_new(struct fuse_chan *fc, unused st } int -fuse_daemonize(unused int foreground) +fuse_daemonize(int foreground) { -#ifdef DEBUG - return (daemon(0,1)); -#else + if (foreground) + return (0); + return (daemon(0,0)); -#endif } void @@ -387,6 +387,7 @@ dump_help(void) { fprintf(stderr, "FUSE options:\n" " -d -o debug enable debug output (implies -f)\n" + " -f run in foreground\n" " -V print fuse version\n" "\n"); } @@ -409,6 +410,9 @@ ifuse_process_opt(void *data, const char switch (key) { case KEY_STUB: return (0); + case KEY_FOREGROUND: + opt->foreground = 1; + return (0); case KEY_HELP: case KEY_HELP_WITHOUT_HEADER: dump_help(); @@ -460,7 +464,7 @@ ifuse_process_opt(void *data, const char } int -fuse_parse_cmdline(struct fuse_args *args, char **mp, int *mt, unused int *fg) +fuse_parse_cmdline(struct fuse_args *args, char **mp, int *mt, int *fg) { struct fuse_core_opt opt; @@ -485,6 +489,9 @@ fuse_parse_cmdline(struct fuse_args *arg if (mt != NULL) *mt = 0; + if (fg != NULL) + *fg = opt.foreground; + return (0); } @@ -530,7 +537,7 @@ fuse_setup(int argc, char **argv, const if (fuse_parse_cmdline(&args, &dir, mt, &fg)) goto err; - fuse_daemonize(0); + fuse_daemonize(fg); if ((fc = fuse_mount(dir, NULL)) == NULL) goto err; Index: fuse_private.h =================================================================== RCS file: /cvs/src/lib/libfuse/fuse_private.h,v retrieving revision 1.14 diff -u -p -u -p -r1.14 fuse_private.h --- fuse_private.h 7 Sep 2016 17:53:35 -0000 1.14 +++ fuse_private.h 26 Nov 2017 08:27:39 -0000 @@ -74,7 +74,8 @@ struct fuse_config { }; struct fuse_core_opt { - char *mp; + char *mp; + int foreground; }; struct fuse {