mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-28 01:47:18 +01:00
Fix probable crash and signal handler
This commit is contained in:
parent
7997de62b7
commit
8c998e886c
4 changed files with 35 additions and 46 deletions
|
|
@ -64,15 +64,6 @@ static void sig_handler(int sig)
|
|||
}
|
||||
}
|
||||
|
||||
static void service_sig_handler(int sig)
|
||||
{
|
||||
WARNING("# Micro-service PID[%ld] received %d signal ...", getpid(), sig);
|
||||
if (sig == SIGSEGV) {
|
||||
ERR("# Micro-service in PID[%ld] ...", getpid());
|
||||
}
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
static void signal_init(void)
|
||||
{
|
||||
signal(SIGSEGV, sig_handler);
|
||||
|
|
@ -81,7 +72,7 @@ static void signal_init(void)
|
|||
|
||||
static void service_signal_init(void)
|
||||
{
|
||||
signal(SIGSEGV, service_sig_handler);
|
||||
signal(SIGSEGV, sig_handler);
|
||||
}
|
||||
|
||||
static void usage(char *prog)
|
||||
|
|
@ -1693,10 +1684,9 @@ void bbfdm_ctx_init(struct bbfdm_context *bbfdm_ctx)
|
|||
int daemon_load_datamodel(struct bbfdm_context *daemon_ctx)
|
||||
{
|
||||
int err = -1;
|
||||
char *tmp = daemon_ctx->config.in_type;
|
||||
char *file_path = daemon_ctx->config.in_name;
|
||||
|
||||
if (DM_STRLEN(tmp) == 0 || DM_STRLEN(file_path) == 0) {
|
||||
if (DM_STRLEN(file_path) == 0) {
|
||||
ERR("Input type/name not supported or defined");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1723,15 +1713,21 @@ int daemon_load_datamodel(struct bbfdm_context *daemon_ctx)
|
|||
}
|
||||
}
|
||||
|
||||
if (strcasecmp(tmp, "JSON") == 0) {
|
||||
char *ext = strrchr(file_path, '.');
|
||||
if (ext == NULL) {
|
||||
ERR("Input file without extension");
|
||||
} else if (strcasecmp(ext, ".json") == 0) {
|
||||
INFO("Loading JSON plugin %s", file_path);
|
||||
err = load_json_plugin(&loaded_json_files, &json_list, &json_memhead, file_path, &DEAMON_DM_ROOT_OBJ);
|
||||
} else if (strcasecmp(tmp, "DotSo") == 0) {
|
||||
} else if (strcasecmp(ext, ".so") == 0) {
|
||||
INFO("Loading DotSo plugin %s", file_path);
|
||||
err = load_dotso_plugin(&deamon_lib_handle, file_path, &DEAMON_DM_ROOT_OBJ);
|
||||
} else {
|
||||
ERR("Input type %s not supported", tmp);
|
||||
ERR("Input type %s not supported", ext);
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
INFO("Loading sub-modules %s", daemon_ctx->config.in_plugin_dir);
|
||||
bbf_global_init(DEAMON_DM_ROOT_OBJ, daemon_ctx->config.in_plugin_dir);
|
||||
} else {
|
||||
ERR("Failed loading %s", file_path);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ int bbfdm_cmd_exec(struct dmctx *bbf_ctx, int cmd)
|
|||
} else {
|
||||
ERR("PID [%ld]::Exception on [%d => %s]", getpid(), cmd, bbf_ctx->in_param);
|
||||
fault = USP_FAULT_INTERNAL_ERROR;
|
||||
if (is_micro_service) {
|
||||
ERR("Micro-service PID [%ld]::Exception on [%d => %s]", getpid(), cmd, bbf_ctx->in_param);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
gs_jump_called_by_bbf = false;
|
||||
|
|
|
|||
|
|
@ -34,8 +34,10 @@ static uint8_t find_number_of_objects(DM_MAP_OBJ *dynamic_obj)
|
|||
|
||||
int load_dotso_plugin(void **lib_handle, const char *file_path, DMOBJ **main_entry)
|
||||
{
|
||||
if (!lib_handle || !file_path || !strlen(file_path) || !main_entry)
|
||||
if (!lib_handle || !file_path || !strlen(file_path) || !main_entry) {
|
||||
ERR("Input validation failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *handle = dlopen(file_path, RTLD_NOW|RTLD_LOCAL);
|
||||
if (!handle) {
|
||||
|
|
@ -105,12 +107,16 @@ int load_json_plugin(struct list_head *json_plugin, struct list_head *json_list,
|
|||
int json_plugin_version = JSON_VERSION_0;
|
||||
uint8_t idx = 0;
|
||||
|
||||
if (!file_path || !strlen(file_path) || !main_entry)
|
||||
if (!file_path || !strlen(file_path) || !main_entry) {
|
||||
ERR("Entry validation failed ...");
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_object *json_obj = json_object_from_file(file_path);
|
||||
if (!json_obj)
|
||||
if (!json_obj) {
|
||||
ERR("Failed to parse json file (%s)", file_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
save_loaded_json_files(json_plugin, json_obj);
|
||||
|
||||
|
|
|
|||
|
|
@ -193,25 +193,6 @@ void get_list_of_registered_service(struct list_head *srvlist, struct blob_buf *
|
|||
}
|
||||
}
|
||||
|
||||
static void free_specific_dynamic_node(DMOBJ *entryobj, int indx)
|
||||
{
|
||||
for (; (entryobj && entryobj->obj); entryobj++) {
|
||||
|
||||
if (entryobj->nextdynamicobj) {
|
||||
struct dm_dynamic_obj *next_dyn_array = entryobj->nextdynamicobj + indx;
|
||||
FREE(next_dyn_array->nextobj);
|
||||
}
|
||||
|
||||
if (entryobj->dynamicleaf) {
|
||||
struct dm_dynamic_leaf *next_dyn_array = entryobj->dynamicleaf + indx;
|
||||
FREE(next_dyn_array->nextleaf);
|
||||
}
|
||||
|
||||
if (entryobj->nextobj)
|
||||
free_specific_dynamic_node(entryobj->nextobj, indx);
|
||||
}
|
||||
}
|
||||
|
||||
static void free_all_dynamic_nodes(DMOBJ *entryobj)
|
||||
{
|
||||
for (; (entryobj && entryobj->obj); entryobj++) {
|
||||
|
|
@ -459,22 +440,24 @@ int get_leaf_idx(DMLEAF **entryleaf)
|
|||
|
||||
void load_plugins(DMOBJ *dm_entryobj, const char *plugin_path)
|
||||
{
|
||||
if (DM_STRLEN(plugin_path) == 0 || !folder_exists(plugin_path))
|
||||
if (DM_STRLEN(plugin_path) == 0) // If empty, return without further action
|
||||
return;
|
||||
|
||||
free_json_plugins();
|
||||
free_specific_dynamic_node(dm_entryobj, INDX_JSON_MOUNT);
|
||||
free_dotso_plugins();
|
||||
free_specific_dynamic_node(dm_entryobj, INDX_LIBRARY_MOUNT);
|
||||
if (!folder_exists(plugin_path)) {
|
||||
BBF_ERR("(%s) doesn't exist", plugin_path);
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *ent = NULL;
|
||||
DIR *dir = opendir(plugin_path);
|
||||
if (dir == NULL)
|
||||
return;
|
||||
|
||||
int num_files = 0;
|
||||
char *files[256];
|
||||
|
||||
DIR *dir = opendir(plugin_path);
|
||||
if (dir == NULL) {
|
||||
BBF_ERR("Cannot open (%s) directory", plugin_path);
|
||||
return;
|
||||
}
|
||||
|
||||
while ((ent = readdir(dir)) != NULL && num_files < 256) {
|
||||
files[num_files++] = strdup(ent->d_name);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue