[Spice-devel] [vdagent-win v1] vdagent-win: start vdagent with lock info from session
Victor Toso
victortoso at redhat.com
Mon Dec 12 21:42:43 UTC 2016
From: Frediano Ziglio <fziglio at redhat.com>
Would be something like this (not tested)
---
common/vdcommon.h | 1 +
vdagent/vdagent.cpp | 12 ++++++++++++
vdservice/vdservice.cpp | 7 +++++++
3 files changed, 20 insertions(+)
diff --git a/common/vdcommon.h b/common/vdcommon.h
index c1920e9..6b53327 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -66,6 +66,7 @@ typedef Mutex mutex_t;
#define VD_AGENT_REGISTRY_KEY "SOFTWARE\\Red Hat\\Spice\\vdagent\\"
#define VD_AGENT_STOP_EVENT TEXT("Global\\vdagent_stop_event")
+#define VD_AGENT_SESSION_UNLOCKED_EVENT TEXT("Global\\vdagent_session_unlocked_event")
#if defined __GNUC__
#define ALIGN_GCC __attribute__ ((packed))
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index e3ba14b..0396a11 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -236,6 +236,18 @@ VDAgent::VDAgent()
ZeroMemory(&_write_overlapped, sizeof(_write_overlapped));
ZeroMemory(_read_buf, sizeof(_read_buf));
+ HANDLE _session_unlocked_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_SESSION_UNLOCKED_EVENT);
+ switch (WaitForSingleObject(_session_unlocked_event, 0)) {
+ case WAIT_OBJECT_0:
+ _session_is_locked = false;
+ break;
+ default:
+ case WAIT_TIMEOUT:
+ _session_is_locked = true;
+ break;
+ }
+ CloseHandle(_session_unlocked_event);
+
_singleton = this;
}
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index 1892b72..65adf72 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -91,6 +91,7 @@ private:
PROCESS_INFORMATION _agent_proc_info;
HANDLE _control_event;
HANDLE _agent_stop_event;
+ HANDLE _session_unlocked_event;
HANDLE* _events;
TCHAR _agent_path[MAX_PATH];
VDControlQueue _control_queue;
@@ -123,11 +124,13 @@ VDService::VDService()
_system_version = supported_system_version();
_control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
_agent_stop_event = CreateEvent(NULL, FALSE, FALSE, VD_AGENT_STOP_EVENT);
+ _session_unlocked_event = CreateEvent(NULL, TRUE, TRUE, VD_AGENT_SESSION_UNLOCKED_EVENT);
_agent_path[0] = wchar_t('\0');
}
VDService::~VDService()
{
+ CloseHandle(_session_unlocked_event);
CloseHandle(_agent_stop_event);
CloseHandle(_control_event);
delete[] _events;
@@ -290,6 +293,10 @@ DWORD WINAPI VDService::control_handler(DWORD control, DWORD event_type, LPVOID
if (event_type == WTS_CONSOLE_CONNECT) {
s->_session_id = session_id;
s->set_control_event(VD_CONTROL_RESTART_AGENT);
+ } else if (event_type == WTS_SESSION_LOCK) {
+ ResetEvent(s->_session_unlocked_event);
+ } else if (event_type == WTS_SESSION_UNLOCK) {
+ SetEvent(s->_session_unlocked_event);
}
break;
}
--
2.9.3
More information about the Spice-devel
mailing list