plugins/python/debug: adapt debug refcount solution of sudoers plugin
This commit is contained in:

committed by
Todd C. Miller

parent
a0c2de4cef
commit
8a9218d161
@@ -413,10 +413,11 @@ python_plugin_deinit(struct PluginContext *plugin_ctx)
|
||||
Py_Finalize();
|
||||
}
|
||||
|
||||
python_debug_deregister();
|
||||
py_ctx_reset();
|
||||
}
|
||||
|
||||
python_debug_deregister();
|
||||
|
||||
debug_return;
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,7 @@
|
||||
|
||||
|
||||
static int python_debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
|
||||
static unsigned int python_debug_refcnt;
|
||||
|
||||
static const char *const python_subsystem_names[] = {
|
||||
"py_calls", // logs c -> py calls
|
||||
@@ -79,20 +80,14 @@ bool
|
||||
python_debug_register(const char *program,
|
||||
struct sudo_conf_debug_file_list *debug_files)
|
||||
{
|
||||
int instance = python_debug_instance;
|
||||
struct sudo_debug_file *debug_file, *debug_next;
|
||||
|
||||
/* Already initialized? */
|
||||
if (python_debug_instance != SUDO_DEBUG_INSTANCE_INITIALIZER) {
|
||||
sudo_debug_set_active_instance(python_debug_instance);
|
||||
}
|
||||
|
||||
/* Setup debugging if indicated. */
|
||||
if (debug_files != NULL && !TAILQ_EMPTY(debug_files)) {
|
||||
if (program != NULL) {
|
||||
python_debug_instance = sudo_debug_register(program,
|
||||
python_subsystem_names, (unsigned int *)python_subsystem_ids, debug_files);
|
||||
if (python_debug_instance == SUDO_DEBUG_INSTANCE_ERROR)
|
||||
return false;
|
||||
instance = sudo_debug_register(program, python_subsystem_names,
|
||||
(unsigned int *)python_subsystem_ids, debug_files);
|
||||
}
|
||||
TAILQ_FOREACH_SAFE(debug_file, debug_files, entries, debug_next) {
|
||||
TAILQ_REMOVE(debug_files, debug_file, entries);
|
||||
@@ -101,6 +96,21 @@ python_debug_register(const char *program,
|
||||
free(debug_file);
|
||||
}
|
||||
}
|
||||
|
||||
switch (instance) {
|
||||
case SUDO_DEBUG_INSTANCE_ERROR:
|
||||
return false;
|
||||
case SUDO_DEBUG_INSTANCE_INITIALIZER:
|
||||
/* Nothing to do */
|
||||
break;
|
||||
default:
|
||||
/* New debug instance or additional reference on existing one. */
|
||||
python_debug_instance = instance;
|
||||
sudo_debug_set_active_instance(python_debug_instance);
|
||||
python_debug_refcnt++;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -112,9 +122,11 @@ python_debug_deregister(void)
|
||||
{
|
||||
debug_decl(python_debug_deregister, PYTHON_DEBUG_INTERNAL);
|
||||
|
||||
if (python_debug_instance != SUDO_DEBUG_INSTANCE_INITIALIZER) {
|
||||
if (python_debug_refcnt != 0) {
|
||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
||||
sudo_debug_deregister(python_debug_instance);
|
||||
if (--python_debug_refcnt == 0) {
|
||||
if (sudo_debug_deregister(python_debug_instance) < 1)
|
||||
python_debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user