From f01f81b87dc04a6bc27f14c2be8f08ffa738373c Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 19 Apr 2023 13:19:11 +0800 Subject: falcodump: Catch exceptions when loading plugins Consolidate some duplicate code. --- extcap/falcodump.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'extcap') diff --git a/extcap/falcodump.cpp b/extcap/falcodump.cpp index b4a19b7cdd..ffaa29ea9b 100644 --- a/extcap/falcodump.cpp +++ b/extcap/falcodump.cpp @@ -274,29 +274,27 @@ void print_cloudtrail_aws_region_config(int arg_num, const char *display, const static void load_plugins(sinsp &inspector) { WS_DIR *dir; WS_DIRENT *file; - char *plugin_path = g_build_filename(get_plugins_dir_with_version(), "falco", NULL); - - if ((dir = ws_dir_open(plugin_path, 0, NULL)) != NULL) { - while ((file = ws_dir_read_name(dir)) != NULL) { - char *libname = g_build_filename(plugin_path, ws_dir_get_name(file), NULL); - inspector.register_plugin(libname); - g_free(libname); - } - ws_dir_close(dir); - } - g_free(plugin_path); - - plugin_path = g_build_filename(get_plugins_pers_dir_with_version(), "falco", NULL); + char *plugin_paths[] = { + g_build_filename(get_plugins_dir_with_version(), "falco", NULL), + g_build_filename(get_plugins_pers_dir_with_version(), "falco", NULL) + }; - if ((dir = ws_dir_open(plugin_path, 0, NULL)) != NULL) { - while ((file = ws_dir_read_name(dir)) != NULL) { - char *libname = g_build_filename(plugin_path, ws_dir_get_name(file), NULL); - inspector.register_plugin(libname); - g_free(libname); + for (size_t idx = 0; idx < 2; idx++) { + char *plugin_path = plugin_paths[idx]; + if ((dir = ws_dir_open(plugin_path, 0, NULL)) != NULL) { + while ((file = ws_dir_read_name(dir)) != NULL) { + char *libname = g_build_filename(plugin_path, ws_dir_get_name(file), NULL); + try { + inspector.register_plugin(libname); + } catch (sinsp_exception &e) { + ws_warning("%s", e.what()); + } + g_free(libname); + } + ws_dir_close(dir); } - ws_dir_close(dir); + g_free(plugin_path); } - g_free(plugin_path); } // Given a key, try to find its value in a JSON object. -- cgit v1.2.3