diff --git a/userspace/libsinsp/fdinfo.cpp b/userspace/libsinsp/fdinfo.cpp index 626dd0d977..724cc9531b 100644 --- a/userspace/libsinsp/fdinfo.cpp +++ b/userspace/libsinsp/fdinfo.cpp @@ -283,6 +283,8 @@ sinsp_fdinfo* sinsp_fdtable::find(int64_t fd) sinsp_fdinfo* sinsp_fdtable::add(int64_t fd, std::unique_ptr fdinfo) { + fdinfo->m_fd = fd; + // // Look for the FD in the table // diff --git a/userspace/libsinsp/fdinfo.h b/userspace/libsinsp/fdinfo.h index 03737bf4d4..c665891351 100644 --- a/userspace/libsinsp/fdinfo.h +++ b/userspace/libsinsp/fdinfo.h @@ -432,6 +432,7 @@ class SINSP_PUBLIC sinsp_fdinfo uint32_t m_mount_id = 0; uint64_t m_ino = 0; int64_t m_pid = 0; // only if fd is a pidfd + int64_t m_fd = -1; }; /*@}*/ diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index e946cf0d91..3f2ad39599 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -4172,6 +4172,13 @@ void sinsp_parser::parse_rw_exit(sinsp_evt *evt) m_inspector->m_thread_manager->thread_to_scap(*evt->get_tinfo(), &scap_tinfo); + // Store current fd; it might get changed by scap_get_fdlist below. + int64_t fd = -1; + if (evt->get_fd_info()) + { + fd = evt->get_fd_info()->m_fd; + } + // Get the new fds. The callbacks we have registered populate the fd table // with the new file descriptors. if (scap_get_fdlist(m_inspector->get_scap_platform(), &scap_tinfo, error) != SCAP_SUCCESS) @@ -4179,6 +4186,12 @@ void sinsp_parser::parse_rw_exit(sinsp_evt *evt) libsinsp_logger()->format(sinsp_logger::SEV_DEBUG, "scap_get_fdlist failed: %s, proc table will not be updated with new fds.", error); } + + // Force refresh event fdinfo + if (fd != -1) + { + evt->set_fd_info(evt->get_tinfo()->get_fd(fd)); + } } } } diff --git a/userspace/libsinsp/threadinfo.cpp b/userspace/libsinsp/threadinfo.cpp index 7557fca4e6..4e97e06a8a 100644 --- a/userspace/libsinsp/threadinfo.cpp +++ b/userspace/libsinsp/threadinfo.cpp @@ -262,6 +262,7 @@ void sinsp_threadinfo::add_fd_from_scap(scap_fdinfo *fdi) newfdi->m_type = fdi->type; newfdi->m_flags = sinsp_fdinfo::FLAGS_FROM_PROC; newfdi->m_ino = fdi->ino; + newfdi->m_fd = fdi->fd; switch(newfdi->m_type) { @@ -1316,6 +1317,7 @@ static void fd_to_scap(scap_fdinfo *dst, sinsp_fdinfo* src) { dst->type = src->m_type; dst->ino = src->m_ino; + dst->fd = src->m_fd; switch(dst->type) { @@ -1992,7 +1994,6 @@ void sinsp_thread_manager::dump_threads_to_file(scap_dumper_t* dumper) // // Populate the fd info // - scfdinfo->fd = fd; fd_to_scap(scfdinfo, &info); //