Attempt to load a plugin shared object file. * * Note that this function is only used to load plugins for the purpose of * verifying that they are valid plugins. It is not used to load plugins for * normal operation. Any loaded plugin will be closed immediately after loading * it. * * @param[in] plugin_type The type of plugin for which to create a PluginInfo. * @param[in] plugin_path The p
| 1034 | * @return True if the plugin loaded successfully, false otherwise. |
| 1035 | */ |
| 1036 | bool |
| 1037 | try_loading_plugin(plugin_type_t plugin_type, const fs::path &plugin_path, std::string &error) |
| 1038 | { |
| 1039 | // At least one plugin checks this during plugin unload, so act like the event system is shutdown |
| 1040 | TSSystemState::shut_down_event_system(); |
| 1041 | |
| 1042 | switch (plugin_type) { |
| 1043 | case plugin_type_t::GLOBAL: { |
| 1044 | void *handle = nullptr; |
| 1045 | void *initptr = nullptr; |
| 1046 | bool const plugin_loaded = plugin_dso_load(plugin_path.c_str(), handle, initptr, error); |
| 1047 | if (handle != nullptr) { |
| 1048 | dlclose(handle); |
| 1049 | handle = nullptr; |
| 1050 | } |
| 1051 | return plugin_loaded; |
| 1052 | } |
| 1053 | case plugin_type_t::REMAP: { |
| 1054 | auto temporary_directory = fs::temp_directory_path(); |
| 1055 | temporary_directory /= fs::path(std::string("verify_plugin_") + std::to_string(getpid())); |
| 1056 | std::error_code ec; |
| 1057 | if (!fs::create_directories(temporary_directory, ec)) { |
| 1058 | std::ostringstream error_os; |
| 1059 | error_os << "Could not create temporary directory " << temporary_directory.string() << ": " << ec.message(); |
| 1060 | error = error_os.str(); |
| 1061 | return false; |
| 1062 | } |
| 1063 | const auto runtime_path = temporary_directory / plugin_path.filename(); |
| 1064 | const fs::path unused_config; |
| 1065 | auto plugin_info = std::make_unique<RemapPluginInfo>(unused_config, plugin_path, runtime_path); |
| 1066 | bool loaded = plugin_info->load(error, unused_config); // ToDo: Will this ever need support for cripts |
| 1067 | if (!fs::remove(temporary_directory, ec)) { |
| 1068 | fprintf(stderr, "ERROR: could not remove temporary directory '%s': %s\n", temporary_directory.c_str(), ec.message().c_str()); |
| 1069 | } |
| 1070 | return loaded; |
| 1071 | } |
| 1072 | } |
| 1073 | // Unreached. |
| 1074 | return false; |
| 1075 | } |
| 1076 | |
| 1077 | /** A helper for the verify plugin command functions. |
| 1078 | * |
no test coverage detected