Skip to content

Commit

Permalink
update(userspace/libscap,userspace/libsinsp): in nodriver mode, avoid…
Browse files Browse the repository at this point in the history
… loading proc, users and interfaces related informations.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 9, 2021
1 parent 396f2c9 commit 11f87d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 57 deletions.
55 changes: 7 additions & 48 deletions userspace/libscap/scap.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,7 @@ scap_t* scap_open_live(char *error, int32_t *rc)
return scap_open_live_int(error, rc, NULL, NULL, true, NULL, NULL);
}

scap_t* scap_open_nodriver_int(char *error, int32_t *rc,
proc_entry_callback proc_callback,
void* proc_callback_context,
bool import_users)
scap_t* scap_open_nodriver_int(char *error, int32_t *rc)
{
#if !defined(HAS_CAPTURE)
snprintf(error, SCAP_LASTERR_SIZE, "live capture not supported on %s", PLATFORM_NAME);
Expand Down Expand Up @@ -865,8 +862,8 @@ scap_t* scap_open_nodriver_int(char *error, int32_t *rc,
//
// Extract machine information
//
handle->m_proc_callback = proc_callback;
handle->m_proc_callback_context = proc_callback_context;
handle->m_proc_callback = NULL;
handle->m_proc_callback_context = NULL;
#ifdef _WIN32
handle->m_machine_info.num_cpus = 0;
handle->m_machine_info.memory_size_bytes = 0;
Expand Down Expand Up @@ -898,52 +895,16 @@ scap_t* scap_open_nodriver_int(char *error, int32_t *rc,
handle->m_win_descs_handle = NULL;
#endif

//
// Create the interface list
//
if((*rc = scap_create_iflist(handle)) != SCAP_SUCCESS)
{
scap_close(handle);
snprintf(error, SCAP_LASTERR_SIZE, "error creating the interface list");
return NULL;
}

//
// Create the user list
//
if(import_users)
{
if((*rc = scap_create_userlist(handle)) != SCAP_SUCCESS)
{
scap_close(handle);
snprintf(error, SCAP_LASTERR_SIZE, "error creating the interface list");
return NULL;
}
}
else
{
handle->m_userlist = NULL;
}
handle->m_userlist = NULL;
handle->m_proclist = NULL;

handle->m_fake_kernel_proc.tid = -1;
handle->m_fake_kernel_proc.pid = -1;
handle->m_fake_kernel_proc.flags = 0;
snprintf(handle->m_fake_kernel_proc.comm, SCAP_MAX_PATH_SIZE, "kernel");
snprintf(handle->m_fake_kernel_proc.exe, SCAP_MAX_PATH_SIZE, "kernel");
handle->m_fake_kernel_proc.args[0] = 0;
handle->refresh_proc_table_when_saving = true;

//
// Create the process list
//
error[0] = '\0';
snprintf(filename, sizeof(filename), "%s/proc", scap_get_host_root());
if((*rc = scap_proc_scan_proc_dir(handle, filename, error)) != SCAP_SUCCESS)
{
scap_close(handle);
snprintf(error, SCAP_LASTERR_SIZE, "scap_open_live() error creating the process list. Make sure you have root credentials.");
return NULL;
}
handle->refresh_proc_table_when_saving = false;

return handle;
#endif // HAS_CAPTURE
Expand Down Expand Up @@ -1086,9 +1047,7 @@ scap_t* scap_open(scap_open_args args, char *error, int32_t *rc)
return NULL;
#endif
case SCAP_MODE_NODRIVER:
return scap_open_nodriver_int(error, rc, args.proc_callback,
args.proc_callback_context,
args.import_users);
return scap_open_nodriver_int(error, rc);
case SCAP_MODE_PLUGIN:
return scap_open_plugin_int(error, rc, args.input_plugin, args.input_plugin_params);
case SCAP_MODE_NONE:
Expand Down
10 changes: 1 addition & 9 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,6 @@ void sinsp::open_nodriver()
scap_open_args oargs;
oargs.mode = SCAP_MODE_NODRIVER;
oargs.fname = NULL;
oargs.proc_callback = NULL;
oargs.proc_callback_context = NULL;
if(!m_filter_proc_table_when_saving)
{
oargs.proc_callback = ::on_new_entry_from_proc;
oargs.proc_callback_context = this;
}
oargs.import_users = m_import_users;

int32_t scap_rc;
m_h = scap_open(oargs, error, &scap_rc);
Expand All @@ -558,7 +550,7 @@ void sinsp::open_nodriver()
throw scap_open_exception(error, scap_rc);
}

scap_set_refresh_proc_table_when_saving(m_h, !m_filter_proc_table_when_saving);
m_filter_proc_table_when_saving = false;

init();
}
Expand Down

0 comments on commit 11f87d3

Please sign in to comment.