check module name when update plugin

This commit is contained in:
xiang.zhou
2024-03-06 09:05:04 +08:00
parent 45fa293fbc
commit 26e480982d
5 changed files with 67 additions and 1 deletions
+29
View File
@@ -511,6 +511,35 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
break;
}
if (!neu_plugin_manager_create_instance_by_lib_name(
manager->plugin_manager, cmd->library, &ins)) {
nlog_warn("library %s not instance", cmd->library);
free(cmd->so_file);
free(cmd->schema_file);
free(so_tmp_path);
header->type = NEU_RESP_ERROR;
e.error = NEU_ERR_LIBRARY_UPDATE_FAIL;
strcpy(header->receiver, header->sender);
reply(manager, header, &e);
break;
}
if (strcmp(module_name, ins.module->module_name) != 0) {
nlog_warn("library %s module name mismatch!", cmd->library);
neu_plugin_manager_destroy_instance(manager->plugin_manager,
&ins);
free(cmd->so_file);
free(cmd->schema_file);
free(so_tmp_path);
header->type = NEU_RESP_ERROR;
e.error = NEU_ERR_LIBRARY_UPDATE_FAIL;
strcpy(header->receiver, header->sender);
reply(manager, header, &e);
break;
}
neu_plugin_manager_destroy_instance(manager->plugin_manager, &ins);
if (!neu_plugin_manager_exists(manager->plugin_manager,
module_name)) {
+32
View File
@@ -489,6 +489,38 @@ bool neu_plugin_manager_create_instance_by_path(neu_plugin_manager_t *mgr,
return true;
}
bool neu_plugin_manager_create_instance_by_lib_name(
neu_plugin_manager_t *mgr, const char *lib_name,
neu_plugin_instance_t *instance)
{
(void) mgr;
char lib_paths[3][64] = { 0 };
snprintf(lib_paths[0], sizeof(lib_paths[0]), "%s", g_plugin_dir);
snprintf(lib_paths[1], sizeof(lib_paths[1]), "%s/system", g_plugin_dir);
snprintf(lib_paths[2], sizeof(lib_paths[2]), "%s/custom", g_plugin_dir);
for (size_t i = 0; i < sizeof(lib_paths) / sizeof(lib_paths[0]); i++) {
char lib_path[256] = { 0 };
snprintf(lib_path, sizeof(lib_path) - 1, "%s/%s", lib_paths[i],
lib_name);
instance->handle = dlopen(lib_path, RTLD_NOW);
if (instance->handle == NULL) {
continue;
}
instance->module = (neu_plugin_module_t *) dlsym(instance->handle,
"neu_plugin_module");
assert(instance->module != NULL);
return true;
}
assert(instance->handle != NULL);
return false;
}
bool neu_plugin_manager_remove_library(neu_plugin_manager_t *mgr,
const char * library)
{
+4
View File
@@ -68,6 +68,10 @@ bool neu_plugin_manager_create_instance_by_path(neu_plugin_manager_t *mgr,
neu_plugin_instance_t *instance,
int * error);
bool neu_plugin_manager_create_instance_by_lib_name(
neu_plugin_manager_t *mgr, const char *lib_name,
neu_plugin_instance_t *instance);
bool neu_plugin_manager_remove_library(neu_plugin_manager_t *mgr,
const char * library);
+1
View File
@@ -71,6 +71,7 @@ NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT = 2313
NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH = 2314
NEU_ERR_LIBRARY_NAME_NOT_CONFORM = 2315
NEU_ERR_LIBRARY_CLIB_NOT_MATCH = 2316
NEU_ERR_LIBRARY_UPDATE_FAIL = 2317
NEU_ERR_LICENSE_NOT_FOUND = 2400
NEU_ERR_LICENSE_INVALID = 2401
+1 -1
View File
@@ -200,7 +200,7 @@ class TestPlugin:
response = api.updata_plugin(
library_name=plugin_data['library'], so_file=plugin_data['so_file'], schema_file=plugin_data['schema_file'])
assert 400 == response.status_code
assert NEU_ERR_LIBRARY_MODULE_NOT_EXISTS == response.json().get("error")
assert NEU_ERR_LIBRARY_UPDATE_FAIL == response.json().get("error")
@description(given="incorrect configuration", when="update plugin", then="fail")
def test_08_update_plugin_fail1(self):