refactor winfsp system stop

This commit is contained in:
2025-01-21 15:05:04 -06:00
parent f57bbdbb50
commit 1b11e500f3

View File

@ -50,6 +50,10 @@ E_SIMPLE3(winfsp_event, debug, true,
std::string, api_path, ap, E_FROM_STRING,
NTSTATUS, result, res, E_FROM_INT32
);
E_SIMPLE(drive_stop_begin, info, true);
E_SIMPLE(drive_stop_end, info, true);
E_SIMPLE(drive_stop_timed_out, info, true);
// clang-format on
#define RAISE_WINFSP_EVENT(func, file, ret) \
@ -137,10 +141,20 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
REPERTORY_USES_FUNCTION_NAME();
timeout stop_timeout([]() { app_config::set_stop_requested(); }, 30s);
event_system::instance().raise<drive_stop_begin>();
timeout stop_timeout(
[]() {
event_system::instance().raise<drive_stop_timed_out>();
app_config::set_stop_requested();
},
30s);
host_.Unmount();
stop_timeout.disable();
event_system::instance().raise<drive_stop_end>();
if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(function_name, "failed to set mount state");
}