MODRESTART/MODRELOAD: Defer reloading more quickly

Commit 41390bfe5f fixed a bug whereby the processing
of a MODRESTART command could result in a crash. The approach
taken in this fix was to defer the reloading of all modules
so that the call stack does not contain functions located in
modules that are being reloaded. It did this by scheduling a
one-shot timer event for 1 second in the future, in the absense
of any better deferral mechanism at the time. Timers are
processed by the event loop, which is core to IRCd and cannot
be reloaded.

Commit 59ea3c6753 introduced a mechanism to defer the
execution of a function until all events have been processed by
the event loop, in order to fix a REHASH bug that could result
in a crash due to closing and reopening listener sockets with a
pending socket connection event to process after the REHASH was
completed.

Rework commit 41390bfe5f to use the new deferral
mechanism introduced by commit 59ea3c6753 and do the
same for module reloads.
This commit is contained in:
Aaron Jones 2023-11-19 11:47:24 +00:00
parent eaf922d427
commit a9505057c5

View file

@ -286,7 +286,7 @@ do_modreload(struct Client *source_p, const char *module)
struct modreload *info = rb_malloc(sizeof *info); struct modreload *info = rb_malloc(sizeof *info);
strcpy(info->module, module); strcpy(info->module, module);
strcpy(info->id, source_p->id); strcpy(info->id, source_p->id);
rb_event_addonce("modules_do_reload", modules_do_reload, info, 1); rb_defer(&modules_do_reload, info);
} }
static void static void
@ -304,7 +304,7 @@ do_modrestart(struct Client *source_p)
* *
* So, defer the restart to the event loop and return now. * So, defer the restart to the event loop and return now.
*/ */
rb_event_addonce("modules_do_restart", modules_do_restart, NULL, 1); rb_defer(&modules_do_restart, NULL);
} }
static void static void