Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

new(userspace/libsinsp): expose get_owner_last_error in plugin's capture listening capability #2147

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manage errors in capture_open/close.

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to expose table_reader and table_writer from plugin sdks.

} ss_plugin_capture_listen_input;

//
Expand Down
Loading