Append full module path if it is a directory.

This commit is contained in:
Joris Vink 2019-03-16 16:13:52 +01:00
parent 31b6365da3
commit c3ab570f56
1 changed files with 12 additions and 0 deletions

View File

@ -17,6 +17,7 @@
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/un.h>
@ -1369,9 +1370,16 @@ python_kore_proc(PyObject *self, PyObject *args)
static PyObject *
python_import(const char *path)
{
struct stat st;
PyObject *module;
char *dir, *file, *copy, *p;
if (stat(path, &st) == -1)
fatal("python_import: stat(%s): %s", path, errno_s);
if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
fatal("python_import: '%s' is not a file or directory", path);
copy = kore_strdup(path);
if ((file = basename(copy)) == NULL)
@ -1383,6 +1391,10 @@ python_import(const char *path)
*p = '\0';
python_append_path(dir);
if (S_ISDIR(st.st_mode))
python_append_path(path);
module = PyImport_ImportModule(file);
if (module == NULL)
PyErr_Print();