Skip to content

Commit

Permalink
properly reference count the threads that are crated by scanning proc
Browse files Browse the repository at this point in the history
  • Loading branch information
ldegio committed Aug 6, 2014
1 parent a327719 commit 2af3bcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion userspace/libscap/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
//
#define INCLUDE_UNKNOWN_SOCKET_FDS

#define USE_ZLIB
#undef USE_ZLIB
19 changes: 19 additions & 0 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,27 @@ sinsp_threadinfo* sinsp::get_thread(int64_t tid, bool query_os_if_not_found, boo
newti.m_exe = "<NA>";
newti.m_uid = 0xffffffff;
newti.m_gid = 0xffffffff;
newti.m_nchilds = 0;
}

//
// Since this thread is created out of thin air, we need to
// properly set its reference count, by scanning the table
//
threadinfo_map_t* pttable = &m_thread_manager->m_threadtable;
threadinfo_map_iterator_t it;

for(it = pttable->begin(); it != pttable->end(); ++it)
{
if(it->second.m_pid == tid)
{
newti.m_nchilds++;
}
}

//
// Done. Add the new thread to the list.
//
m_thread_manager->add_thread(newti);
sinsp_proc = m_thread_manager->get_thread(tid, lookup_only);
}
Expand Down
1 change: 1 addition & 0 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void sinsp_threadinfo::init(const scap_threadinfo* pi)
m_vmswap_kb = pi->vmswap_kb;
m_pfmajor = pi->pfmajor;
m_pfminor = pi->pfminor;
m_nchilds = 0;

HASH_ITER(hh, pi->fdlist, fdi, tfdi)
{
Expand Down

0 comments on commit 2af3bcb

Please sign in to comment.