diff --git a/include/h.h b/include/h.h index 914dc0460..0df2e9230 100644 --- a/include/h.h +++ b/include/h.h @@ -452,7 +452,7 @@ extern void report_dynconf(Client *client); extern void count_memory(Client *cptr, char *nick); extern void list_scache(Client *client); extern char *oflagstr(long oflag); -extern int rehash(Client *client, int sig); +extern void request_rehash(Client *client); extern void s_die(); extern int match_simple(const char *mask, const char *name); extern int match_esc(const char *mask, const char *name); diff --git a/include/struct.h b/include/struct.h index cbd8a4578..e46982bc6 100644 --- a/include/struct.h +++ b/include/struct.h @@ -864,7 +864,6 @@ struct LoopStruct { unsigned config_load_failed : 1; unsigned tainted : 1; Client *rehash_save_client; - int rehash_save_sig; void (*boot_function)(); }; diff --git a/src/conf.c b/src/conf.c index f09341555..a1c31a346 100644 --- a/src/conf.c +++ b/src/conf.c @@ -259,7 +259,7 @@ void update_remote_include(ConfigItem_include *inc, const char *file, int, const int remote_include(ConfigEntry *ce); #endif void free_all_includes(void); -int rehash_internal(Client *client, int sig); +int rehash_internal(Client *client); int is_blacklisted_module(char *name); /** Return the printable string of a 'cep' location, such as set::something::xyz */ @@ -10713,42 +10713,51 @@ static void conf_download_complete(const char *url, const char *file, const char * startup loop where it also checks is_config_read_finished(). */ if (loop.rehashing && is_config_read_finished()) - rehash_internal(loop.rehash_save_client, loop.rehash_save_sig); + rehash_internal(loop.rehash_save_client); } #endif -int rehash(Client *client, int sig) +/** Request to REHASH the configuration file. + * There is no guarantee that the request will be done immediately + * (eg: it won't in case of remote includes). + * @param client The client requesting the /REHASH. + * If this is NULL then the rehash was requested + * via a signal to the process or GUI. + */ +void request_rehash(Client *client) { #ifdef USE_LIBCURL ConfigItem_include *inc; char found_remote = 0; if (loop.rehashing) { - if (!sig) + if (client) sendnotice(client, "A rehash is already in progress"); - return 0; + return; } loop.rehashing = 1; loop.rehash_save_client = client; - loop.rehash_save_sig = sig; config_read_start(); /* If we already have everything, then can we proceed with the rehash */ if (is_config_read_finished()) - return rehash_internal(client, sig); - /* Otherwise, return here, I/O events will take care of it later + { + rehash_internal(client); + return; + } + /* Otherwise, I/O events will take care of it later * after all remote includes have been downloaded. */ - return 0; #else loop.rehashing = 1; - return rehash_internal(client, sig); + rehash_internal(client); #endif } -int rehash_internal(Client *client, int sig) +int rehash_internal(Client *client) { - if (sig == 1) + /* Log it here if it is by a signal */ + if (client == NULL) unreal_log(ULOG_INFO, "config", "CONFIG_RELOAD", client, "Rehashing server configuration file [./unrealircd rehash]"); loop.rehashing = 1; /* double checking.. */ diff --git a/src/ircd.c b/src/ircd.c index 48373f7c0..d47c96f52 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -1241,7 +1241,7 @@ void SocketLoop(void *dummy) */ if (dorehash) { - (void)rehash(&me, 1); + request_rehash(NULL); dorehash = 0; } if (dorestart) diff --git a/src/serv.c b/src/serv.c index 50ff4d3af..9af8d4a89 100644 --- a/src/serv.c +++ b/src/serv.c @@ -508,7 +508,7 @@ extern void reinit_resolver(Client *client); */ CMD_FUNC(cmd_rehash) { - int x = 0; + int x; /* This is one of the (few) commands that cannot be handled * by labeled-response accurately in all circumstances. @@ -643,7 +643,7 @@ CMD_FUNC(cmd_rehash) /* Normal rehash, rehash motds&rules too, just like the on in the tld block will :p */ sendnumeric(client, RPL_REHASHING, configfile); - x = rehash(client, 0); + request_rehash(client); } /** RESTART command - restart the server (discouraged command) diff --git a/src/windows/gui.c b/src/windows/gui.c index cba50010b..0bcaf78b1 100644 --- a/src/windows/gui.c +++ b/src/windows/gui.c @@ -581,13 +581,12 @@ LRESULT CALLBACK MainDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case IDM_RHALL: MessageBox(NULL, "Rehashing all files", "Rehashing", MB_OK); sendto_realops("Rehashing all files via the console"); - rehash(&me,0); - reread_motdsandrules(); + request_rehash(NULL); break; case IDM_RHCONF: MessageBox(NULL, "Rehashing the Config file", "Rehashing", MB_OK); sendto_realops("Rehashing the Config file via the console"); - rehash(&me,0); + request_rehash(NULL); break; case IDM_RHMOTD: { diff --git a/src/windows/service.c b/src/windows/service.c index dc76411d8..d4dafb49a 100644 --- a/src/windows/service.c +++ b/src/windows/service.c @@ -77,8 +77,7 @@ VOID WINAPI IRCDCtrlHandler(DWORD opcode) /* Rehash */ else if (opcode == IRCD_SERVICE_CONTROL_REHASH) { - rehash(&me,0); - reread_motdsandrules(); + request_rehash(NULL); } SetServiceStatus(IRCDStatusHandle, &IRCDStatus);