[icinga-checkins] icinga.org: icinga2/master: Pass argc and argv to the Python interpreter.

git at icinga.org git at icinga.org
Thu Feb 14 16:19:07 CET 2013


Module: icinga2
Branch: master
Commit: d3928a7e69c26cf11eabeb1cda82ca2ff7e83b46
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=d3928a7e69c26cf11eabeb1cda82ca2ff7e83b46

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Feb 14 16:18:58 2013 +0100

Pass argc and argv to the Python interpreter.

---

 icinga-app/icinga.cpp         |    4 ++++
 lib/base/application.cpp      |   22 ++++++++++++++++++++++
 lib/base/application.h        |    9 ++++++++-
 lib/python/pythonlanguage.cpp |    6 +++++-
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index f6b66bd..08af590 100644
--- a/icinga-app/icinga.cpp
+++ b/icinga-app/icinga.cpp
@@ -140,6 +140,10 @@ int main(int argc, char **argv)
 	 * in the base library. */
 	Application::SetMainThread();
 
+	/* Set command-line arguments. */
+	Application::SetArgC(argc);
+	Application::SetArgV(argv);
+
 	/* Install exception handlers to make debugging easier. */
 	Application::InstallExceptionHandlers();
 
diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index b0d179d..0a3c7ba 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -30,6 +30,8 @@ String Application::m_PrefixDir;
 String Application::m_LocalStateDir;
 String Application::m_PkgLibDir;
 String Application::m_PkgDataDir;
+int Application::m_ArgC;
+char **Application::m_ArgV;
 
 /**
  * Constructor for the Application class.
@@ -87,6 +89,26 @@ Application::Ptr Application::GetInstance(void)
 		return Application::Ptr();
 }
 
+int Application::GetArgC(void)
+{
+	return m_ArgC;
+}
+
+void Application::SetArgC(int argc)
+{
+	m_ArgC = argc;
+}
+
+char **Application::GetArgV(void)
+{
+	return m_ArgV;
+}
+
+void Application::SetArgV(char **argv)
+{
+	m_ArgV = argv;
+}
+
 /**
  * Runs one iteration of the event loop.
  *
diff --git a/lib/base/application.h b/lib/base/application.h
index d693d00..3d1114a 100644
--- a/lib/base/application.h
+++ b/lib/base/application.h
@@ -48,6 +48,12 @@ public:
 	 */
 	virtual int Main(void) = 0;
 
+	static int GetArgC(void);
+	static void SetArgC(int argc);
+
+	static char **GetArgV(void);
+	static void SetArgV(char **argv);
+
 	static void InstallExceptionHandlers(void);
 
 	static void RequestShutdown(void);
@@ -89,7 +95,8 @@ private:
 
 	static bool m_ShuttingDown; /**< Whether the application is in the process of
 				  shutting down. */
-	vector<String> m_Arguments; /**< Command-line arguments */
+	static int m_ArgC; /**< The number of command-line arguments. */
+	static char **m_ArgV; /**< Command-line arguments. */
 	FILE *m_PidFile; /**< The PID file */
 	static bool m_Debugging; /**< Whether debugging is enabled. */
 	static boost::thread::id m_MainThreadID; /**< ID of the main thread. */
diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp
index b933159..4b54e73 100644
--- a/lib/python/pythonlanguage.cpp
+++ b/lib/python/pythonlanguage.cpp
@@ -29,7 +29,11 @@ PythonLanguage::PythonLanguage(void)
 	Py_Initialize();
 	PyEval_InitThreads();
 
-	//PySys_SetArgv(argc, argv);
+	Py_SetProgramName(Application::GetArgV()[0]);
+	PySys_SetArgv(Application::GetArgC(), Application::GetArgV());
+
+	// See http://docs.python.org/2/c-api/init.html for an explanation.
+	PyRun_SimpleString("import sys; sys.path.pop(0)\n");
 
 	m_MainThreadState = PyThreadState_Get();
 





More information about the icinga-checkins mailing list