[Spice-commits] 4 commits - vdservice/vdservice.cpp
Frediano Ziglio
fziglio at kemper.freedesktop.org
Sat Jul 8 07:29:41 UTC 2017
vdservice/vdservice.cpp | 66 ++++++++++++++++++++++++------------------------
1 file changed, 33 insertions(+), 33 deletions(-)
New commits:
commit b2c8665777fe1e926953d90d9f9268d3f7210f5b
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Sat Jul 8 08:22:11 2017 +0100
Store agent process handle instead of using PROCESS_INFORMATION
We just need the handle of the process.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index 5caed39..1eff380 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -78,18 +78,18 @@ private:
bool kill_agent();
unsigned fill_agent_event() {
ASSERT(_events);
- if (_agent_proc_info.hProcess) {
- _events[_events_count - 1] = _agent_proc_info.hProcess;
+ if (_agent_process) {
+ _events[_events_count - 1] = _agent_process;
return _events_count;
} else {
return _events_count - 1;
}
}
- bool agent_alive() const { return _agent_proc_info.hProcess != NULL; }
+ bool agent_alive() const { return _agent_process != NULL; }
private:
SERVICE_STATUS _status;
SERVICE_STATUS_HANDLE _status_handle;
- PROCESS_INFORMATION _agent_proc_info;
+ HANDLE _agent_process;
HANDLE _control_event;
HANDLE _agent_stop_event;
HANDLE* _events;
@@ -109,6 +109,7 @@ private:
VDService::VDService()
: _status_handle (0)
+ , _agent_process(NULL)
, _events (NULL)
, _connection_id (0)
, _session_id (0)
@@ -118,7 +119,6 @@ VDService::VDService()
, _log (NULL)
, _events_count(0)
{
- ZeroMemory(&_agent_proc_info, sizeof(_agent_proc_info));
_system_version = supported_system_version();
_control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
_agent_stop_event = CreateEvent(NULL, FALSE, FALSE, VD_AGENT_STOP_EVENT);
@@ -695,20 +695,21 @@ bool VDService::launch_agent()
{
STARTUPINFO startup_info;
BOOL ret = FALSE;
+ PROCESS_INFORMATION agent_proc_info = {};
ZeroMemory(&startup_info, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
startup_info.lpDesktop = const_cast<LPTSTR>(TEXT("Winsta0\\winlogon"));
- ZeroMemory(&_agent_proc_info, sizeof(_agent_proc_info));
+ _agent_process = NULL;
if (_system_version == SYS_VER_WIN_XP_CLASS) {
if (_session_id == 0) {
ret = CreateProcess(_agent_path, _agent_path, NULL, NULL, FALSE, 0, NULL, NULL,
- &startup_info, &_agent_proc_info);
+ &startup_info, &agent_proc_info);
} else {
for (int i = 0; i < CREATE_PROC_MAX_RETRIES; i++) {
ret = create_session_process_as_user(_session_id, TRUE, NULL, NULL, _agent_path,
NULL, NULL, FALSE, 0, NULL, NULL,
- &startup_info, &_agent_proc_info);
+ &startup_info, &agent_proc_info);
if (ret) {
vd_printf("create_session_process_as_user #%d", i);
break;
@@ -719,7 +720,7 @@ bool VDService::launch_agent()
} else if (_system_version == SYS_VER_WIN_7_CLASS) {
startup_info.lpDesktop = const_cast<LPTSTR>(TEXT("Winsta0\\default"));
ret = create_process_as_user(_session_id, _agent_path, _agent_path, NULL, NULL, FALSE, 0,
- NULL, NULL, &startup_info, &_agent_proc_info);
+ NULL, NULL, &startup_info, &agent_proc_info);
} else {
vd_printf("Not supported in this system version");
return false;
@@ -728,8 +729,8 @@ bool VDService::launch_agent()
vd_printf("CreateProcess() failed: %lu", GetLastError());
return false;
}
- CloseHandle(_agent_proc_info.hThread);
- _agent_proc_info.hThread = NULL;
+ CloseHandle(agent_proc_info.hThread);
+ _agent_process = agent_proc_info.hProcess;
return true;
}
@@ -743,8 +744,8 @@ bool VDService::kill_agent()
if (!agent_alive()) {
return true;
}
- proc_handle = _agent_proc_info.hProcess;
- _agent_proc_info.hProcess = 0;
+ proc_handle = _agent_process;
+ _agent_process = NULL;
SetEvent(_agent_stop_event);
if (GetProcessId(proc_handle)) {
wait_ret = WaitForSingleObject(proc_handle, VD_AGENT_TIMEOUT);
@@ -768,7 +769,6 @@ bool VDService::kill_agent()
}
ResetEvent(_agent_stop_event);
CloseHandle(proc_handle);
- ZeroMemory(&_agent_proc_info, sizeof(_agent_proc_info));
return ret;
}
commit babef14b8ca24383cabdb160a331110ca712ed18
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Dec 14 09:46:32 2016 +0000
Use process handle to mark agent existence
Avoid extra field that could be out of sync.
Having a valid process handle is enough.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index 3de8111..5caed39 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -85,6 +85,7 @@ private:
return _events_count - 1;
}
}
+ bool agent_alive() const { return _agent_proc_info.hProcess != NULL; }
private:
SERVICE_STATUS _status;
SERVICE_STATUS_HANDLE _status_handle;
@@ -101,7 +102,6 @@ private:
DWORD _last_agent_restart_time;
int _agent_restarts;
int _system_version;
- bool _agent_alive;
bool _running;
VDLog* _log;
unsigned _events_count;
@@ -114,7 +114,6 @@ VDService::VDService()
, _session_id (0)
, _last_agent_restart_time (0)
, _agent_restarts (0)
- , _agent_alive (false)
, _running (false)
, _log (NULL)
, _events_count(0)
@@ -428,7 +427,7 @@ bool VDService::execute()
WAIT_OBJECT_0) {
handle_control_event();
}
- if (_running && !_agent_alive) {
+ if (_running && !agent_alive()) {
restart_agent(false);
}
}
@@ -731,7 +730,6 @@ bool VDService::launch_agent()
}
CloseHandle(_agent_proc_info.hThread);
_agent_proc_info.hThread = NULL;
- _agent_alive = true;
return true;
}
@@ -742,10 +740,9 @@ bool VDService::kill_agent()
HANDLE proc_handle;
bool ret = true;
- if (!_agent_alive) {
+ if (!agent_alive()) {
return true;
}
- _agent_alive = false;
proc_handle = _agent_proc_info.hProcess;
_agent_proc_info.hProcess = 0;
SetEvent(_agent_stop_event);
commit 143f6e55ee3701dfb8e8faf743cc5a5d8ab7b0c8
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Dec 14 09:41:41 2016 +0000
Close agent thread handle
This is not needed so we can close it
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index e9bf1a2..3de8111 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -729,6 +729,8 @@ bool VDService::launch_agent()
vd_printf("CreateProcess() failed: %lu", GetLastError());
return false;
}
+ CloseHandle(_agent_proc_info.hThread);
+ _agent_proc_info.hThread = NULL;
_agent_alive = true;
return true;
}
@@ -769,7 +771,6 @@ bool VDService::kill_agent()
}
ResetEvent(_agent_stop_event);
CloseHandle(proc_handle);
- CloseHandle(_agent_proc_info.hThread);
ZeroMemory(&_agent_proc_info, sizeof(_agent_proc_info));
return ret;
}
commit cf829d09ef2a5707a6e4e677f50d41beff508aa9
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Dec 14 09:40:51 2016 +0000
Make some functions static
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index dc49ec5..e9bf1a2 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -444,7 +444,7 @@ bool VDService::execute()
return true;
}
-DWORD64 marshall_string(LPCWSTR str, DWORD max_size, LPBYTE* next_buf, DWORD* used_bytes)
+static DWORD64 marshall_string(LPCWSTR str, DWORD max_size, LPBYTE* next_buf, DWORD* used_bytes)
{
DWORD offset = *used_bytes;
@@ -486,14 +486,15 @@ typedef struct CreateProcessRet {
PROCESS_INFORMATION process_information;
} CreateProcessRet;
-BOOL create_session_process_as_user(IN DWORD session_id, IN BOOL use_default_token, IN HANDLE token,
- IN LPCWSTR application_name, IN LPWSTR command_line,
- IN LPSECURITY_ATTRIBUTES process_attributes,
- IN LPSECURITY_ATTRIBUTES thread_attributes,
- IN BOOL inherit_handles, IN DWORD creation_flags,
- IN LPVOID environment, IN LPCWSTR current_directory,
- IN LPSTARTUPINFOW startup_info,
- OUT LPPROCESS_INFORMATION process_information)
+static BOOL
+create_session_process_as_user(IN DWORD session_id, IN BOOL use_default_token, IN HANDLE token,
+ IN LPCWSTR application_name, IN LPWSTR command_line,
+ IN LPSECURITY_ATTRIBUTES process_attributes,
+ IN LPSECURITY_ATTRIBUTES thread_attributes,
+ IN BOOL inherit_handles, IN DWORD creation_flags,
+ IN LPVOID environment, IN LPCWSTR current_directory,
+ IN LPSTARTUPINFOW startup_info,
+ OUT LPPROCESS_INFORMATION process_information)
{
WCHAR win_sta_path[MAX_PATH];
HINSTANCE win_sta_handle;
@@ -624,12 +625,13 @@ BOOL create_session_process_as_user(IN DWORD session_id, IN BOOL use_default_tok
return ret;
}
-BOOL create_process_as_user(IN DWORD session_id, IN LPCWSTR application_name,
- IN LPWSTR command_line, IN LPSECURITY_ATTRIBUTES process_attributes,
- IN LPSECURITY_ATTRIBUTES thread_attributes, IN BOOL inherit_handles,
- IN DWORD creation_flags, IN LPVOID environment,
- IN LPCWSTR current_directory, IN LPSTARTUPINFOW startup_info,
- OUT LPPROCESS_INFORMATION process_information)
+static BOOL
+create_process_as_user(IN DWORD session_id, IN LPCWSTR application_name,
+ IN LPWSTR command_line, IN LPSECURITY_ATTRIBUTES process_attributes,
+ IN LPSECURITY_ATTRIBUTES thread_attributes, IN BOOL inherit_handles,
+ IN DWORD creation_flags, IN LPVOID environment,
+ IN LPCWSTR current_directory, IN LPSTARTUPINFOW startup_info,
+ OUT LPPROCESS_INFORMATION process_information)
{
PROCESSENTRY32 proc_entry;
DWORD winlogon_pid = 0;
More information about the Spice-commits
mailing list