From 65ecfc7d572dfc896b5d6b88fd67875d290e8114 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 24 Jun 2012 16:32:50 +0200 Subject: [PATCH] Compile fix for *NIX. --- icinga/i2-icinga.h | 4 ++++ icinga/nagioschecktask.cpp | 21 +++++++-------------- icinga/nagioschecktask.h | 2 ++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/icinga/i2-icinga.h b/icinga/i2-icinga.h index 45cf6be84..e831b2b26 100644 --- a/icinga/i2-icinga.h +++ b/icinga/i2-icinga.h @@ -31,6 +31,10 @@ #include #include +#ifndef _MSC_VER +# include "popen_noshell.h" +#endif /* _MSC_VER */ + #include using boost::packaged_task; using boost::unique_future; diff --git a/icinga/nagioschecktask.cpp b/icinga/nagioschecktask.cpp index f2901b9be..97fb58677 100644 --- a/icinga/nagioschecktask.cpp +++ b/icinga/nagioschecktask.cpp @@ -1,7 +1,4 @@ #include "i2-icinga.h" -#ifndef _MSC_VER -# include "popen_noshell.h" -#endif /* _MSC_VER */ using namespace icinga; @@ -10,7 +7,7 @@ deque NagiosCheckTask::m_Tasks; condition_variable NagiosCheckTask::m_TasksCV; NagiosCheckTask::NagiosCheckTask(const Service& service) - : CheckTask(service), m_FP(NULL) + : CheckTask(service), m_FP(NULL), m_UsePopen(false) { string checkCommand = service.GetCheckCommand(); m_Command = MacroProcessor::ResolveMacros(checkCommand, service.GetMacros()); // + " 2>&1"; @@ -108,18 +105,14 @@ bool NagiosCheckTask::InitTask(void) #ifdef _MSC_VER m_FP = _popen(m_Command.c_str(), "r"); #else /* _MSC_VER */ - bool use_libc_popen = false; - - popen_noshell_pass_to_pclose pclose_arg; - - if (!use_libc_popen) { - m_FP = popen_noshell_compat(m_Command.c_str(), "r", &pclose_arg); + if (!m_UsePopen) { + m_FP = popen_noshell_compat(m_Command.c_str(), "r", &m_PCloseArg); if (m_FP == NULL) // TODO: add check for valgrind - use_libc_popen = true; + m_UsePopen = true; } - if (use_libc_popen) + if (m_UsePopen) m_FP = popen(m_Command.c_str(), "r"); #endif /* _MSC_VER */ @@ -144,10 +137,10 @@ bool NagiosCheckTask::RunTask(void) #ifdef _MSC_VER status = _pclose(m_FP); #else /* _MSC_VER */ - if (use_libc_popen) + if (m_UsePopen) status = pclose(fp); else - status = pclose_noshell(&pclose_arg); + status = pclose_noshell(&m_PCloseArg); #endif /* _MSC_VER */ #ifndef _MSC_VER diff --git a/icinga/nagioschecktask.h b/icinga/nagioschecktask.h index d850ad8cf..ef46d079f 100644 --- a/icinga/nagioschecktask.h +++ b/icinga/nagioschecktask.h @@ -26,6 +26,8 @@ private: FILE *m_FP; stringstream m_OutputStream; + bool m_UsePopen; + popen_noshell_pass_to_pclose m_PCloseArg; static boost::mutex m_Mutex; static deque m_Tasks; -- 2.50.1