From 193de363019bb801581407ac12ec81982cf75d77 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Fri, 10 Mar 2017 21:57:27 -0800 Subject: [PATCH] dll: fuse: debug output goes to stderr; configurable with -oDebugLog=FILE --- doc/WinFsp-Tutorial.asciidoc | 4 ++-- src/dll/fuse/fuse.c | 26 ++++++++++++++++++++++++++ tst/memfs/memfs-main.c | 4 ++-- tst/passthrough/passthrough.c | 4 ++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/doc/WinFsp-Tutorial.asciidoc b/doc/WinFsp-Tutorial.asciidoc index 18471969..7aff8967 100644 --- a/doc/WinFsp-Tutorial.asciidoc +++ b/doc/WinFsp-Tutorial.asciidoc @@ -112,7 +112,7 @@ usage: passthrough OPTIONS options: -d DebugFlags [-1: enable all debug logs] - -D DebugLogFile [file path; use - for stdout] + -D DebugLogFile [file path; use - for stderr] -u \Server\Share [UNC prefix (single backslash)] -p Directory [directory to expose as pass through file system] -m MountPoint [X:|*|directory] @@ -138,7 +138,7 @@ The variable `DebugLogFile` is used to control the WinFsp debug logging mechanis if (0 != DebugLogFile) { if (0 == wcscmp(L"-", DebugLogFile)) - DebugLogHandle = GetStdHandle(STD_OUTPUT_HANDLE); + DebugLogHandle = GetStdHandle(STD_ERROR_HANDLE); else DebugLogHandle = CreateFileW( DebugLogFile, diff --git a/src/dll/fuse/fuse.c b/src/dll/fuse/fuse.c index c31aa773..c7ac85d0 100644 --- a/src/dll/fuse/fuse.c +++ b/src/dll/fuse/fuse.c @@ -32,6 +32,7 @@ struct fsp_fuse_core_opt_data { struct fsp_fuse_env *env; int help, debug; + HANDLE DebugLogHandle; int set_umask, umask, set_uid, uid, set_gid, gid, @@ -52,6 +53,8 @@ static struct fuse_opt fsp_fuse_core_opts[] = FSP_FUSE_CORE_OPT("-d", debug, 1), FSP_FUSE_CORE_OPT("debug", debug, 1), + FUSE_OPT_KEY("DebugLog=", 'D'), + FUSE_OPT_KEY("hard_remove", FUSE_OPT_KEY_DISCARD), FUSE_OPT_KEY("use_ino", FUSE_OPT_KEY_DISCARD), FUSE_OPT_KEY("readdir_ino", FUSE_OPT_KEY_DISCARD), @@ -450,6 +453,7 @@ static int fsp_fuse_core_opt_proc(void *opt_data0, const char *arg, int key, case 'h': FspServiceLog(EVENTLOG_ERROR_TYPE, L"" FSP_FUSE_LIBRARY_NAME " options:\n" + " -o DebugLog=FILE debug log file (deflt: stderr)\n" " -o SectorSize=N sector size for Windows (512-4096, deflt: 4096)\n" " -o SectorsPerAllocationUnit=N sectors per allocation unit (deflt: 1)\n" " -o MaxComponentLength=N max file name component length (deflt: 255)\n" @@ -466,6 +470,17 @@ static int fsp_fuse_core_opt_proc(void *opt_data0, const char *arg, int key, FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION); opt_data->help = 1; return 1; + case 'D': + arg += sizeof "DebugLog=" - 1; + opt_data->DebugLogHandle = CreateFileA( + arg, + FILE_APPEND_DATA, + FILE_SHARE_READ | FILE_SHARE_WRITE, + 0, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + 0); + return 0; case 'U': if ('U' == arg[2]) arg += sizeof "--UNC=" - 1; @@ -508,6 +523,7 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env, memset(&opt_data, 0, sizeof opt_data); opt_data.env = env; + opt_data.DebugLogHandle = GetStdHandle(STD_ERROR_HANDLE); opt_data.VolumeParams.FileInfoTimeout = 1000; /* default FileInfoTimeout for FUSE file systems */ if (-1 == fsp_fuse_opt_parse(env, args, &opt_data, fsp_fuse_core_opts, fsp_fuse_core_opt_proc)) @@ -515,6 +531,16 @@ FSP_FUSE_API struct fuse *fsp_fuse_new(struct fsp_fuse_env *env, if (opt_data.help) return 0; + if (opt_data.debug) + { + if (INVALID_HANDLE_VALUE == opt_data.DebugLogHandle) + { + ErrorMessage = L": cannot open debug log file."; + goto fail; + } + FspDebugLogSetHandle(opt_data.DebugLogHandle); + } + if ((opt_data.set_uid && -1 == opt_data.uid) || (opt_data.set_gid && -1 == opt_data.gid)) { diff --git a/tst/memfs/memfs-main.c b/tst/memfs/memfs-main.c index 78ff16bb..edebbfea 100644 --- a/tst/memfs/memfs-main.c +++ b/tst/memfs/memfs-main.c @@ -106,7 +106,7 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv) if (0 != DebugLogFile) { if (0 == wcscmp(L"-", DebugLogFile)) - DebugLogHandle = GetStdHandle(STD_OUTPUT_HANDLE); + DebugLogHandle = GetStdHandle(STD_ERROR_HANDLE); else DebugLogHandle = CreateFileW( DebugLogFile, @@ -184,7 +184,7 @@ usage: "\n" "options:\n" " -d DebugFlags [-1: enable all debug logs]\n" - " -D DebugLogFile [file path; use - for stdout]\n" + " -D DebugLogFile [file path; use - for stderr]\n" " -i [case insensitive file system]\n" " -t FileInfoTimeout [millis]\n" " -n MaxFileNodes\n" diff --git a/tst/passthrough/passthrough.c b/tst/passthrough/passthrough.c index 2eef2a45..b99ee329 100644 --- a/tst/passthrough/passthrough.c +++ b/tst/passthrough/passthrough.c @@ -846,7 +846,7 @@ static NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv) if (0 != DebugLogFile) { if (0 == wcscmp(L"-", DebugLogFile)) - DebugLogHandle = GetStdHandle(STD_OUTPUT_HANDLE); + DebugLogHandle = GetStdHandle(STD_ERROR_HANDLE); else DebugLogHandle = CreateFileW( DebugLogFile, @@ -903,7 +903,7 @@ usage: "\n" "options:\n" " -d DebugFlags [-1: enable all debug logs]\n" - " -D DebugLogFile [file path; use - for stdout]\n" + " -D DebugLogFile [file path; use - for stderr]\n" " -u \\Server\\Share [UNC prefix (single backslash)]\n" " -p Directory [directory to expose as pass through file system]\n" " -m MountPoint [X:|*|directory]\n";