Skip to content

Commit 2cd6315

Browse files
committed
fix(libsinsp): expose main thread fd table
Signed-off-by: Gianmatteo Palmieri <[email protected]>
1 parent 90c1520 commit 2cd6315

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

userspace/libsinsp/threadinfo.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ sinsp_threadinfo::sinsp_threadinfo(
5050
m_cgroups(new cgroups_t),
5151
m_inspector(inspector),
5252
m_fdtable(inspector),
53+
m_main_fdtable(m_fdtable.table_ptr()),
5354
m_args_table_adapter("args", m_args),
5455
m_env_table_adapter("env", m_env) {
5556
init();
@@ -105,7 +106,7 @@ libsinsp::state::static_struct::field_infos sinsp_threadinfo::static_fields() co
105106
// m_clone_ts
106107
// m_lastexec_ts
107108
// m_latency
108-
define_static_field(ret, this, m_fdtable.table_ptr(), "file_descriptors", true);
109+
define_static_field(ret, this, m_main_fdtable, "file_descriptors", true);
109110
define_static_field(ret, this, m_cwd, "cwd", true);
110111
// m_parent_loop_detected
111112
return ret;
@@ -1231,6 +1232,13 @@ void sinsp_threadinfo::strvec_to_iovec(const std::vector<std::string>& strs,
12311232
}
12321233
}
12331234

1235+
void sinsp_threadinfo::update_main_fdtable() {
1236+
auto fdtable = get_fd_table();
1237+
if(fdtable) {
1238+
m_main_fdtable = static_cast<const libsinsp::state::base_table*>(fdtable->table_ptr());
1239+
}
1240+
}
1241+
12341242
static void fd_to_scap(scap_fdinfo* dst, sinsp_fdinfo* src) {
12351243
dst->type = src->m_type;
12361244
dst->ino = src->m_ino;
@@ -1385,6 +1393,8 @@ void sinsp_thread_manager::create_thread_dependencies(
13851393
return;
13861394
}
13871395
parent_thread->add_child(tinfo);
1396+
1397+
tinfo->update_main_fdtable();
13881398
}
13891399

13901400
std::unique_ptr<sinsp_threadinfo> sinsp_thread_manager::new_threadinfo() const {

userspace/libsinsp/threadinfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
630630
const std::function<std::string(sinsp_threadinfo*)>& get_field_str,
631631
bool is_virtual_id = false);
632632

633+
void update_main_fdtable();
634+
633635
private:
634636
sinsp_threadinfo* get_cwd_root();
635637
bool set_env_from_proc();
@@ -649,7 +651,9 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry {
649651
// Parameters that can't be accessed directly because they could be in the
650652
// parent thread info
651653
//
652-
sinsp_fdtable m_fdtable; // The fd table of this thread
654+
sinsp_fdtable m_fdtable; // The fd table of this thread
655+
const libsinsp::state::base_table*
656+
m_main_fdtable; // Points to the base fd table of the current main thread
653657
std::string m_cwd; // current working directory
654658
uint8_t* m_lastevent_data; // Used by some event parsers to store the last enter event
655659

0 commit comments

Comments
 (0)