mirror of https://github.com/Icinga/icinga2.git
parent
a75d7d69ec
commit
06c2a4088d
|
@ -63,7 +63,7 @@ static boost::once_flag l_ProcessOnceFlag = BOOST_ONCE_INIT;
|
||||||
static boost::once_flag l_SpawnHelperOnceFlag = BOOST_ONCE_INIT;
|
static boost::once_flag l_SpawnHelperOnceFlag = BOOST_ONCE_INIT;
|
||||||
|
|
||||||
Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& extraEnvironment)
|
Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& extraEnvironment)
|
||||||
: m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment), m_Timeout(600)
|
: m_Arguments(arguments), m_ExtraEnvironment(extraEnvironment), m_Timeout(600), m_AdjustPriority(false)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
, m_ReadPending(false), m_ReadFailed(false), m_Overlapped()
|
, m_ReadPending(false), m_ReadFailed(false), m_Overlapped()
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
@ -94,6 +94,7 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques
|
||||||
|
|
||||||
Array::Ptr arguments = request->Get("arguments");
|
Array::Ptr arguments = request->Get("arguments");
|
||||||
Dictionary::Ptr extraEnvironment = request->Get("extraEnvironment");
|
Dictionary::Ptr extraEnvironment = request->Get("extraEnvironment");
|
||||||
|
bool adjustPriority = request->Get("adjustPriority");
|
||||||
|
|
||||||
// build argv
|
// build argv
|
||||||
char **argv = new char *[arguments->GetLength() + 1];
|
char **argv = new char *[arguments->GetLength() + 1];
|
||||||
|
@ -161,7 +162,7 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques
|
||||||
(void)close(fds[2]);
|
(void)close(fds[2]);
|
||||||
|
|
||||||
#ifdef HAVE_NICE
|
#ifdef HAVE_NICE
|
||||||
if (nice(5) < 0)
|
if (adjustPriority && nice(5) < 0)
|
||||||
Log(LogWarning, "base", "Failed to renice child process.");
|
Log(LogWarning, "base", "Failed to renice child process.");
|
||||||
#endif /* HAVE_NICE */
|
#endif /* HAVE_NICE */
|
||||||
|
|
||||||
|
@ -366,12 +367,13 @@ static void StartSpawnProcessHelper(void)
|
||||||
l_ProcessControlPID = pid;
|
l_ProcessControlPID = pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment, int fds[3])
|
static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary::Ptr& extraEnvironment, bool adjustPriority, int fds[3])
|
||||||
{
|
{
|
||||||
Dictionary::Ptr request = new Dictionary();
|
Dictionary::Ptr request = new Dictionary();
|
||||||
request->Set("command", "spawn");
|
request->Set("command", "spawn");
|
||||||
request->Set("arguments", Array::FromVector(arguments));
|
request->Set("arguments", Array::FromVector(arguments));
|
||||||
request->Set("extraEnvironment", extraEnvironment);
|
request->Set("extraEnvironment", extraEnvironment);
|
||||||
|
request->Set("adjustPriority", adjustPriority);
|
||||||
|
|
||||||
String jrequest = JsonEncode(request);
|
String jrequest = JsonEncode(request);
|
||||||
size_t length = jrequest.GetLength();
|
size_t length = jrequest.GetLength();
|
||||||
|
@ -579,6 +581,16 @@ double Process::GetTimeout(void) const
|
||||||
return m_Timeout;
|
return m_Timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Process::SetAdjustPriority(bool adjust)
|
||||||
|
{
|
||||||
|
m_AdjustPriority = adjust;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Process::GetAdjustPriority(void) const
|
||||||
|
{
|
||||||
|
return m_AdjustPriority;
|
||||||
|
}
|
||||||
|
|
||||||
void Process::IOThreadProc(int tid)
|
void Process::IOThreadProc(int tid)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -959,7 +971,7 @@ void Process::Run(const boost::function<void(const ProcessResult&)>& callback)
|
||||||
fds[1] = outfds[1];
|
fds[1] = outfds[1];
|
||||||
fds[2] = outfds[1];
|
fds[2] = outfds[1];
|
||||||
|
|
||||||
m_Process = ProcessSpawn(m_Arguments, m_ExtraEnvironment, fds);
|
m_Process = ProcessSpawn(m_Arguments, m_ExtraEnvironment, m_AdjustPriority, fds);
|
||||||
m_PID = m_Process;
|
m_PID = m_Process;
|
||||||
|
|
||||||
Log(LogNotice, "Process")
|
Log(LogNotice, "Process")
|
||||||
|
|
|
@ -73,6 +73,9 @@ public:
|
||||||
void SetTimeout(double timeout);
|
void SetTimeout(double timeout);
|
||||||
double GetTimeout(void) const;
|
double GetTimeout(void) const;
|
||||||
|
|
||||||
|
void SetAdjustPriority(bool adjust);
|
||||||
|
bool GetAdjustPriority(void) const;
|
||||||
|
|
||||||
void Run(const boost::function<void (const ProcessResult&)>& callback = boost::function<void (const ProcessResult&)>());
|
void Run(const boost::function<void (const ProcessResult&)>& callback = boost::function<void (const ProcessResult&)>());
|
||||||
|
|
||||||
pid_t GetPID(void) const;
|
pid_t GetPID(void) const;
|
||||||
|
@ -92,6 +95,7 @@ private:
|
||||||
Dictionary::Ptr m_ExtraEnvironment;
|
Dictionary::Ptr m_ExtraEnvironment;
|
||||||
|
|
||||||
double m_Timeout;
|
double m_Timeout;
|
||||||
|
bool m_AdjustPriority;
|
||||||
|
|
||||||
ProcessHandle m_Process;
|
ProcessHandle m_Process;
|
||||||
pid_t m_PID;
|
pid_t m_PID;
|
||||||
|
|
|
@ -93,6 +93,8 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
|
||||||
else
|
else
|
||||||
process->SetTimeout(checkable->GetCheckTimeout());
|
process->SetTimeout(checkable->GetCheckTimeout());
|
||||||
|
|
||||||
|
process->SetAdjustPriority(true);
|
||||||
|
|
||||||
process->Run(boost::bind(callback, command, _1));
|
process->Run(boost::bind(callback, command, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue