Skip to content

Commit

Permalink
update(userspace/libsinsp): avoid code duplication when handling proc…
Browse files Browse the repository at this point in the history
….fd fields

Signed-off-by: Lorenzo Susini <[email protected]>
  • Loading branch information
loresuso authored and poiana committed Jun 18, 2024
1 parent 4d2bc8b commit 57f5168
Showing 1 changed file with 20 additions and 50 deletions.
70 changes: 20 additions & 50 deletions userspace/libsinsp/sinsp_filtercheck_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,43 +1619,28 @@ uint8_t* sinsp_filter_check_thread::extract_single(sinsp_evt *evt, uint32_t* len
}
}
case TYPE_FD_STDIN_TYPE:
case TYPE_FD_STDOUT_TYPE:
case TYPE_FD_STDERR_TYPE:
{
auto fdtable_ptr = tinfo->get_fd_table();
if (fdtable_ptr == nullptr)
{
return NULL;
}
auto fdinfo = fdtable_ptr->find(0);
if (fdinfo == nullptr)
int64_t fd = -1;
if (m_field_id == TYPE_FD_STDIN_TYPE)
{
return NULL;
fd = 0;
}
m_tstr = fdinfo->get_typestring();
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_FD_STDOUT_TYPE:
{
auto fdtable_ptr = tinfo->get_fd_table();
if (fdtable_ptr == nullptr)
else if (m_field_id == TYPE_FD_STDOUT_TYPE)
{
return NULL;
fd = 1;
}
auto fdinfo = fdtable_ptr->find(1);
if (fdinfo == nullptr)
else if (m_field_id == TYPE_FD_STDERR_TYPE)
{
return NULL;
fd = 2;
}
m_tstr = fdinfo->get_typestring();
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_FD_STDERR_TYPE:
{
auto fdtable_ptr = tinfo->get_fd_table();
if (fdtable_ptr == nullptr)
{
return NULL;
}
auto fdinfo = fdtable_ptr->find(2);
auto fdinfo = fdtable_ptr->find(fd);
if (fdinfo == nullptr)
{
return NULL;
Expand All @@ -1664,43 +1649,28 @@ uint8_t* sinsp_filter_check_thread::extract_single(sinsp_evt *evt, uint32_t* len
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_FD_STDIN_NAME:
case TYPE_FD_STDOUT_NAME:
case TYPE_FD_STDERR_NAME:
{
auto fdtable_ptr = tinfo->get_fd_table();
if (fdtable_ptr == nullptr)
{
return NULL;
}
auto fdinfo = fdtable_ptr->find(0);
if (fdinfo == nullptr)
int64_t fd = -1;
if (m_field_id == TYPE_FD_STDIN_NAME)
{
return NULL;
fd = 0;
}
m_tstr = fdinfo->m_name.c_str();
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_FD_STDOUT_NAME:
{
auto fdtable_ptr = tinfo->get_fd_table();
if (fdtable_ptr == nullptr)
else if (m_field_id == TYPE_FD_STDOUT_NAME)
{
return NULL;
fd = 1;
}
auto fdinfo = fdtable_ptr->find(1);
if (fdinfo == nullptr)
else if (m_field_id == TYPE_FD_STDERR_NAME)
{
return NULL;
fd = 2;
}
m_tstr = fdinfo->m_name.c_str();
RETURN_EXTRACT_STRING(m_tstr);
}
case TYPE_FD_STDERR_NAME:
{
auto fdtable_ptr = tinfo->get_fd_table();
if (fdtable_ptr == nullptr)
{
return NULL;
}
auto fdinfo = fdtable_ptr->find(2);
auto fdinfo = fdtable_ptr->find(fd);
if (fdinfo == nullptr)
{
return NULL;
Expand Down

0 comments on commit 57f5168

Please sign in to comment.