From ba2052f92e76dfe28743aa19a4cc7dc4e098a99b Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:52:48 +0100 Subject: [PATCH 01/10] Fix crash looking up departed channel member Found by: BigBadWouf Patch by: michaelortmann Fixes: #1708 --- src/mod/irc.mod/chan.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mod/irc.mod/chan.c b/src/mod/irc.mod/chan.c index 2467b2d1b..7e57ffcfa 100644 --- a/src/mod/irc.mod/chan.c +++ b/src/mod/irc.mod/chan.c @@ -2240,7 +2240,7 @@ static int gotjoin(char *from, char *channame) */ static int gotpart(char *from, char *msg) { - char *nick, *chname, *key; + char *nick, *chname, uhost[UHOSTLEN], *key; struct chanset_t *chan; struct userrec *u; memberlist *m; @@ -2255,9 +2255,14 @@ static int gotpart(char *from, char *msg) return 0; } if (chan && !channel_pending(chan)) { + strlcpy(uhost, from, sizeof uhost); nick = splitnick(&from); m = ismember(chan, nick); - u = get_user_from_member(m); + // TODO: check account from rawt account-tags + if (m) + u = get_user_from_member(m); + else + u = get_user_by_host(uhost); if (!channel_active(chan)) { /* whoa! */ putlog(LOG_MISC, chan->dname, @@ -2276,7 +2281,8 @@ static int gotpart(char *from, char *msg) if (!chan) return 0; - killmember(chan, nick); + if (m) + killmember(chan, nick); if (msg[0]) putlog(LOG_JOIN, chan->dname, "%s (%s) left %s (%s).", nick, from, chan->dname, msg); From 1e5658408dbb60ffbbd84ec9641a22ff57431728 Mon Sep 17 00:00:00 2001 From: Johannes Kuhn Date: Sun, 1 Dec 2024 16:55:28 +0100 Subject: [PATCH 02/10] Fix bind log interpreter results Found by: DasBrain Patch by: DasBrain --- src/tclhash.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tclhash.c b/src/tclhash.c index 08d5ee631..0fb2e6cfc 100644 --- a/src/tclhash.c +++ b/src/tclhash.c @@ -1240,13 +1240,19 @@ void check_tcl_die(char *reason) void check_tcl_log(int lv, char *chan, char *msg) { char mask[512]; + Tcl_Obj* prev_result; + /* We have to store the old result, as check_tcl_bind may override it */ + prev_result = Tcl_GetObjResult(interp); + Tcl_IncrRefCount(prev_result); egg_snprintf(mask, sizeof mask, "%s %s", chan, msg); Tcl_SetVar(interp, "_log1", masktype(lv), TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "_log2", chan, TCL_GLOBAL_ONLY); Tcl_SetVar(interp, "_log3", msg, TCL_GLOBAL_ONLY); check_tcl_bind(H_log, mask, 0, " $::_log1 $::_log2 $::_log3", MATCH_MASK | BIND_STACKABLE); + Tcl_SetObjResult(interp, prev_result); + Tcl_DecrRefCount(prev_result); } #ifdef TLS From 1d4c00953638db806b3b57c97d0a39c65214e0a0 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:03:01 +0100 Subject: [PATCH 03/10] Fix crash when restarting with python.mod loaded Found by: aleksandrov89 Patch by: michaelortmann --- src/main.c | 2 +- src/mod/python.mod/Makefile.in | 5 ++--- src/mod/python.mod/python.c | 33 +++++++++++++-------------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main.c b/src/main.c index 42ddc61a6..2a24422b0 100644 --- a/src/main.c +++ b/src/main.c @@ -876,7 +876,7 @@ static void mainloop(int toplevel) if (strcmp(p->name, "eggdrop") && strcmp(p->name, "encryption") && strcmp(p->name, "encryption2") && strcmp(p->name, "uptime")) { f++; - debug1("stagnant module %s", p->name); + putlog(LOG_MISC, "*", "stagnant module %s", p->name); } } if (f != 0) { diff --git a/src/mod/python.mod/Makefile.in b/src/mod/python.mod/Makefile.in index bf1c0b622..b7282f311 100644 --- a/src/mod/python.mod/Makefile.in +++ b/src/mod/python.mod/Makefile.in @@ -41,6 +41,5 @@ distclean: clean ../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \ ../../../src/compat/explicit_bzero.h ../../../src/compat/strlcpy.h \ ../../../src/mod/modvals.h ../../../src/tandem.h \ - ../../../src/mod/irc.mod/irc.h ../../../src/mod/server.mod/server.h \ - .././python.mod/python.h .././python.mod/pycmds.c \ - .././python.mod/tclpython.c + ../../../src/mod/server.mod/server.h .././python.mod/python.h \ + .././python.mod/pycmds.c .././python.mod/tclpython.c diff --git a/src/mod/python.mod/python.c b/src/mod/python.mod/python.c index 254a4b7d5..bb6d7cf3d 100644 --- a/src/mod/python.mod/python.c +++ b/src/mod/python.mod/python.c @@ -33,7 +33,6 @@ #undef days #include #include -#include "src/mod/irc.mod/irc.h" #include "src/mod/server.mod/server.h" #include "python.h" @@ -41,7 +40,7 @@ static PyObject *pirp, *pglobals; #undef global -static Function *global = NULL, *irc_funcs = NULL; +static Function *global = NULL; static PyThreadState *_pythreadsave; #include "pycmds.c" #include "tclpython.c" @@ -141,33 +140,27 @@ static Function python_table[] = { char *python_start(Function *global_funcs) { char *s; + /* Assign the core function table. After this point you use all normal * functions defined in src/mod/modules.h */ - global = global_funcs; - - /* Register the module. */ - module_register(MODULE_NAME, python_table, 0, 1); - - if (!module_depend(MODULE_NAME, "eggdrop", 109, 0)) { - module_undepend(MODULE_NAME); - return "This module requires Eggdrop 1.9.0 or later."; - } - // TODO: Is this dependency necessary? It auto-loads irc.mod, that might be undesired - if (!(irc_funcs = module_depend(MODULE_NAME, "irc", 1, 5))) { - module_undepend(MODULE_NAME); - return "This module requires irc module 1.5 or later."; + if (global_funcs) { + global = global_funcs; + + /* Register the module. */ + module_register(MODULE_NAME, python_table, 0, 1); + if (!module_depend(MODULE_NAME, "eggdrop", 109, 0)) { + module_undepend(MODULE_NAME); + return "This module requires Eggdrop 1.9.0 or later."; + } + if ((s = init_python())) + return s; } - // irc.mod depends on server.mod and channels.mod, so those were implicitly loaded - - if ((s = init_python())) - return s; /* Add command table to bind list */ add_builtins(H_dcc, mydcc); add_tcl_commands(my_tcl_cmds); add_hook(HOOK_PRE_SELECT, (Function)python_gil_unlock); add_hook(HOOK_POST_SELECT, (Function)python_gil_lock); - return NULL; } From 9014477b68396275a81b7e4891fd4ed1455bb5f9 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:03:31 +0100 Subject: [PATCH 04/10] Fix compiler warning for make static Found by: michaelortmann Patch by: michaelortmann --- src/modules.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules.c b/src/modules.c index 0fd005760..5c703a298 100644 --- a/src/modules.c +++ b/src/modules.c @@ -695,7 +695,6 @@ int module_register(char *name, Function *funcs, int major, int minor) const char *module_load(char *name) { - size_t len; module_entry *p; char *e; Function f; @@ -704,6 +703,7 @@ const char *module_load(char *name) #endif #ifndef STATIC + size_t len; char workbuf[PATH_MAX]; # ifdef MOD_USE_SHL shl_t hand; From caa08edbec74fc98bdb204a46b8d6e7cf08c85f6 Mon Sep 17 00:00:00 2001 From: crazycatdevs <44431938+crazycatdevs@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:04:21 +0100 Subject: [PATCH 05/10] Correct mod-path variable Found by: CrazyCat Patch by: CrazyCat In Modules section, path was referenced as module-path when it's mod-path --- doc/sphinx_source/using/core.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sphinx_source/using/core.rst b/doc/sphinx_source/using/core.rst index f192c3cac..8c1e88e8f 100644 --- a/doc/sphinx_source/using/core.rst +++ b/doc/sphinx_source/using/core.rst @@ -589,7 +589,7 @@ Modules After the core settings, you should start loading modules. Modules are loaded by the command "loadmodule ". Eggdrop looks for modules -in the directory you specified by the module-path setting in the files +in the directory you specified by the mod-path setting in the files and directories section. Please note that for different configurations, different modules are needed. From 14c181bb02d1cd99c4755d2f2ee65f40d47c6d82 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:10:38 +0100 Subject: [PATCH 06/10] Fix python thread Found by: Empus Patch by: thommey and michaelortmann Fixes [20:20:20] !!! writing to nonexistent socket: 9 when using putlog() or other functions using sockets not available via thread local storage returned via threaddata() in python thread the underlying idea is that the dccsockets etc. of the main thread are separated from the one in Tcl threads because that is necessary. From Python however, it should be (famous last words) safe to access the main thread's socket table, so this PR makes it globally accessible, with only Tcl threads having their own. The safety requirement is that Python is only called when the main thread isn't operating on them and right now, Python is only called during Tcl binds and in select(). --- src/tcl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tcl.c b/src/tcl.c index 5bc135b35..949fc5842 100644 --- a/src/tcl.c +++ b/src/tcl.c @@ -615,10 +615,14 @@ int tclthreadmainloop(int zero) return (i == -5); } +struct threaddata *td_main = 0; + struct threaddata *threaddata() { static Tcl_ThreadDataKey tdkey; struct threaddata *td = Tcl_GetThreadData(&tdkey, sizeof(struct threaddata)); + if (!(td->mainloopfunc) && td_main) /* python thread */ + return td_main; return td; } @@ -638,6 +642,8 @@ void init_threaddata(int mainthread) td->blocktime.tv_usec = 0; td->MAXSOCKS = 0; increase_socks_max(); + if (mainthread) + td_main = td; } /* workaround for Tcl that does not support unicode outside BMP (3 byte utf-8 characters) */ From 1effc20f6094d2e4ef89d9750f207723849d6960 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:15:04 +0100 Subject: [PATCH 07/10] Add .clangd to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 37ee0f2d9..ad58b54d0 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ eggdrop EGGMOD.stamp mod.xlibs __pycache__ +.clangd From a5f1d6734b7a1aafa818405c9bc56460dd412b4d Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:17:09 +0100 Subject: [PATCH 08/10] Fix format-truncation warning Found by: Geo Patch by: michaelortmann --- src/dns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dns.c b/src/dns.c index 863d40c33..a47f53bcf 100644 --- a/src/dns.c +++ b/src/dns.c @@ -565,7 +565,8 @@ void *thread_dns_ipbyhost(void *arg) else if (error == EAI_NONAME) snprintf(dtn->strerror, sizeof dtn->strerror, "dns: thread_dns_ipbyhost(): getaddrinfo(): not known"); else if (error == EAI_SYSTEM) { - snprintf(dtn->strerror, sizeof dtn->strerror, "dns: thread_dns_ipbyhost(): getaddrinfo(): %s: %s", gai_strerror(error), strerror(errno)); + /* print raw errno, dont use strerror() in thread and dont use strerror_r() due to GNU / POSIX portability complexity */ + snprintf(dtn->strerror, sizeof dtn->strerror, "dns: thread_dns_ipbyhost(): getaddrinfo(): %s: errno %i", gai_strerror(error), errno); } else snprintf(dtn->strerror, sizeof dtn->strerror, "dns: thread_dns_ipbyhost(): getaddrinfo(): %s", gai_strerror(error)); close(dtn->fildes[1]); From 0c036871ea6127420cc7a1427fef1b960677945b Mon Sep 17 00:00:00 2001 From: Geo Date: Sun, 1 Dec 2024 11:18:49 -0500 Subject: [PATCH 09/10] Update patchlevel to pythonfixes --- src/version.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 3898c7449..3fdfdc745 100644 --- a/src/version.h +++ b/src/version.h @@ -27,4 +27,5 @@ */ #define EGG_STRINGVER "1.10.0" -#define EGG_NUMVER 1100003 +#define EGG_NUMVER 1100005 +#define EGG_PATCH pythonfixes From 0f5599e1fafa97454dc7a8b147c6076638e95ba8 Mon Sep 17 00:00:00 2001 From: Geo Date: Sun, 1 Dec 2024 11:32:01 -0500 Subject: [PATCH 10/10] Update patchlevel --- src/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 3fdfdc745..c446bfadf 100644 --- a/src/version.h +++ b/src/version.h @@ -28,4 +28,4 @@ #define EGG_STRINGVER "1.10.0" #define EGG_NUMVER 1100005 -#define EGG_PATCH pythonfixes +#define EGG_PATCH "pythonfixes"