From 701e9914b06c5b056efafb110d12aee880fe92d3 Mon Sep 17 00:00:00 2001 From: Gianmatteo Palmieri Date: Thu, 24 Oct 2024 09:06:05 +0200 Subject: [PATCH] fix(libsinsp): expose main thread fd table Signed-off-by: Gianmatteo Palmieri --- userspace/libsinsp/threadinfo.cpp | 12 +++++++++++- userspace/libsinsp/threadinfo.h | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/userspace/libsinsp/threadinfo.cpp b/userspace/libsinsp/threadinfo.cpp index 68da447f93..6109c7a3a6 100644 --- a/userspace/libsinsp/threadinfo.cpp +++ b/userspace/libsinsp/threadinfo.cpp @@ -49,6 +49,7 @@ sinsp_threadinfo::sinsp_threadinfo( table_entry(dyn_fields), m_inspector(inspector), m_fdtable(inspector), + m_main_fdtable(m_fdtable.table_ptr()), m_args_table_adapter("args", m_args), m_env_table_adapter("env", m_env), m_cgroups_table_adapter("cgroups", m_cgroups) { @@ -105,7 +106,7 @@ libsinsp::state::static_struct::field_infos sinsp_threadinfo::static_fields() co // m_clone_ts // m_lastexec_ts // m_latency - define_static_field(ret, this, m_fdtable.table_ptr(), "file_descriptors", true); + define_static_field(ret, this, m_main_fdtable, "file_descriptors", true); define_static_field(ret, this, m_cwd, "cwd", true); // m_parent_loop_detected return ret; @@ -1230,6 +1231,13 @@ void sinsp_threadinfo::strvec_to_iovec(const std::vector& strs, } } +void sinsp_threadinfo::update_main_fdtable() { + auto fdtable = get_fd_table(); + if(fdtable) { + m_main_fdtable = static_cast(fdtable->table_ptr()); + } +} + static void fd_to_scap(scap_fdinfo* dst, sinsp_fdinfo* src) { dst->type = src->m_type; dst->ino = src->m_ino; @@ -1384,6 +1392,8 @@ void sinsp_thread_manager::create_thread_dependencies( return; } parent_thread->add_child(tinfo); + + tinfo->update_main_fdtable(); } std::unique_ptr sinsp_thread_manager::new_threadinfo() const { diff --git a/userspace/libsinsp/threadinfo.h b/userspace/libsinsp/threadinfo.h index 3622d0b469..267ceb9ab4 100644 --- a/userspace/libsinsp/threadinfo.h +++ b/userspace/libsinsp/threadinfo.h @@ -631,6 +631,8 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry { const std::function& get_field_str, bool is_virtual_id = false); + void update_main_fdtable(); + private: sinsp_threadinfo* get_cwd_root(); bool set_env_from_proc(); @@ -650,7 +652,9 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry { // Parameters that can't be accessed directly because they could be in the // parent thread info // - sinsp_fdtable m_fdtable; // The fd table of this thread + sinsp_fdtable m_fdtable; // The fd table of this thread + const libsinsp::state::base_table* + m_main_fdtable; // Points to the base fd table of the current main thread std::string m_cwd; // current working directory uint8_t* m_lastevent_data; // Used by some event parsers to store the last enter event