Skip to content

Commit

Permalink
update(userspace/libsinsp): check correct allocation of thread info, …
Browse files Browse the repository at this point in the history
…remove useless forward decl

Signed-off-by: Lorenzo Susini <[email protected]>
  • Loading branch information
loresuso committed Oct 12, 2023
1 parent b3119d2 commit ed5ff00
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions userspace/libscap/linux/scap_procs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,7 @@ int32_t scap_linux_get_fdlist(struct scap_platform* platform, struct scap_thread
struct scap_ns_socket_list* sockets_by_ns = NULL;
struct scap_linux_platform* linux_platform = (struct scap_linux_platform*)platform;

// We collect file descriptors only for the main thread
snprintf(proc_dir, sizeof(proc_dir), "%s/proc/%d/", scap_get_host_root(), tinfo->pid);

return scap_fd_scan_fd_dir(linux_platform, &platform->m_proclist, proc_dir, tinfo, &sockets_by_ns, &num_fds_ret, lasterr);
Expand Down
1 change: 0 additions & 1 deletion userspace/libscap/scap_platform_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ extern "C" {

struct ppm_proclist_info;
struct scap;
struct scap_fdinfo;
struct scap_addrlist;
struct _scap_machine_info;
struct scap_threadinfo;
Expand Down
1 change: 0 additions & 1 deletion userspace/libscap/scap_platform_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct scap_open_args;
struct scap_platform;
struct scap_proclist;
struct scap_userlist;
struct scap_fdinfo;
struct ppm_proclist_info;

// a method table for platform-specific operations
Expand Down
7 changes: 6 additions & 1 deletion userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4937,13 +4937,18 @@ void sinsp_parser::parse_rw_exit(sinsp_evt *evt)
if(cmsg->cmsg_type == SCM_RIGHTS)
{
auto scap_tinfo = scap_proc_alloc(m_inspector->m_h);
if (scap_tinfo == NULL)
{
g_logger.format(sinsp_logger::SEV_CRITICAL, "scap_proc_alloc failed, proc table will not be updated with new fds.");
return;
}
m_inspector->m_thread_manager->thread_to_scap(*evt->m_tinfo, scap_tinfo);

// Get the new fds. The callbacks we have registered populate the fd table
// with the new file descriptors.
if (scap_get_fdlist(m_inspector->m_h, scap_tinfo) != SCAP_SUCCESS)
{
g_logger.format(sinsp_logger::SEV_DEBUG, "scap_get_fdlist failed, proc table will not be updated with new fds.");
g_logger.format(sinsp_logger::SEV_ERROR, "scap_get_fdlist failed, proc table will not be updated with new fds.");
}

scap_proc_free(m_inspector->m_h, scap_tinfo);
Expand Down

0 comments on commit ed5ff00

Please sign in to comment.