diff options
| author | Johannes Berg <johannes@sipsolutions.net> | 2010-06-07 04:47:31 -0400 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2010-06-07 10:04:53 -0400 |
| commit | 7efc6c46b8eddf711060c542df17b9269d559db4 (patch) | |
| tree | 2a53059366201618e8cd3bae0d02e1f1b9092a8a | |
| parent | c3fb083d902e20a764a8d46a1fcfaede67df570b (diff) | |
python plugin: modify sys.path only once
Rather than appending to sys.path for every loaded plugin,
do it only once when initializing.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | plugin_python.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/plugin_python.c b/plugin_python.c index 0f52bb3..74a4cfe 100644 --- a/plugin_python.c +++ b/plugin_python.c | |||
| @@ -6,9 +6,11 @@ | |||
| 6 | #define PYTHON_DIR . | 6 | #define PYTHON_DIR . |
| 7 | #endif | 7 | #endif |
| 8 | 8 | ||
| 9 | static const char pyload[] = | 9 | static const char pypath[] = |
| 10 | "import sys\n" | 10 | "import sys\n" |
| 11 | "sys.path.append(\"" MAKE_STR(PYTHON_DIR) "\")\n" | 11 | "sys.path.append(\"" MAKE_STR(PYTHON_DIR) "\")\n"; |
| 12 | |||
| 13 | static const char pyload[] = | ||
| 12 | "import imp, tracecmd, ctracecmd\n" | 14 | "import imp, tracecmd, ctracecmd\n" |
| 13 | "fn = r'%s'\n" | 15 | "fn = r'%s'\n" |
| 14 | "file = open(fn, 'r')\n" | 16 | "file = open(fn, 'r')\n" |
| @@ -55,13 +57,20 @@ static void load_plugin(struct pevent *pevent, const char *path, | |||
| 55 | 57 | ||
| 56 | int PEVENT_PLUGIN_LOADER(struct pevent *pevent) | 58 | int PEVENT_PLUGIN_LOADER(struct pevent *pevent) |
| 57 | { | 59 | { |
| 58 | PyObject *globals, *m, *py_pevent, *str; | 60 | PyObject *globals, *m, *py_pevent, *str, *res; |
| 59 | 61 | ||
| 60 | Py_Initialize(); | 62 | Py_Initialize(); |
| 61 | 63 | ||
| 62 | m = PyImport_AddModule("__main__"); | 64 | m = PyImport_AddModule("__main__"); |
| 63 | globals = PyModule_GetDict(m); | 65 | globals = PyModule_GetDict(m); |
| 64 | 66 | ||
| 67 | res = PyRun_String(pypath, Py_file_input, globals, globals); | ||
| 68 | if (!res) { | ||
| 69 | PyErr_Print(); | ||
| 70 | return -1; | ||
| 71 | } else | ||
| 72 | Py_DECREF(res); | ||
| 73 | |||
| 65 | str = PyString_FromString("pevent"); | 74 | str = PyString_FromString("pevent"); |
| 66 | if (!str) | 75 | if (!str) |
| 67 | return -ENOMEM; | 76 | return -ENOMEM; |
