Skip to content

Commit

Permalink
fix(libsinsp): expose main thread fd table
Browse files Browse the repository at this point in the history
Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian committed Oct 24, 2024
1 parent 90c1520 commit 2cd6315
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sinsp_threadinfo::sinsp_threadinfo(
m_cgroups(new cgroups_t),
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) {
init();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1231,6 +1232,13 @@ void sinsp_threadinfo::strvec_to_iovec(const std::vector<std::string>& strs,
}
}

void sinsp_threadinfo::update_main_fdtable() {
auto fdtable = get_fd_table();
if(fdtable) {
m_main_fdtable = static_cast<const libsinsp::state::base_table*>(fdtable->table_ptr());
}
}

static void fd_to_scap(scap_fdinfo* dst, sinsp_fdinfo* src) {
dst->type = src->m_type;
dst->ino = src->m_ino;
Expand Down Expand Up @@ -1385,6 +1393,8 @@ void sinsp_thread_manager::create_thread_dependencies(
return;
}
parent_thread->add_child(tinfo);

tinfo->update_main_fdtable();
}

std::unique_ptr<sinsp_threadinfo> sinsp_thread_manager::new_threadinfo() const {
Expand Down
6 changes: 5 additions & 1 deletion userspace/libsinsp/threadinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
const std::function<std::string(sinsp_threadinfo*)>& get_field_str,
bool is_virtual_id = false);

void update_main_fdtable();

private:
sinsp_threadinfo* get_cwd_root();
bool set_env_from_proc();
Expand All @@ -649,7 +651,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

Expand Down

0 comments on commit 2cd6315

Please sign in to comment.