The -d option prevents fuse clients from detaching from the terminal and
running in the background. This is of course useful when debugging. The
following patch adds support for this option and also ensures that the
FUSE_DEBUG environment variable turns on debug output for clients that
don't call fuse_parse_cmdline.
Tested on amd64 with ntfs-3g, sshfs and fuse-exfat.
Index: libfuse/fuse.c
===================================================================
RCS file: /cvs/src/lib/libfuse/fuse.c,v
retrieving revision 1.24
diff -u -p -r1.24 fuse.c
--- libfuse/fuse.c 20 May 2014 13:32:22 -0000 1.24
+++ libfuse/fuse.c 14 Dec 2014 22:45:40 -0000
@@ -40,6 +40,7 @@ enum {
KEY_HELP_WITHOUT_HEADER,
KEY_VERSION,
KEY_MAXREAD,
+ KEY_FOREGROUND,
KEY_STUB
};
@@ -51,7 +52,7 @@ static struct fuse_opt fuse_core_opts[]
FUSE_OPT_KEY("--version", KEY_VERSION),
FUSE_OPT_KEY("max_read=", KEY_MAXREAD),
FUSE_OPT_KEY("debug", KEY_STUB),
- FUSE_OPT_KEY("-d", KEY_STUB),
+ FUSE_OPT_KEY("-d", KEY_FOREGROUND),
FUSE_OPT_KEY("-f", KEY_STUB),
FUSE_OPT_KEY("-s", KEY_STUB),
FUSE_OPT_KEY("use_ino", KEY_STUB),
@@ -264,8 +265,11 @@ fuse_new(struct fuse_chan *fc, unused st
}
int
-fuse_daemonize(unused int foreground)
+fuse_daemonize(int foreground)
{
+ if (foreground)
+ return 0;
+
#ifdef DEBUG
return (daemon(0,1));
#else
@@ -370,6 +374,9 @@ ifuse_process_opt(void *data, const char
}
max_read = res;
break;
+ case KEY_FOREGROUND:
+ opt->foreground = 1;
+ break;
case FUSE_OPT_KEY_NONOPT:
if (opt->mp == NULL) {
opt->mp = realpath(arg, opt->mp);
@@ -406,7 +413,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;
@@ -424,6 +431,7 @@ fuse_parse_cmdline(struct fuse_args *arg
*mp = strdup(opt.mp);
*mt = 0;
+ *fg = opt.foreground;
return (0);
}
Index: libfuse/fuse_opt.c
===================================================================
RCS file: /cvs/src/lib/libfuse/fuse_opt.c,v
retrieving revision 1.11
diff -u -p -r1.11 fuse_opt.c
--- libfuse/fuse_opt.c 8 Oct 2014 04:50:10 -0000 1.11
+++ libfuse/fuse_opt.c 14 Dec 2014 22:45:40 -0000
@@ -334,6 +334,9 @@ fuse_opt_insert_arg(struct fuse_args *ar
char *this_arg, *next_arg;
int i;
+#ifdef DEBUG
+ ifuse_debug_init();
+#endif
if (name == NULL)
return (-1);
Index: libfuse/fuse_private.h
===================================================================
RCS file: /cvs/src/lib/libfuse/fuse_private.h,v
retrieving revision 1.10
diff -u -p -r1.10 fuse_private.h
--- libfuse/fuse_private.h 28 Apr 2014 13:08:34 -0000 1.10
+++ libfuse/fuse_private.h 14 Dec 2014 22:45:40 -0000
@@ -72,6 +72,7 @@ struct fuse_config {
struct fuse_core_opt {
char *mp;
+ int foreground;
};
struct fuse {