Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
  • Loading branch information
therealbobo committed Sep 20, 2024
1 parent 6c053fa commit 1701d8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 49 deletions.
57 changes: 11 additions & 46 deletions test/libsinsp_e2e/event_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,66 +103,31 @@ void event_capture::capture() {
}
} // End init synchronized section

bool signaled_start = false;
sinsp_evt* event;
bool result = true;
int32_t next_result = SCAP_SUCCESS;
bool end_event = false;
while(!m_capture_stopped && !end_event && result && !::testing::Test::HasFatalFailure()) {

m_capture_started = true;
m_condition_started.notify_one();

while(!end_event && !::testing::Test::HasFatalFailure()) {
{
std::scoped_lock inspector_next_lock(m_inspector_mutex);
next_result = get_inspector()->next(&event);
}
if(SCAP_SUCCESS == next_result) {
if(strcmp(event->get_name(), "close") == 0 && event->get_param(0)->as<int64_t>() == 8192) {
if(next_result == SCAP_SUCCESS) {
if(event->get_type() == PPME_SYSCALL_KILL_E && event->get_param(1)->as<int8_t>() == -1) {
end_event = true;
continue;
}
result = handle_event(event);
if(m_mode != SINSP_MODE_NODRIVER && m_dump) {
dumper->dump(event);
}
}
if(!signaled_start) {
signaled_start = true;
m_capture_started = true;
m_condition_started.notify_one();
}
}

if(m_mode != SINSP_MODE_NODRIVER) {
uint32_t n_timeouts = 0;
while(result && !::testing::Test::HasFatalFailure()) {
{
std::scoped_lock inspector_next_lock(m_inspector_mutex);
next_result = get_inspector()->next(&event);
}
if(next_result == SCAP_TIMEOUT) {
n_timeouts++;

if(n_timeouts < m_max_timeouts) {
continue;
} else {
if(m_capture_stopped) {
break;
}
}

if(next_result == SCAP_FILTERED_EVENT) {
continue;
} else {
handle_event(event);
}
if(next_result != SCAP_SUCCESS) {
break;
}
if(m_dump) {
if(m_mode != SINSP_MODE_NODRIVER && m_dump) {
dumper->dump(event);
}
result = handle_event(event);
}
{
std::scoped_lock inspector_next_lock(m_inspector_mutex);
while(SCAP_SUCCESS == get_inspector()->next(&event)) {
// just consume the remaining events
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions test/libsinsp_e2e/event_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,9 @@ class event_capture {

if(!capturing.m_start_failed.load()) {
run_function(capturing.get_inspector_handle());
// This close is just used to be sure that all the events
// This kill is just used to be sure that all the events
// created in the run_function were consumed.
close(8192);
capturing.stop_capture();
kill(-1,-1);
capturing.wait_for_capture_stop();
} else {
std::unique_lock<std::mutex> error_lookup_lock(capturing.m_object_state_mutex);
Expand Down

0 comments on commit 1701d8f

Please sign in to comment.