Skip to content

Commit

Permalink
new(userspace/libsinsp): expose get_owner_last_error in plugin's ca…
Browse files Browse the repository at this point in the history
…pture listening capability.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 5, 2024
1 parent f82c686 commit ad86638
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ bool sinsp_plugin::capture_open() {
ss_plugin_table_writer_vtable table_writer;

in.owner = (ss_plugin_owner_t*)this;
in.get_owner_last_error = sinsp_plugin::get_owner_last_error;

Check warning on line 817 in userspace/libsinsp/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/plugin.cpp#L817

Added line #L817 was not covered by tests
in.table_reader_ext = &table_reader_ext;
in.table_writer_ext = &table_writer_ext;
in.routine = &routine_vtable;
Expand Down Expand Up @@ -844,6 +845,7 @@ bool sinsp_plugin::capture_close() {
ss_plugin_table_writer_vtable table_writer;

in.owner = (ss_plugin_owner_t*)this;
in.get_owner_last_error = sinsp_plugin::get_owner_last_error;

Check warning on line 848 in userspace/libsinsp/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/plugin.cpp#L848

Added line #L848 was not covered by tests
in.table_reader_ext = &table_reader_ext;
in.table_writer_ext = &table_writer_ext;
in.routine = &routine_vtable;
Expand Down
10 changes: 8 additions & 2 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ void sinsp::open_common(scap_open_args* oargs,
// notify registered plugins of capture open
for(auto& p : m_plugin_manager->plugins()) {
if(p->caps() & CAP_CAPTURE_LISTENING) {
p->capture_open();
if(!p->capture_open()) {
throw sinsp_exception("capture_open error for plugin '" + p->name() +
"' : " + p->get_last_error());
}
}
}
}
Expand Down Expand Up @@ -741,7 +744,10 @@ void sinsp::close() {
if(m_mode != SINSP_MODE_NONE) {
for(auto& p : m_plugin_manager->plugins()) {
if(p->caps() & CAP_CAPTURE_LISTENING) {
p->capture_close();
if(!p->capture_close()) {
throw sinsp_exception("capture_close error for plugin '" + p->name() +
"' : " + p->get_last_error());
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion userspace/plugin/plugin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
//
// todo(jasondellaluce): when/if major changes to v4, check and solve all todos
#define PLUGIN_API_VERSION_MAJOR 3
#define PLUGIN_API_VERSION_MINOR 8
#define PLUGIN_API_VERSION_MINOR 9
#define PLUGIN_API_VERSION_PATCH 0

//
Expand Down Expand Up @@ -469,6 +469,11 @@ typedef struct ss_plugin_capture_listen_input {
//
// Vtable for controlling a state table for write operations.
ss_plugin_table_writer_vtable_ext* table_writer_ext;
//
// Return a string with the error that was last generated by the plugin's
// owner, or NULL if no error is present.
// The string pointer is owned by the plugin's owenr.
const char* (*get_owner_last_error)(ss_plugin_owner_t* o);
} ss_plugin_capture_listen_input;

//
Expand Down

0 comments on commit ad86638

Please sign in to comment.