Browse Source

[core] filter out duplicate modules

filter out modules duplicated in server.modules list
master
Glenn Strauss 2 months ago
parent
commit
78ec2b5b68
2 changed files with 38 additions and 28 deletions
  1. +32
    -0
      src/configfile.c
  2. +6
    -28
      src/plugin.c

+ 32
- 0
src/configfile.c View File

@ -288,6 +288,36 @@ static void config_warn_openssl_module (server *srv) {
}
#endif
static void config_check_module_duplicates (server *srv) {
int dup = 0;
data_string ** const data = (data_string **)srv->srvconf.modules->data;
const uint32_t used = srv->srvconf.modules->used;
for (uint32_t i = 0; i < used; ++i) {
const buffer * const m = &data[i]->value;
for (uint32_t j = i+1; j < used; ++j) {
if (buffer_is_equal(m, &data[j]->value)) {
++dup;
break;
}
}
}
if (!dup) return;
array * const modules = array_init(used - dup);
for (uint32_t i = 0; i < used; ++i) {
const buffer * const m = &data[i]->value;
uint32_t j;
for (j = 0; j < modules->used; ++j) {
buffer *n = &((data_string *)modules->data[j])->value;
if (buffer_is_equal(m, n)) break; /* duplicate */
}
if (j == modules->used)
array_insert_value(modules, CONST_BUF_LEN(m));
}
array_free(srv->srvconf.modules);
srv->srvconf.modules = modules;
}
static void config_compat_module_load (server *srv) {
int prepend_mod_indexfile = 1;
int append_mod_dirlisting = 1;
@ -807,6 +837,8 @@ static int config_insert_srvconf(server *srv) {
if (0 == srv->srvconf.port)
srv->srvconf.port = ssl_enabled ? 443 : 80;
config_check_module_duplicates(srv);
if (srv->srvconf.compat_module_load)
config_compat_module_load(srv);


+ 6
- 28
src/plugin.c View File

@ -130,16 +130,6 @@ int plugins_load(server *srv) {
char *module = ds->value.ptr;
uint32_t j;
for (j = 0; j < i; ++j) {
if (buffer_is_equal(&ds->value, &((data_string *) srv->srvconf.modules->data[j])->value)) {
log_error(srv->errh, __FILE__, __LINE__,
"Cannot load plugin %s "
"more than once, please fix your config (lighttpd may not accept such configs in future releases)",
ds->value.ptr);
continue;
}
}
for (j = 0; load_functions[j].name; ++j) {
if (0 == strcmp(load_functions[j].name, module)) {
plugin * const p = plugin_init();
@ -165,26 +155,14 @@ int plugins_load(server *srv) {
buffer * const tb = srv->tmp_buf;
plugin *p;
int (*init)(plugin *pl);
size_t i, j;
for (i = 0; i < srv->srvconf.modules->used; i++) {
data_string *ds = (data_string *)srv->srvconf.modules->data[i];
char *module = ds->value.ptr;
for (j = 0; j < i; j++) {
if (buffer_is_equal(&ds->value, &((data_string *) srv->srvconf.modules->data[j])->value)) {
log_error(srv->errh, __FILE__, __LINE__,
"Cannot load plugin %s "
"more than once, please fix your config (lighttpd may not accept such configs in future releases)",
ds->value.ptr);
continue;
}
}
for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) {
const buffer * const module = &((data_string *)srv->srvconf.modules->data[i])->value;
buffer_copy_buffer(tb, srv->srvconf.modules_dir);
buffer_append_string_len(tb, CONST_STR_LEN("/"));
buffer_append_string(tb, module);
buffer_append_string_buffer(tb, module);
#if defined(__WIN32) || defined(__CYGWIN__)
buffer_append_string_len(tb, CONST_STR_LEN(".dll"));
#else
@ -223,7 +201,7 @@ int plugins_load(server *srv) {
}
#endif
buffer_copy_string(tb, module);
buffer_copy_buffer(tb, module);
buffer_append_string_len(tb, CONST_STR_LEN("_plugin_init"));
#ifdef __WIN32
@ -267,13 +245,13 @@ int plugins_load(server *srv) {
#endif
if ((*init)(p)) {
log_error(srv->errh, __FILE__, __LINE__, "%s plugin init failed", module);
log_error(srv->errh, __FILE__, __LINE__, "%s plugin init failed", module->ptr);
plugin_free(p);
return -1;
}
#if 0
log_error(srv->errh, __FILE__, __LINE__, "%s plugin loaded", module);
log_error(srv->errh, __FILE__, __LINE__, "%s plugin loaded", module->ptr);
#endif
plugins_register(srv, p);
}


Loading…
Cancel
Save