Skip to content

Commit

Permalink
cleanup(scap): move scap_alloc_proclist_info to scap_procs.c
Browse files Browse the repository at this point in the history
Signed-off-by: Grzegorz Nosek <[email protected]>
  • Loading branch information
gnosek authored and poiana committed Nov 10, 2023
1 parent a85056c commit 3284fa8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
33 changes: 0 additions & 33 deletions userspace/libscap/scap.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,39 +464,6 @@ const char* scap_get_host_root()
return env_str;
}

bool scap_alloc_proclist_info(struct ppm_proclist_info **proclist_p, uint32_t n_entries, char* error)
{
uint32_t memsize;

if(n_entries >= SCAP_DRIVER_PROCINFO_MAX_SIZE)
{
snprintf(error, SCAP_LASTERR_SIZE, "driver process list too big");
return false;
}

memsize = sizeof(struct ppm_proclist_info) +
sizeof(struct ppm_proc_info) * n_entries;

struct ppm_proclist_info *procinfo = (struct ppm_proclist_info*) realloc(*proclist_p, memsize);
if(procinfo == NULL)
{
free(*proclist_p);
*proclist_p = NULL;
snprintf(error, SCAP_LASTERR_SIZE, "driver process list allocation error");
return false;
}

if(*proclist_p == NULL)
{
procinfo->n_entries = 0;
}

procinfo->max_entries = n_entries;
*proclist_p = procinfo;

return true;
}

uint64_t scap_ftell(scap_t *handle)
{
if(handle->m_vtable->savefile_ops)
Expand Down
32 changes: 32 additions & 0 deletions userspace/libscap/scap_procs.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,36 @@ void init_proclist(struct scap_proclist* proclist, proc_entry_callback callback,
}

proclist->m_proclist = NULL;
}
bool scap_alloc_proclist_info(struct ppm_proclist_info **proclist_p, uint32_t n_entries, char* error)
{
uint32_t memsize;

if(n_entries >= SCAP_DRIVER_PROCINFO_MAX_SIZE)
{
snprintf(error, SCAP_LASTERR_SIZE, "driver process list too big");
return false;
}

memsize = sizeof(struct ppm_proclist_info) +
sizeof(struct ppm_proc_info) * n_entries;

struct ppm_proclist_info *procinfo = (struct ppm_proclist_info*) realloc(*proclist_p, memsize);
if(procinfo == NULL)
{
free(*proclist_p);
*proclist_p = NULL;
snprintf(error, SCAP_LASTERR_SIZE, "driver process list allocation error");
return false;
}

if(*proclist_p == NULL)
{
procinfo->n_entries = 0;
}

procinfo->max_entries = n_entries;
*proclist_p = procinfo;

return true;
}

0 comments on commit 3284fa8

Please sign in to comment.