Skip to content

Commit

Permalink
python plugin: modify sys.path only once
Browse files Browse the repository at this point in the history
Rather than appending to sys.path for every loaded plugin,
do it only once when initializing.

Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
jmberg authored and rostedt committed Jun 7, 2010
1 parent c3fb083 commit 7efc6c4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions plugin_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#define PYTHON_DIR .
#endif

static const char pyload[] =
static const char pypath[] =
"import sys\n"
"sys.path.append(\"" MAKE_STR(PYTHON_DIR) "\")\n"
"sys.path.append(\"" MAKE_STR(PYTHON_DIR) "\")\n";

static const char pyload[] =
"import imp, tracecmd, ctracecmd\n"
"fn = r'%s'\n"
"file = open(fn, 'r')\n"
Expand Down Expand Up @@ -55,13 +57,20 @@ static void load_plugin(struct pevent *pevent, const char *path,

int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
{
PyObject *globals, *m, *py_pevent, *str;
PyObject *globals, *m, *py_pevent, *str, *res;

Py_Initialize();

m = PyImport_AddModule("__main__");
globals = PyModule_GetDict(m);

res = PyRun_String(pypath, Py_file_input, globals, globals);
if (!res) {
PyErr_Print();
return -1;
} else
Py_DECREF(res);

str = PyString_FromString("pevent");
if (!str)
return -ENOMEM;
Expand Down

0 comments on commit 7efc6c4

Please sign in to comment.