misc: tweaks (mostly cosmetic) to several source files

. a more appropriate error return code was substituted
. a safer form of comparison is utilized in two places
. a STAT_VAL macro replaced by more proper MEMINFO_VAL
. several of the silly 'xerrx' formats had been missed
. a few whitespace changes have also been incorporated

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-07-24 00:00:00 -05:00 committed by Craig Small
parent 612f36189e
commit 5c857b865e
3 changed files with 29 additions and 33 deletions

View File

@ -303,6 +303,7 @@ static struct dev_node *node_add (
return this;
} // end: node_add
static void node_classify (
struct dev_node *this)
{
@ -319,7 +320,7 @@ static void node_classify (
this->type = DISKSTATS_TYPE_DISK;
return;
}
while((dent = readdir(dirp))) {
while ((dent = readdir(dirp))) {
if (strcmp(this->name, dent->d_name) == 0) {
this->type = DISKSTATS_TYPE_DISK;
break;
@ -578,7 +579,7 @@ static int read_diskstats_failed (
if (rc != 14) {
if (errno != 0)
return -errno;
return -EINVAL;
return -EIO;
}
node.stamped = info->new_stamp;
if ((rc = node_update(info, &node)))
@ -605,27 +606,27 @@ static struct stacks_extent *stacks_alloc (
if (maxstacks < 1)
return NULL;
vect_size = sizeof(void *) * maxstacks; // size of the addr vectors |
vect_size += sizeof(void *); // plus NULL addr delimiter |
head_size = sizeof(struct diskstats_stack); // size of that head struct |
list_size = sizeof(struct diskstats_result) * this->numitems;// any single results stack |
blob_size = sizeof(struct stacks_extent); // the extent anchor itself |
blob_size += vect_size; // plus room for addr vects |
blob_size += head_size * maxstacks; // plus room for head thing |
blob_size += list_size * maxstacks; // plus room for our stacks |
vect_size = sizeof(void *) * maxstacks; // size of the addr vectors |
vect_size += sizeof(void *); // plus NULL addr delimiter |
head_size = sizeof(struct diskstats_stack); // size of that head struct |
list_size = sizeof(struct diskstats_result) * this->numitems; // any single results stack |
blob_size = sizeof(struct stacks_extent); // the extent anchor itself |
blob_size += vect_size; // plus room for addr vects |
blob_size += head_size * maxstacks; // plus room for head thing |
blob_size += list_size * maxstacks; // plus room for our stacks |
/* note: all of our memory is allocated in a single blob, facilitating some later free(). |
as a minimum, it is important that all those result structs themselves always be |
contiguous within every stack since they will be accessed via relative position. | */
/* note: all of our memory is allocated in one single blob, facilitating some later free(). |
as a minimum, it's important that all of those result structs themselves always be |
contiguous within every stack since they will be accessed via a relative position. | */
if (NULL == (p_blob = calloc(1, blob_size)))
return NULL;
p_blob->next = this->extents; // push this extent onto... |
this->extents = p_blob; // ...some existing extents |
p_vect = (void *)p_blob + sizeof(struct stacks_extent); // prime our vector pointer |
p_blob->stacks = p_vect; // set actual vectors start |
v_head = (void *)p_vect + vect_size; // prime head pointer start |
v_list = v_head + (head_size * maxstacks); // prime our stacks pointer |
p_blob->next = this->extents; // push this extent onto... |
this->extents = p_blob; // ...some existing extents |
p_vect = (void *)p_blob + sizeof(struct stacks_extent); // prime our vector pointer |
p_blob->stacks = p_vect; // set actual vectors start |
v_head = (void *)p_vect + vect_size; // prime head pointer start |
v_list = v_head + (head_size * maxstacks); // prime our stacks pointer |
for (i = 0; i < maxstacks; i++) {
p_head = (struct diskstats_stack *)v_head;
@ -963,7 +964,7 @@ PROCPS_EXPORT struct diskstats_stack **procps_diskstats_sort (
if (p->item == sortitem)
break;
++offset;
if (p->item == DISKSTATS_logical_end)
if (p->item >= DISKSTATS_logical_end)
return NULL;
++p;
}

View File

@ -994,7 +994,7 @@ PROCPS_EXPORT struct slabinfo_stack **procps_slabinfo_sort (
if (p->item == sortitem)
break;
++offset;
if (p->item == SLABINFO_logical_end)
if (p->item >= SLABINFO_logical_end)
return NULL;
++p;
}

View File

@ -326,7 +326,7 @@ static void new_format(void)
#define TICv(E) STAT_VAL(E, ull_int, stat_stack)
#define DTICv(E) STAT_VAL(E, sl_int, stat_stack)
#define SYSv(E) STAT_VAL(E, ul_int, stat_stack)
#define MEMv(E) STAT_VAL(E, ul_int, mem_stack)
#define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack)
#define DSYSv(E) STAT_VAL(E, s_int, stat_stack)
const char format[] =
"%2lu %2lu %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u";
@ -536,8 +536,7 @@ static void diskpartition_format(const char *partition_name)
int i;
if (procps_diskstats_new(&disk_stat) < 0)
xerr(EXIT_FAILURE,
_("Unable to create diskstat structure"));
xerrx(EXIT_FAILURE, _("Unable to create diskstat structure"));
if (!(got = procps_diskstats_get(disk_stat, partition_name, DISKSTATS_TYPE)))
xerrx(EXIT_FAILURE, _("Disk/Partition %s not found"), partition_name);
@ -637,16 +636,14 @@ static void diskformat(void)
const char wide_format[] = "%-5s %9lu %9lu %11lu %11lu %9lu %9lu %11lu %11lu %7lu %7lu";
if (procps_diskstats_new(&disk_stat) < 0)
xerr(EXIT_FAILURE,
_("Unable to create diskstat structure"));
xerrx(EXIT_FAILURE, _("Unable to create diskstat structure"));
if (!moreheaders)
diskheader();
for (i=0; infinite_updates || i < num_updates ; i++) {
if (!(reap = procps_diskstats_reap(disk_stat, Disk_items, MAX_disk)))
xerr(EXIT_FAILURE,
_("Unable to retrieve disk statistics"));
xerrx(EXIT_FAILURE, _("Unable to retrieve disk statistics"));
if (t_option) {
(void) time( &the_time );
tm_ptr = localtime( &the_time );
@ -714,7 +711,7 @@ static void slabformat (void)
slab_AOBJS, slab_OBJS, slab_OSIZE, slab_OPS, slab_NAME };
if (procps_slabinfo_new(&slab_info) < 0)
xerr(EXIT_FAILURE, _("Unable to create slabinfo structure"));
xerrx(EXIT_FAILURE, _("Unable to create slabinfo structure"));
if (!moreheaders)
slabheader();
@ -759,11 +756,9 @@ static void disksum_format(void)
disk_count = part_count = 0;
if (procps_diskstats_new(&disk_stat) < 0)
xerr(EXIT_FAILURE,
_("Unable to create diskstat structure"));
xerrx(EXIT_FAILURE, _("Unable to create diskstat structure"));
if (!(reap = procps_diskstats_reap(disk_stat, Disk_items, MAX_disk)))
xerr(EXIT_FAILURE,
_("Unable to retrieve disk statistics"));
xerrx(EXIT_FAILURE, _("Unable to retrieve disk statistics"));
for (j = 0; j < reap->total; j++) {
if (diskVAL(disk_TYPE, s_int) != DISKSTATS_TYPE_DISK) {