Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

cleanup(sinsp): remove some duplicated code #2180

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
75 changes: 18 additions & 57 deletions userspace/libsinsp/sinsp_filtercheck_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,69 +1284,30 @@
return extract_buflen(evt, len);
}
break;
case TYPE_RESRAW: {
const sinsp_evt_param* pi = evt->get_param_by_name("res");

if(pi != NULL) {
*len = pi->m_len;
return (uint8_t*)pi->m_val;
}

if((evt->get_info_flags() & EF_CREATES_FD) && PPME_IS_EXIT(evt->get_type())) {
pi = evt->get_param_by_name("fd");

if(pi != NULL) {
*len = pi->m_len;
return (uint8_t*)pi->m_val;
}
case TYPE_RESRAW:
if(!evt->has_return_value()) {
return NULL;

Check warning on line 1289 in userspace/libsinsp/sinsp_filtercheck_event.cpp

View check run for this annotation

Codecov / codecov/patch

userspace/libsinsp/sinsp_filtercheck_event.cpp#L1289

Added line #L1289 was not covered by tests
}

return NULL;
} break;
m_val.s64 = evt->get_syscall_return_value();
RETURN_EXTRACT_VAR(m_val.s64);
case TYPE_RESSTR: {
const char* resolved_argstr;
const char* argstr;

const sinsp_evt_param* pi = evt->get_param_by_name("res");

if(pi != NULL) {
int64_t res = pi->as<int64_t>();

if(res >= 0) {
RETURN_EXTRACT_CSTR("SUCCESS");
} else {
argstr = evt->get_param_value_str("res", &resolved_argstr);
ASSERT(resolved_argstr != NULL && resolved_argstr[0] != 0);
if(!evt->has_return_value()) {
return NULL;
}

if(resolved_argstr != NULL && resolved_argstr[0] != 0) {
RETURN_EXTRACT_CSTR(resolved_argstr);
} else if(argstr != NULL) {
RETURN_EXTRACT_CSTR(argstr);
}
}
} else {
if((evt->get_info_flags() & EF_CREATES_FD) && PPME_IS_EXIT(evt->get_type())) {
pi = evt->get_param_by_name("fd");
if(pi) {
int64_t res = pi->as<int64_t>();

if(res >= 0) {
RETURN_EXTRACT_CSTR("SUCCESS");
} else {
argstr = evt->get_param_value_str("fd", &resolved_argstr);
ASSERT(resolved_argstr != NULL && resolved_argstr[0] != 0);

if(resolved_argstr != NULL && resolved_argstr[0] != 0) {
RETURN_EXTRACT_CSTR(resolved_argstr);
} else if(argstr != NULL) {
RETURN_EXTRACT_CSTR(argstr);
}
}
}
}
int64_t res = evt->get_syscall_return_value();
if(res >= 0) {
RETURN_EXTRACT_CSTR("SUCCESS");
}

return NULL;
// todo!: we should check if a failed syscall can return something that is not an errno.
// When res is < 0 usually it is an errno. In that case we could directly call
// `sinsp_utils::errno_to_str`
//
// m_strstorage = sinsp_utils::errno_to_str((int32_t)res);
m_strstorage = evt->get_param_value_str(0, true);
RETURN_EXTRACT_STRING(m_strstorage);
} break;
case TYPE_ISIO: {
ppm_event_flags eflags = evt->get_info_flags();
Expand Down
Loading