Skip to content

Commit 23d0c7d

Browse files
committed
Automatically rehash when modules change conf
When loading a module that modifies config (add/remove conf items or top conf sections), we now queue a rehash operation so that new config can be immediately applied. A new rb_defer_once() function was added to deduplicate these rehash requests so that at most one rehash will occur regardless of how many modules change conf.
1 parent 54286cf commit 23d0c7d

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

include/s_conf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ extern unsigned long cidr_to_bitmask[];
419419
extern char conffilebuf[BUFSIZE + 1];
420420
extern int lineno;
421421

422+
extern bool conf_changed;
423+
422424
#define NOT_AUTHORISED (-1)
423425
#define I_SOCKET_ERROR (-2)
424426
#define I_LINE_FULL (-3)

ircd/modules.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ load_a_module(const char *path, bool warn, int origin, bool core)
571571
return false;
572572
}
573573

574+
/* flag to determine if a rehash is needed after this module load */
575+
conf_changed = false;
576+
574577
switch (MAPI_VERSION(*mapi_version))
575578
{
576579
case 1:
@@ -761,6 +764,10 @@ load_a_module(const char *path, bool warn, int origin, bool core)
761764
mod->path = rb_strdup(path);
762765
rb_dlinkAddTail(mod, &mod->node, &module_list);
763766

767+
/* queue a rehash if the conf changed */
768+
if (conf_changed)
769+
rehash(0);
770+
764771
if(warn)
765772
{
766773
const char *o;

ircd/newconf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ add_top_conf(const char *name, int (*sfunc) (struct TopConf *),
105105
tc->tc_entries = items;
106106

107107
rb_dlinkAddAlloc(tc, &conf_items);
108+
conf_changed = true;
108109
return 0;
109110
}
110111

@@ -168,6 +169,7 @@ remove_top_conf(char *name)
168169

169170
rb_dlinkDestroy(ptr, &conf_items);
170171
rb_free(tc);
172+
conf_changed = true;
171173

172174
return 0;
173175
}
@@ -2553,6 +2555,7 @@ add_conf_item(const char *topconf, const char *name, int type, void (*func) (voi
25532555
cf->cf_arg = NULL;
25542556

25552557
rb_dlinkAddAlloc(cf, &tc->tc_items);
2558+
conf_changed = true;
25562559

25572560
return 0;
25582561
}
@@ -2575,6 +2578,7 @@ remove_conf_item(const char *topconf, const char *name)
25752578

25762579
rb_dlinkDestroy(ptr, &tc->tc_items);
25772580
rb_free(cf);
2581+
conf_changed = true;
25782582

25792583
return 0;
25802584
}

ircd/s_conf.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ rb_dlink_list service_list;
6767

6868
rb_dictionary *prop_bans_dict;
6969

70+
/* used for automatic rehash after loading a module which changes config */
71+
bool conf_changed = false;
72+
7073
/* internally defined functions */
7174
static void set_default_conf(void);
7275
static void validate_conf(void);
@@ -623,14 +626,15 @@ struct rehash_data {
623626
bool sig;
624627
};
625628

629+
static struct rehash_data rehash_sig = { true };
630+
static struct rehash_data rehash_no_sig = { false };
631+
626632
static void
627633
service_rehash(void *data_)
628634
{
629635
struct rehash_data *data = data_;
630636
bool sig = data->sig;
631637

632-
rb_free(data);
633-
634638
rb_dlink_node *n;
635639

636640
hook_data_rehash hdata = { sig };
@@ -675,9 +679,7 @@ service_rehash(void *data_)
675679
bool
676680
rehash(bool sig)
677681
{
678-
struct rehash_data *data = rb_malloc(sizeof *data);
679-
data->sig = sig;
680-
rb_defer(service_rehash, data);
682+
rb_defer_once(service_rehash, sig ? &rehash_sig : &rehash_no_sig);
681683
return false;
682684
}
683685

librb/include/rb_commio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ void rb_setselect(rb_fde_t *, unsigned int type, PF * handler, void *client_data
160160
void rb_init_netio(void);
161161
int rb_select(unsigned long);
162162
void rb_defer(void (*)(void *), void *);
163+
void rb_defer_once(void (*)(void *), void *);
163164
int rb_fd_ssl(rb_fde_t *F);
164165
int rb_get_fd(rb_fde_t *F);
165166
const char *rb_get_ssl_strerror(rb_fde_t *F);

librb/src/commio.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,20 @@ rb_defer(void (*fn)(void *), void *data)
20322032
rb_dlinkAdd(defer, &defer->node, &defer_list);
20332033
}
20342034

2035+
void
2036+
rb_defer_once(void (*fn)(void *), void *data)
2037+
{
2038+
rb_dlink_node *ptr;
2039+
RB_DLINK_FOREACH(ptr, defer_list.head)
2040+
{
2041+
struct defer *node = ptr->data;
2042+
if (node->fn == fn && node->data == data)
2043+
return;
2044+
}
2045+
2046+
rb_defer(fn, data);
2047+
}
2048+
20352049
int
20362050
rb_select(unsigned long timeout)
20372051
{

0 commit comments

Comments
 (0)