From 9159f9b99ae6fd4bf7eb31fab804207da57961f0 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:55:18 +0200 Subject: [PATCH 1/4] Forbid reloading of python mod (it would crash the bot) --- src/mod/python.mod/python.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mod/python.mod/python.c b/src/mod/python.mod/python.c index c4221efac..2bf10a387 100644 --- a/src/mod/python.mod/python.c +++ b/src/mod/python.mod/python.c @@ -137,7 +137,14 @@ static Function python_table[] = { char *python_start(Function *global_funcs) { + static int forbid_reload = 0; char *s; + + if (forbid_reload) + /* Reloading, reexecuting PyDateTime_IMPORT, would crash */ + return "You can't reload the " MODULE_NAME " module (it would crash the bot)"; + forbid_reload = 1; + /* Assign the core function table. After this point you use all normal * functions defined in src/mod/modules.h */ From 6adc7d382fba80b4f4511583dd275d03c34ee5f4 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:12:34 +0200 Subject: [PATCH 2/4] later --- src/mod/python.mod/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/python.mod/python.c b/src/mod/python.mod/python.c index 2bf10a387..a040e313e 100644 --- a/src/mod/python.mod/python.c +++ b/src/mod/python.mod/python.c @@ -143,7 +143,6 @@ char *python_start(Function *global_funcs) if (forbid_reload) /* Reloading, reexecuting PyDateTime_IMPORT, would crash */ return "You can't reload the " MODULE_NAME " module (it would crash the bot)"; - forbid_reload = 1; /* Assign the core function table. After this point you use all normal * functions defined in src/mod/modules.h @@ -164,6 +163,7 @@ char *python_start(Function *global_funcs) } // irc.mod depends on server.mod and channels.mod, so those were implicitely loaded + forbid_reload = 1; if ((s = init_python())) return s; From e8a96968d84678d0b8e19c5bf31cbc9fa380be2a Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:02:34 +0200 Subject: [PATCH 3/4] Forbid unload --- src/mod/python.mod/python.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/mod/python.mod/python.c b/src/mod/python.mod/python.c index a040e313e..62625943f 100644 --- a/src/mod/python.mod/python.c +++ b/src/mod/python.mod/python.c @@ -104,13 +104,6 @@ static char *init_python() { return NULL; } -static void kill_python() { - if (Py_FinalizeEx() < 0) { - exit(120); - } - return; -} - static void python_report(int idx, int details) { if (details) @@ -119,13 +112,12 @@ static void python_report(int idx, int details) static char *python_close() { - del_hook(HOOK_PRE_SELECT, (Function)python_gil_unlock); - del_hook(HOOK_POST_SELECT, (Function)python_gil_lock); - kill_python(); - rem_builtins(H_dcc, mydcc); - rem_tcl_commands(my_tcl_cmds); - module_undepend(MODULE_NAME); - return NULL; + /* Forbid unloading, because: + * - Reloading (Reexecuting PyDateTime_IMPORT) would crash + * - Py_FinalizeEx() does not clean up everything + * - Complexity regarding running python threads + */ + return "The " MODULE_NAME " module is not allowed to be unloaded."; } static Function python_table[] = { @@ -137,13 +129,7 @@ static Function python_table[] = { char *python_start(Function *global_funcs) { - static int forbid_reload = 0; char *s; - - if (forbid_reload) - /* Reloading, reexecuting PyDateTime_IMPORT, would crash */ - return "You can't reload the " MODULE_NAME " module (it would crash the bot)"; - /* Assign the core function table. After this point you use all normal * functions defined in src/mod/modules.h */ @@ -163,7 +149,6 @@ char *python_start(Function *global_funcs) } // irc.mod depends on server.mod and channels.mod, so those were implicitely loaded - forbid_reload = 1; if ((s = init_python())) return s; From 120ca580b5cd2b56f9e9560b98e0c3395d91e508 Mon Sep 17 00:00:00 2001 From: Thomas Sader Date: Sat, 13 Jul 2024 00:04:50 +0200 Subject: [PATCH 4/4] Update src/mod/python.mod/python.c --- src/mod/python.mod/python.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/python.mod/python.c b/src/mod/python.mod/python.c index 62625943f..5003cd59f 100644 --- a/src/mod/python.mod/python.c +++ b/src/mod/python.mod/python.c @@ -116,6 +116,7 @@ static char *python_close() * - Reloading (Reexecuting PyDateTime_IMPORT) would crash * - Py_FinalizeEx() does not clean up everything * - Complexity regarding running python threads + * see https://bugs.python.org/issue34309 for details */ return "The " MODULE_NAME " module is not allowed to be unloaded."; }