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