Skip to content

Commit

Permalink
libmetrics: freebsd fixes for crashes and disk statistics (BUG153)
Browse files Browse the repository at this point in the history
sanitized version of Koie Hidetaka fixes which are being distributed
already with FreeBSD's port by Brooks
  • Loading branch information
carenas committed Dec 1, 2009
1 parent edc863e commit e908cd9
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions libmetrics/freebsd/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static int mibswap[MIB_SWAPINFO_SIZE];
static size_t mibswap_size;
static kvm_t *kd = NULL;
static int pagesize;
static int skipvfs;
static int skipvfs = 1;

/* Function prototypes */
static long percentages(int cnt, int *out, register long *new,
Expand Down Expand Up @@ -881,7 +881,6 @@ find_disk_space(double *total, double *tot_avail)

netvfslist = makenetvfslist();
vfslist = makevfslist(netvfslist);
free(netvfslist);

mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
mntsize = regetmntinfo(&mntbuf, mntsize, vfslist);
Expand All @@ -899,6 +898,8 @@ find_disk_space(double *total, double *tot_avail)
*tot_avail += mntbuf[i].f_bavail / toru;
}
}
free(vfslist);
free(netvfslist);

return most_full;
}
Expand Down Expand Up @@ -955,7 +956,7 @@ makevfslist(fslist)
return (NULL);
if (fslist[0] == 'n' && fslist[1] == 'o') {
fslist += 2;
skipvfs = 1;
skipvfs = 0;
}
for (i = 0, nextcp = fslist; *nextcp; nextcp++)
if (*nextcp == ',')
Expand Down Expand Up @@ -1007,7 +1008,10 @@ makenetvfslist(void)
goto done;
}

for (cnt = 0; cnt < maxvfsconf; xvfsp++) {
cnt = 0;
for (i = 0; i < maxvfsconf; i++, xvfsp++) {
if (xvfsp->vfc_typenum == 0)
continue;
if (xvfsp->vfc_flags & VFCF_NONLOCAL)
continue;

Expand Down Expand Up @@ -1057,10 +1061,13 @@ makenetvfslist(void)
* Count up the string lengths, we need a extra byte to hold
* the between entries ',' or the NUL at the end.
*/
slen = 0;
for (i = 0; i < cnt; i++)
slen = strlen(listptr[i]) + 1;
/* Add 2 for initial "no". */
slen += 2;
slen += strlen(listptr[i]);
/* for ',' */
slen += cnt - 1;
/* Add 3 for initial "no" and the NUL. */
slen += 3;

if ((str = malloc(slen)) == NULL) {
warnx("malloc failed");
Expand All @@ -1069,10 +1076,11 @@ makenetvfslist(void)

str[0] = 'n';
str[1] = 'o';
for (i = 0, strptr = str + 2; i < cnt; i++, strptr++) {
for (i = 0, strptr = str + 2; i < cnt; i++) {
if (i > 0)
*strptr++ = ',';
strcpy(strptr, listptr[i]);
strptr += strlen(listptr[i]);
*strptr = ',';
}
*strptr = '\0';

Expand Down

0 comments on commit e908cd9

Please sign in to comment.