X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Futils_mount.c;h=a2e96a65e43dca1aca8272fa7f33c1ab6d42a163;hb=6fd0d2574fc386c2724c8307d33b12529b30048b;hp=d303677d4e6b0f88b2153fcd85b17a5ab50b7f3a;hpb=865a6c83250e3d4381596a0d937df31d563f97c6;p=collectd.git diff --git a/src/utils_mount.c b/src/utils_mount.c index d303677d..a2e96a65 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -31,10 +31,14 @@ #define XFS_SUPER_MAGIC2_STR "BSFX" #endif -#include "common.h" -#include "plugin.h" +#include "collectd.h" + #include "utils_mount.h" +#include "common.h" /* sstrncpy() et alii */ +#include "plugin.h" /* ERROR() macro */ + + #if HAVE_GETVFSSTAT # if HAVE_SYS_TYPES_H # include @@ -464,10 +468,8 @@ static cu_mount_t *cu_mount_getfsstat (void) return (NULL); } - if ((buf = (STRUCT_STATFS *) malloc (bufsize * sizeof (STRUCT_STATFS))) - == NULL) + if ((buf = calloc (bufsize, sizeof (*buf))) == NULL) return (NULL); - memset (buf, '\0', bufsize * sizeof (STRUCT_STATFS)); /* The bufsize needs to be passed in bytes. Really. This is not in the * manpage.. -octo */ @@ -484,10 +486,9 @@ static cu_mount_t *cu_mount_getfsstat (void) for (i = 0; i < num; i++) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); - + /* Copy values from `struct mnttab' */ new->dir = sstrdup (buf[i].f_mntonname); new->spec_device = sstrdup (buf[i].f_mntfromname); @@ -538,10 +539,9 @@ static cu_mount_t *cu_mount_gen_getmntent (void) while (getmntent (fp, &mt) == 0) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); - + /* Copy values from `struct mnttab' */ new->dir = sstrdup (mt.mnt_mountp); new->spec_device = sstrdup (mt.mnt_special); @@ -596,9 +596,8 @@ static cu_mount_t *cu_mount_getmntent (void) while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) )) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); /* Copy values from `struct mntent *' */ new->dir = sstrdup (me.mnt_dir); @@ -653,10 +652,9 @@ static cu_mount_t *cu_mount_getmntent (void) while ((me = getmntent (fp)) != NULL) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = calloc (1, sizeof (*new))) == NULL) break; - memset (new, '\0', sizeof (cu_mount_t)); - + /* Copy values from `struct mntent *' */ new->dir = sstrdup (me->mnt_dir); new->spec_device = sstrdup (me->mnt_fsname); @@ -760,7 +758,7 @@ void cu_mount_freelist (cu_mount_t *list) } /* void cu_mount_freelist(cu_mount_t *list) */ char * -cu_mount_checkoption(char *line, char *keyword, int full) +cu_mount_checkoption(char *line, const char *keyword, int full) { char *line2, *l2, *p1, *p2; int l; @@ -801,7 +799,7 @@ cu_mount_checkoption(char *line, char *keyword, int full) } /* char *cu_mount_checkoption(char *line, char *keyword, int full) */ char * -cu_mount_getoptionvalue(char *line, char *keyword) +cu_mount_getoptionvalue(char *line, const char *keyword) { char *r; @@ -817,13 +815,13 @@ cu_mount_getoptionvalue(char *line, char *keyword) if((p-r) == 1) { return NULL; } - m = (char *)smalloc(p-r+1); + m = smalloc(p-r+1); sstrncpy(m, r, p-r+1); return m; } } return r; -} /* char *cu_mount_getoptionvalue(char *line, char *keyword) */ +} /* char *cu_mount_getoptionvalue(char *line, const char *keyword) */ int cu_mount_type(const char *type)