mirror of https://github.com/Icinga/icinga2.git
parent
60114d4b5d
commit
3cf08ad050
|
@ -24,6 +24,7 @@
|
|||
#include "base/string.hpp"
|
||||
#include "base/stacktrace.hpp"
|
||||
#include "base/context.hpp"
|
||||
#include "base/utility.hpp"
|
||||
#include <sstream>
|
||||
#include <boost/exception/errinfo_api_function.hpp>
|
||||
#include <boost/exception/errinfo_errno.hpp>
|
||||
|
@ -97,26 +98,7 @@ typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
|||
|
||||
inline std::string to_string(const errinfo_win32_error& e)
|
||||
{
|
||||
std::ostringstream tmp;
|
||||
int code = e.value();
|
||||
|
||||
char *message;
|
||||
String result = "Unknown error.";
|
||||
|
||||
DWORD rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM, NULL, code, 0, (char *)&message,
|
||||
0, NULL);
|
||||
|
||||
if (rc != 0) {
|
||||
result = String(message);
|
||||
LocalFree(message);
|
||||
|
||||
/* remove trailing new-line characters */
|
||||
boost::algorithm::trim_right(result);
|
||||
}
|
||||
|
||||
tmp << code << ", \"" << result << "\"";
|
||||
return tmp.str();
|
||||
return Utility::FormatErrorNumber(e.value());
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
|
|
|
@ -413,21 +413,30 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
|||
|
||||
if (!CreateProcess(NULL, args, NULL, NULL, TRUE,
|
||||
EXTENDED_STARTUPINFO_PRESENT, envp, NULL, &si.StartupInfo, &pi)) {
|
||||
DWORD error = GetLastError();
|
||||
CloseHandle(outWritePipe);
|
||||
CloseHandle(outWritePipeDup);
|
||||
delete args;
|
||||
free(envp);
|
||||
DeleteProcThreadAttributeList(lpAttributeList);
|
||||
delete [] reinterpret_cast<char *>(lpAttributeList);
|
||||
BOOST_THROW_EXCEPTION(win32_error()
|
||||
<< boost::errinfo_api_function("CreateProcess")
|
||||
<< errinfo_win32_error(GetLastError()));
|
||||
|
||||
m_Result.PID = 0;
|
||||
m_Result.ExecutionEnd = Utility::GetTime();
|
||||
m_Result.ExitStatus = 127;
|
||||
m_Result.Output = "Command " + String(args) + " failed to execute: " + Utility::FormatErrorNumber(error);
|
||||
|
||||
delete [] args;
|
||||
|
||||
if (callback)
|
||||
Utility::QueueAsyncCallback(boost::bind(callback, m_Result));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
delete args;
|
||||
delete [] args;
|
||||
free(envp);
|
||||
DeleteProcThreadAttributeList(lpAttributeList);
|
||||
delete[] reinterpret_cast<char *>(lpAttributeList);
|
||||
delete [] reinterpret_cast<char *>(lpAttributeList);
|
||||
|
||||
CloseHandle(outWritePipe);
|
||||
CloseHandle(outWritePipeDup);
|
||||
|
|
Loading…
Reference in New Issue