diff options
author | Gerald Combs <gerald@wireshark.org> | 2023-04-19 13:19:11 +0800 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2023-04-20 23:00:18 +0000 |
commit | f01f81b87dc04a6bc27f14c2be8f08ffa738373c (patch) | |
tree | 9e0c9b88837c40a993d03e8f1093a43e3660e5ed /extcap | |
parent | 9af7fe872427730cdf185606ede3d5608ae519aa (diff) |
falcodump: Catch exceptions when loading plugins
Consolidate some duplicate code.
Diffstat (limited to 'extcap')
-rw-r--r-- | extcap/falcodump.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
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. |