diff --git a/userspace/libsinsp/sinsp_filtercheck_thread.cpp b/userspace/libsinsp/sinsp_filtercheck_thread.cpp index 044f71c94d..82fe9d35bc 100644 --- a/userspace/libsinsp/sinsp_filtercheck_thread.cpp +++ b/userspace/libsinsp/sinsp_filtercheck_thread.cpp @@ -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; @@ -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;