Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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 @@ -1230,6 +1231,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 @@ -1384,6 +1392,8 @@ void sinsp_thread_manager::create_thread_dependencies(
return;
}
parent_thread->add_child(tinfo);

tinfo->update_main_fdtable();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting this in create_thread_dependencies should correctly set the fdtable in all cases

  • /proc scan at initi time
  • /proc scan at runtime
  • when a new thread is added after a clone syscall

}

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 @@ -631,6 +631,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 @@ -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

Expand Down