plugins/python: only deinit interpreters when sudo unlinks the plugin

This only happens when sudo unloads the last python plugin.
The reason doing so is because there are some python modules which
does not support importing them again after destroying the interpreter
which has imported them previously.

Another solution would be to just leak the interpreters (let the kernel
free up), but then there might be some python resources like open files
would not get cleaned up correctly if the plugin is badly written.

Tests are meant to test the scenario sudo does, so I have modified them
to generally do not unlink but only a few times (~per plugin type) so it
does not use 48 interpreters (one gets started on every plugin->open) and
it is visible at least which type of plugin fails deinit if there is an
error.
This commit is contained in:
Robert Manner
2020-02-17 16:16:04 +01:00
committed by Todd C. Miller
parent 8a9218d161
commit 27de7dd24d
6 changed files with 124 additions and 47 deletions

View File

@@ -38,12 +38,15 @@ enum SudoPluginFunctionReturnCode {
SUDO_RC_USAGE_ERROR = -2,
};
#define INTERPRETER_MAX 32
struct PythonContext
{
sudo_printf_t sudo_log;
sudo_conv_t sudo_conv;
int open_plugin_count;
PyThreadState *py_main_interpreter;
size_t interpreter_count;
PyThreadState *py_subinterpreters[INTERPRETER_MAX];
};
extern struct PythonContext py_ctx;