mirror of https://github.com/Icinga/icinga2.git
parent
04210894d3
commit
0484706324
|
@ -275,8 +275,12 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
||||||
m_Result.ExecutionStart = Utility::GetTime();
|
m_Result.ExecutionStart = Utility::GetTime();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
SECURITY_ATTRIBUTES sa = {};
|
||||||
|
sa.nLength = sizeof(sa);
|
||||||
|
sa.bInheritHandle = TRUE;
|
||||||
|
|
||||||
HANDLE outReadPipe, outWritePipe;
|
HANDLE outReadPipe, outWritePipe;
|
||||||
if (!CreatePipe(&outReadPipe, &outWritePipe, NULL, 0))
|
if (!CreatePipe(&outReadPipe, &outWritePipe, &sa, 0))
|
||||||
BOOST_THROW_EXCEPTION(win32_error()
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
<< boost::errinfo_api_function("CreatePipe")
|
<< boost::errinfo_api_function("CreatePipe")
|
||||||
<< errinfo_win32_error(GetLastError()));
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
@ -293,12 +297,39 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
||||||
<< boost::errinfo_api_function("DuplicateHandle")
|
<< boost::errinfo_api_function("DuplicateHandle")
|
||||||
<< errinfo_win32_error(GetLastError()));
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
|
||||||
STARTUPINFO si = {};
|
LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;
|
||||||
si.cb = sizeof(si);
|
SIZE_T cbSize;
|
||||||
si.hStdError = outWritePipe;
|
|
||||||
si.hStdOutput = outWritePipeDup;
|
if (!InitializeProcThreadAttributeList(NULL, 1, 0, &cbSize) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||||
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
si.dwFlags = STARTF_USESTDHANDLES;
|
<< boost::errinfo_api_function("InitializeProcThreadAttributeList")
|
||||||
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
|
||||||
|
lpAttributeList = reinterpret_cast<LPPROC_THREAD_ATTRIBUTE_LIST>(new char[cbSize]);
|
||||||
|
|
||||||
|
if (!InitializeProcThreadAttributeList(lpAttributeList, 1, 0, &cbSize))
|
||||||
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< boost::errinfo_api_function("InitializeProcThreadAttributeList")
|
||||||
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
|
||||||
|
HANDLE rgHandles[3];
|
||||||
|
rgHandles[0] = outWritePipe;
|
||||||
|
rgHandles[1] = outWritePipeDup;
|
||||||
|
rgHandles[2] = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
|
||||||
|
if (!UpdateProcThreadAttribute(lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
|
||||||
|
rgHandles, sizeof(rgHandles), NULL, NULL))
|
||||||
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
|
<< boost::errinfo_api_function("UpdateProcThreadAttribute")
|
||||||
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
|
||||||
|
STARTUPINFOEX si = {};
|
||||||
|
si.StartupInfo.cb = sizeof(si);
|
||||||
|
si.StartupInfo.hStdError = outWritePipe;
|
||||||
|
si.StartupInfo.hStdOutput = outWritePipeDup;
|
||||||
|
si.StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
si.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
||||||
|
si.lpAttributeList = lpAttributeList;
|
||||||
|
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
|
|
||||||
|
@ -358,11 +389,14 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
||||||
|
|
||||||
envp[offset] = '\0';
|
envp[offset] = '\0';
|
||||||
|
|
||||||
if (!CreateProcess(NULL, args, NULL, NULL, TRUE, 0, envp, NULL, &si, &pi)) {
|
if (!CreateProcess(NULL, args, NULL, NULL, TRUE,
|
||||||
|
EXTENDED_STARTUPINFO_PRESENT, envp, NULL, &si.StartupInfo, &pi)) {
|
||||||
CloseHandle(outWritePipe);
|
CloseHandle(outWritePipe);
|
||||||
CloseHandle(outWritePipeDup);
|
CloseHandle(outWritePipeDup);
|
||||||
delete args;
|
delete args;
|
||||||
free(envp);
|
free(envp);
|
||||||
|
DeleteProcThreadAttributeList(lpAttributeList);
|
||||||
|
delete [] reinterpret_cast<char *>(lpAttributeList);
|
||||||
BOOST_THROW_EXCEPTION(win32_error()
|
BOOST_THROW_EXCEPTION(win32_error()
|
||||||
<< boost::errinfo_api_function("CreateProcess")
|
<< boost::errinfo_api_function("CreateProcess")
|
||||||
<< errinfo_win32_error(GetLastError()));
|
<< errinfo_win32_error(GetLastError()));
|
||||||
|
@ -370,6 +404,8 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
||||||
|
|
||||||
delete args;
|
delete args;
|
||||||
free(envp);
|
free(envp);
|
||||||
|
DeleteProcThreadAttributeList(lpAttributeList);
|
||||||
|
delete[] reinterpret_cast<char *>(lpAttributeList);
|
||||||
|
|
||||||
CloseHandle(outWritePipe);
|
CloseHandle(outWritePipe);
|
||||||
CloseHandle(outWritePipeDup);
|
CloseHandle(outWritePipeDup);
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define WIN32_H
|
#define WIN32_H
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define _WIN32_WINNT 0x0502
|
#define _WIN32_WINNT _WIN32_WINNT_VISTA
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
Loading…
Reference in New Issue