diff --git a/inc/winfsp/winfsp.h b/inc/winfsp/winfsp.h index 8382f3d7..cbd33332 100644 --- a/inc/winfsp/winfsp.h +++ b/inc/winfsp/winfsp.h @@ -864,6 +864,10 @@ typedef struct _FSP_SERVICE WCHAR ServiceName[]; } FSP_SERVICE; #pragma warning(pop) +FSP_API ULONG FspServiceRun(PWSTR ServiceName, + FSP_SERVICE_START *OnStart, + FSP_SERVICE_STOP *OnStop, + FSP_SERVICE_CONTROL *OnControl); FSP_API NTSTATUS FspServiceCreate(PWSTR ServiceName, FSP_SERVICE_START *OnStart, FSP_SERVICE_STOP *OnStop, diff --git a/src/dll/service.c b/src/dll/service.c index c413b409..7b06d66a 100644 --- a/src/dll/service.c +++ b/src/dll/service.c @@ -59,6 +59,36 @@ static inline FSP_SERVICE *FspServiceFromTable(VOID) return Service; } +FSP_API ULONG FspServiceRun(PWSTR ServiceName, + FSP_SERVICE_START *OnStart, + FSP_SERVICE_STOP *OnStop, + FSP_SERVICE_CONTROL *OnControl) +{ + FSP_SERVICE *Service; + NTSTATUS Result; + ULONG ExitCode; + + Result = FspServiceCreate(ServiceName, OnStart, OnStop, OnControl, &Service); + if (!NT_SUCCESS(Result)) + { + FspServiceLog(EVENTLOG_ERROR_TYPE, L"cannot create service (Status=%lx)", Result); + return FspWin32FromNtStatus(Result); + } + + FspServiceAllowConsoleMode(Service); + Result = FspServiceLoop(Service); + ExitCode = FspServiceGetExitCode(Service); + FspServiceDelete(Service); + + if (!NT_SUCCESS(Result)) + { + FspServiceLog(EVENTLOG_ERROR_TYPE, L"cannot run service (Status=%lx)", Result); + return FspWin32FromNtStatus(Result); + } + + return ExitCode; +} + FSP_API NTSTATUS FspServiceCreate(PWSTR ServiceName, FSP_SERVICE_START *OnStart, FSP_SERVICE_STOP *OnStop, diff --git a/tst/memfs/memfs-main.c b/tst/memfs/memfs-main.c index 77f5c72e..1e724802 100644 --- a/tst/memfs/memfs-main.c +++ b/tst/memfs/memfs-main.c @@ -24,8 +24,6 @@ #define warn(format, ...) FspServiceLog(EVENTLOG_WARNING_TYPE, format, __VA_ARGS__) #define fail(format, ...) FspServiceLog(EVENTLOG_ERROR_TYPE, format, __VA_ARGS__) -#define fatal(format, ...) (fail(format, __VA_ARGS__), exit(ERROR_GEN_FAILURE)) - #define argtos(v) if (arge > ++argp) v = *argp; else goto usage #define argtol(v) if (arge > ++argp) v = wcstol_deflt(*argp, v); else goto usage @@ -108,16 +106,16 @@ NTSTATUS SvcStart(FSP_SERVICE *Service, ULONG argc, PWSTR *argv) MountPoint = FspFileSystemMountPoint(MemfsFileSystem(Memfs)); - Service->UserContext = Memfs; - Result = STATUS_SUCCESS; - -exit: info(L"%s -t %ld -n %ld -s %ld%s%s%s%s -m %s", L"" PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize, RootSddl ? L" -S " : L"", RootSddl ? RootSddl : L"", VolumePrefix ? L" -u " : L"", VolumePrefix ? VolumePrefix : L"", MountPoint); + Service->UserContext = Memfs; + Result = STATUS_SUCCESS; + +exit: if (!NT_SUCCESS(Result) && 0 != Memfs) MemfsDelete(Memfs); @@ -152,21 +150,5 @@ NTSTATUS SvcStop(FSP_SERVICE *Service) int wmain(int argc, wchar_t **argv) { - FSP_SERVICE *Service; - NTSTATUS Result; - ULONG ExitCode; - - Result = FspServiceCreate(L"" PROGNAME, SvcStart, SvcStop, 0, &Service); - if (!NT_SUCCESS(Result)) - fatal(L"cannot create service (Status=%lx)", Result); - - FspServiceAllowConsoleMode(Service); - Result = FspServiceLoop(Service); - ExitCode = FspServiceGetExitCode(Service); - FspServiceDelete(Service); - - if (!NT_SUCCESS(Result)) - fatal(L"cannot run service (Status=%lx)", Result); - - return ExitCode; + return FspServiceRun(L"" PROGNAME, SvcStart, SvcStop, 0); }