Skip to content

Commit 1681f14

Browse files
committed
Core: add an option to disable plugin unload on exit
1 parent 8a002ce commit 1681f14

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/core/configurator/plugin_finder.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,30 @@ extern "C" {
6262
/** Component identification (for log) */
6363
static const char *comp_str = "Configurator (plugin finder)";
6464

65+
ipx_plugin_finder::ipx_plugin_finder()
66+
{
67+
// Enable automatic unload of plugins
68+
unload_on_exit = true;
69+
}
70+
6571
ipx_plugin_finder::~ipx_plugin_finder()
6672
{
6773
// Unload all plugins
6874
for (struct ipx_plugin_data *plugin : loaded_plugins) {
69-
dlclose(plugin->cbs.handle);
75+
if (unload_on_exit) {
76+
dlclose(plugin->cbs.handle);
77+
}
78+
7079
delete plugin;
7180
}
7281
}
7382

83+
void
84+
ipx_plugin_finder::auto_unload(bool enable)
85+
{
86+
unload_on_exit = enable;
87+
}
88+
7489
void
7590
ipx_plugin_finder::path_add(const std::string &pathname)
7691
{

src/core/configurator/plugin_finder.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class ipx_plugin_finder {
7171
/** Search paths (files and directories) */
7272
std::vector<std::string> paths;
7373
std::vector<struct ipx_plugin_data *> loaded_plugins;
74+
bool unload_on_exit;
7475

7576
void find_in_paths(const std::string &name, uint16_t, struct ipx_ctx_callbacks &cbs);
7677
void *find_in_file(const std::string &name, uint16_t type, const char *path);
@@ -80,7 +81,7 @@ class ipx_plugin_finder {
8081

8182
public:
8283
// Use default constructor and destructor
83-
ipx_plugin_finder() = default;
84+
ipx_plugin_finder();
8485
~ipx_plugin_finder();
8586

8687
/**
@@ -105,6 +106,18 @@ class ipx_plugin_finder {
105106
const struct ipx_plugin_data *
106107
find(const std::string &name, uint16_t type);
107108

109+
/**
110+
* \brief Automatically unload all plugins on destroy
111+
*
112+
* This options allows plugin developers to disable automatic unload of plugins. Disabled
113+
* unload leaves plugin symbols available even after the collector shutdown. This is necessary
114+
* for analysis of performance and memory leaks. For example, valgrind is unable to identify
115+
* position of memory leaks of unloaded plugins.
116+
* \note By default, unload is enabled.
117+
* \param[in] enable Enable/disable
118+
*/
119+
void
120+
auto_unload(bool enable);
108121
};
109122

110123
#endif //IPFIXCOL_PLUGIN_FINDER_H

src/core/main.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ print_help()
8484
{
8585
std::cout
8686
<< "IPFIX Collector daemon\n"
87-
<< "Usage: ipfixcol [-c FILE] [-p PATH] [-e DIR] [-P FILE] [-vVhd]\n"
87+
<< "Usage: ipfixcol2 [-c FILE] [-p PATH] [-e DIR] [-P FILE] [-r SIZE] [-vVhdu]\n"
8888
<< " -c FILE Path to the startup configuration file\n"
8989
<< " (default: " << IPX_DEFAULT_STARTUP_CONFIG << ")\n"
9090
<< " -p PATH Add path to a directory with plugins or to a file\n"
@@ -97,7 +97,8 @@ print_help()
9797
<< " -h Show this help message and exit\n"
9898
<< " -V Show version information and exit\n"
9999
<< " -v Increase verbosity level (by default, show only error messages)\n"
100-
<< " (can be used up to 3 times to add warning/info/debug messages)\n";
100+
<< " (can be used up to 3 times to add warning/info/debug messages)\n"
101+
<< " -u Disable plugins unload on exit (only for plugin developers)\n";
101102
}
102103

103104
/**
@@ -206,7 +207,7 @@ int main(int argc, char *argv[])
206207
// Parse configuration
207208
int opt;
208209
opterr = 0; // Disable default error messages
209-
while ((opt = getopt(argc, argv, "c:vVhdp:e:P:r:")) != -1) {
210+
while ((opt = getopt(argc, argv, "c:vVhdp:e:P:r:u")) != -1) {
210211
switch (opt) {
211212
case 'c': // Configuration file
212213
cfg_startup = optarg;
@@ -220,21 +221,24 @@ int main(int argc, char *argv[])
220221
case 'h': // Help
221222
print_help();
222223
return EXIT_SUCCESS;
223-
case 'd':
224+
case 'd': // Run as a standalone process (daemon)
224225
daemon_en = true;
225226
break;
226227
case 'p': // Plugin search path
227228
conf.finder.path_add(std::string(optarg));
228229
break;
229-
case 'e':
230+
case 'e': // Redefine path to Information Elements definition
230231
cfg_iedir = optarg;
231232
break;
232-
case 'P':
233+
case 'P': // Create a PID file
233234
pid_file = optarg;
234235
break;
235-
case 'r':
236+
case 'r': // Change ring size
236237
ring_size = optarg;
237238
break;
239+
case 'u': // Disable automatic plugin unload
240+
conf.finder.auto_unload(false);
241+
break;
238242
default: // ?
239243
std::cerr << "Unknown parameter '" << static_cast<char>(optopt) << "'!" << std::endl;
240244
return EXIT_FAILURE;

0 commit comments

Comments
 (0)