summaryrefslogtreecommitdiff
path: root/vdservice
diff options
context:
space:
mode:
authorArnon Gilboa <agilboa@redhat.com>2011-07-24 13:20:50 +0300
committerArnon Gilboa <agilboa@redhat.com>2011-07-24 18:08:02 +0300
commit407acb2288e48281cf1c60c70608f5838ac97c91 (patch)
tree2f0a51501fa4b14e38bac8d75836dc88f0ffa243 /vdservice
parente0a75c9042eca4aa6e013aa05c2603f5cf156f57 (diff)
vdservice: clean agent proc handle in kill_agent()
fill_agent_events() will not add it to the events used by WaitFor(), preventing usage of a dead process handle.
Diffstat (limited to 'vdservice')
-rw-r--r--vdservice/vdservice.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/vdservice/vdservice.cpp b/vdservice/vdservice.cpp
index b6c9234..94fe361 100644
--- a/vdservice/vdservice.cpp
+++ b/vdservice/vdservice.cpp
@@ -904,21 +904,24 @@ bool VDService::kill_agent()
{
DWORD exit_code = 0;
DWORD wait_ret;
+ HANDLE proc_handle;
bool ret = true;
if (!_agent_alive) {
return true;
}
_agent_alive = false;
+ proc_handle = _agent_proc_info.hProcess;
+ _agent_proc_info.hProcess = 0;
if (_pipe_connected) {
_pipe_connected = false;
DisconnectNamedPipe(_pipe_state.pipe);
}
- if (GetProcessId(_agent_proc_info.hProcess)) {
- wait_ret = WaitForSingleObject(_agent_proc_info.hProcess, 3000);
+ if (GetProcessId(proc_handle)) {
+ wait_ret = WaitForSingleObject(proc_handle, 3000);
switch (wait_ret) {
case WAIT_OBJECT_0:
- if (GetExitCodeProcess(_agent_proc_info.hProcess, &exit_code)) {
+ if (GetExitCodeProcess(proc_handle, &exit_code)) {
vd_printf("vdagent exit code %u", exit_code);
} else if (exit_code == STILL_ACTIVE) {
vd_printf("Failed killing vdagent");
@@ -937,7 +940,7 @@ bool VDService::kill_agent()
break;
}
}
- CloseHandle(_agent_proc_info.hProcess);
+ CloseHandle(proc_handle);
CloseHandle(_agent_proc_info.hThread);
ZeroMemory(&_agent_proc_info, sizeof(_agent_proc_info));
return ret;