library: minor tweaks of program logic and/or comments

This commit just corrects the oversight wherein 'item'
was being employed when 'these' was actually intended.

Also, it trades some 'item' use for a more descriptive
input parameter which henceforth is known as a 'dest'.

And, there was one leftover 'next' pointer eliminated.

Finally, some logic was made a tad less dependent upon
enumerator names and a few comments were also updated.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2015-07-23 00:00:00 -05:00 committed by Craig Small
parent aa7ff688db
commit 63e828fe88
4 changed files with 34 additions and 35 deletions

View File

@ -463,7 +463,7 @@ static int stack_items_valid (
int i; int i;
for (i = 0; i < maxitems; i++) { for (i = 0; i < maxitems; i++) {
if (items[i] < PROCPS_MEMHI_FREE) if (items[i] < 0)
return 0; return 0;
if (items[i] > PROCPS_MEM_stack_end) if (items[i] > PROCPS_MEM_stack_end)
return 0; return 0;
@ -508,7 +508,7 @@ static struct meminfo_stack **procps_meminfo_stacks_alloc (
list_size = sizeof(struct meminfo_result) * maxitems; // a results stack list_size = sizeof(struct meminfo_result) * maxitems; // a results stack
blob_size = sizeof(struct stacks_anchor); // the anchor itself blob_size = sizeof(struct stacks_anchor); // the anchor itself
blob_size += vect_size; // all vectors + delims blob_size += vect_size; // all vectors + delims
blob_size += head_size * maxstacks; // all head structs + user stuff blob_size += head_size * maxstacks; // all head structs
blob_size += list_size * maxstacks; // all results stacks blob_size += list_size * maxstacks; // all results stacks
/* note: all memory is allocated in a single blob, facilitating a later free(). /* note: all memory is allocated in a single blob, facilitating a later free().

View File

@ -441,24 +441,24 @@ reap_em_again:
*/ */
PROCPS_EXPORT int procps_stat_jiffs_get ( PROCPS_EXPORT int procps_stat_jiffs_get (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs *item, struct procps_jiffs *dest,
int which) int which)
{ {
struct procps_jiffs_private *p; struct procps_jiffs_private *p;
int i; int i;
if (info == NULL || item == NULL) if (info == NULL || dest == NULL)
return -EINVAL; return -EINVAL;
if (which < 0) { if (which < 0) {
// note, we're just copying the 'new' portion of our procps_jiffs_private // note, we're just copying the 'new' portion of our procps_jiffs_private
memcpy(item, &info->cpu_summary, sizeof(struct procps_jiffs)); memcpy(dest, &info->cpu_summary, sizeof(struct procps_jiffs));
return 0; return 0;
} }
p = info->jiff_hists; p = info->jiff_hists;
for (i = 0; i < info->jiff_hists_inuse; i++) { for (i = 0; i < info->jiff_hists_inuse; i++) {
if (p->cpu.id == which) { if (p->cpu.id == which) {
// note, we're just copying the 'new' portion of our procps_jiffs_private // note, we're just copying the 'new' portion of our procps_jiffs_private
memcpy(item, p, sizeof(struct procps_jiffs)); memcpy(dest, p, sizeof(struct procps_jiffs));
return 0; return 0;
} }
++p; ++p;
@ -470,30 +470,30 @@ PROCPS_EXPORT int procps_stat_jiffs_get (
* procps_stat_jiffs_fill: * procps_stat_jiffs_fill:
* *
* Refresh available cpu data, then return all cpu data in the caller * Refresh available cpu data, then return all cpu data in the caller
* supplied structures, up to the lesser of numitems or total available. * supplied structures, up to the lesser of maxdests or total available.
* *
* We tolerate a numitems greater than the total available, and * We tolerate a maxdests greater than the total available, and
* the caller had better tolerate fewer returned than requested. * the caller had better tolerate fewer returned than requested.
* *
* This function deals only with the 'current' jiffs counts. * This function deals only with the 'current' jiffs counts.
*/ */
PROCPS_EXPORT int procps_stat_jiffs_fill ( PROCPS_EXPORT int procps_stat_jiffs_fill (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs *item, struct procps_jiffs *dests,
int numitems) int maxdests)
{ {
int i, rc; int i, rc;
if (info == NULL || item == NULL) if (info == NULL || dests == NULL)
return -EINVAL; return -EINVAL;
if ((rc = procps_stat_read_jiffs(info)) < 0) if ((rc = procps_stat_read_jiffs(info)) < 0)
return rc; return rc;
if (!info->jiff_hists_inuse) if (!info->jiff_hists_inuse)
return -1; return -1;
for (i = 0; i < info->jiff_hists_inuse && i < numitems; i++) { for (i = 0; i < info->jiff_hists_inuse && i < maxdests; i++) {
// note, we're just copying the 'new' portion of our procps_jiffs_private // note, we're just copying the 'new' portion of our procps_jiffs_private
memcpy(item + i, info->jiff_hists + i, sizeof(struct procps_jiffs)); memcpy(dests + i, info->jiff_hists + i, sizeof(struct procps_jiffs));
} }
return i; return i;
} }
@ -508,22 +508,22 @@ PROCPS_EXPORT int procps_stat_jiffs_fill (
*/ */
PROCPS_EXPORT int procps_stat_jiffs_hist_get ( PROCPS_EXPORT int procps_stat_jiffs_hist_get (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs_hist *item, struct procps_jiffs_hist *dest,
int which) int which)
{ {
struct procps_jiffs_private *p; struct procps_jiffs_private *p;
int i; int i;
if (info == NULL || item == NULL) if (info == NULL || dest == NULL)
return -EINVAL; return -EINVAL;
if (which < 0) { if (which < 0) {
memcpy(item, &info->cpu_summary, sizeof(struct procps_jiffs_hist)); memcpy(dest, &info->cpu_summary, sizeof(struct procps_jiffs_hist));
return 0; return 0;
} }
p = info->jiff_hists; p = info->jiff_hists;
for (i = 0; i < info->jiff_hists_inuse; i++) { for (i = 0; i < info->jiff_hists_inuse; i++) {
if (p->cpu.id == which) { if (p->cpu.id == which) {
memcpy(item, p, sizeof(struct procps_jiffs_hist)); memcpy(dest, p, sizeof(struct procps_jiffs_hist));
return 0; return 0;
} }
++p; ++p;
@ -535,29 +535,29 @@ PROCPS_EXPORT int procps_stat_jiffs_hist_get (
* procps_stat_jiffs_hist_fill: * procps_stat_jiffs_hist_fill:
* *
* Refresh available cpu data, then return all cpu data in the caller * Refresh available cpu data, then return all cpu data in the caller
* supplied structures, up to the lesser of numitems or total available. * supplied structures, up to the lesser of maxdests or total available.
* *
* We tolerate a numitems greater than the total available, and * We tolerate a maxdests greater than the total available, and
* the caller had better tolerate fewer returned than requested. * the caller had better tolerate fewer returned than requested.
* *
* This function provides both 'new' and 'old' jiffs counts. * This function provides both 'new' and 'old' jiffs counts.
*/ */
PROCPS_EXPORT int procps_stat_jiffs_hist_fill ( PROCPS_EXPORT int procps_stat_jiffs_hist_fill (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs_hist *item, struct procps_jiffs_hist *dests,
int numitems) int maxdests)
{ {
int i, rc; int i, rc;
if (info == NULL || item == NULL) if (info == NULL || dests == NULL)
return -EINVAL; return -EINVAL;
if ((rc = procps_stat_read_jiffs(info)) < 0) if ((rc = procps_stat_read_jiffs(info)) < 0)
return rc; return rc;
if (!info->jiff_hists_inuse) if (!info->jiff_hists_inuse)
return -1; return -1;
for (i = 0; i < info->jiff_hists_inuse && i < numitems; i++) { for (i = 0; i < info->jiff_hists_inuse && i < maxdests; i++) {
memcpy(item + i, info->jiff_hists + i, sizeof(struct procps_jiffs_hist)); memcpy(dests + i, info->jiff_hists + i, sizeof(struct procps_jiffs_hist));
} }
return i; return i;
} }

View File

@ -66,7 +66,6 @@ struct stat_result {
unsigned int u_int; unsigned int u_int;
jiff jiff; jiff jiff;
} result; } result;
struct stat_result *next;
}; };
struct procps_stat; struct procps_stat;
@ -84,27 +83,27 @@ jiff procps_stat_cpu_get (
int procps_stat_cpu_getstack ( int procps_stat_cpu_getstack (
struct procps_stat *info, struct procps_stat *info,
struct stat_result *item); struct stat_result *these);
int procps_stat_jiffs_get ( int procps_stat_jiffs_get (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs *item, struct procps_jiffs *dest,
int which); int which);
int procps_stat_jiffs_hist_get ( int procps_stat_jiffs_hist_get (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs_hist *item, struct procps_jiffs_hist *dest,
int which); int which);
int procps_stat_jiffs_fill ( int procps_stat_jiffs_fill (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs *item, struct procps_jiffs *dests,
int numitems); int maxdests);
int procps_stat_jiffs_hist_fill ( int procps_stat_jiffs_hist_fill (
struct procps_stat *info, struct procps_stat *info,
struct procps_jiffs_hist *item, struct procps_jiffs_hist *dests,
int numitems); int maxdests);
unsigned int procps_stat_sys_get ( unsigned int procps_stat_sys_get (
struct procps_stat *info, struct procps_stat *info,
@ -112,7 +111,7 @@ unsigned int procps_stat_sys_get (
int procps_stat_sys_getstack ( int procps_stat_sys_getstack (
struct procps_stat *info, struct procps_stat *info,
struct stat_result *item); struct stat_result *these);
__END_DECLS __END_DECLS
#endif #endif

View File

@ -689,7 +689,7 @@ static int stack_items_valid (
int i; int i;
for (i = 0; i < maxitems; i++) { for (i = 0; i < maxitems; i++) {
if (items[i] < PROCPS_SLABNODE_SIZE) if (items[i] < 0)
return 0; return 0;
if (items[i] > PROCPS_SLABNODE_stack_end) if (items[i] > PROCPS_SLABNODE_stack_end)
return 0; return 0;
@ -737,7 +737,7 @@ PROCPS_EXPORT struct slabnode_stack **procps_slabnode_stacks_alloc (
list_size = sizeof(struct slab_result) * maxitems; // a results stack list_size = sizeof(struct slab_result) * maxitems; // a results stack
blob_size = sizeof(struct stacks_anchor); // the anchor itself blob_size = sizeof(struct stacks_anchor); // the anchor itself
blob_size += vect_size; // all vectors + delims blob_size += vect_size; // all vectors + delims
blob_size += head_size * maxstacks; // all head structs + user stuff blob_size += head_size * maxstacks; // all head structs
blob_size += list_size * maxstacks; // all results stacks blob_size += list_size * maxstacks; // all results stacks
/* note: all memory is allocated in a single blob, facilitating a later free(). /* note: all memory is allocated in a single blob, facilitating a later free().