projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1856 from rubenk/snmp-dont-dispatch-values-with-empty-type-instance
[collectd.git]
/
src
/
utils_mount.c
diff --git
a/src/utils_mount.c
b/src/utils_mount.c
index
014620c
..
b8dabb1
100644
(file)
--- a/
src/utils_mount.c
+++ b/
src/utils_mount.c
@@
-20,18
+20,25
@@
* Niki W. Waibel <niki.waibel@gmx.net>
**/
* Niki W. Waibel <niki.waibel@gmx.net>
**/
-#include "collectd.h"
-#include "utils_mount.h"
-
-#include "common.h" /* sstrncpy() et alii */
-#include "plugin.h" /* ERROR() macro */
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
#if HAVE_XFS_XQM_H
#if HAVE_XFS_XQM_H
+# define _GNU_SOURCE
# include <xfs/xqm.h>
#define XFS_SUPER_MAGIC_STR "XFSB"
#define XFS_SUPER_MAGIC2_STR "BSFX"
#endif
# include <xfs/xqm.h>
#define XFS_SUPER_MAGIC_STR "XFSB"
#define XFS_SUPER_MAGIC2_STR "BSFX"
#endif
+#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 <sys/types.h>
#if HAVE_GETVFSSTAT
# if HAVE_SYS_TYPES_H
# include <sys/types.h>
@@
-209,7
+216,6
@@
uuidcache_init(void)
FILE *procpt;
char uuid[16], *label = NULL;
char device[110];
FILE *procpt;
char uuid[16], *label = NULL;
char device[110];
- int firstPass;
int handleOnFirst;
if(uuidCache) {
int handleOnFirst;
if(uuidCache) {
@@
-221,7
+227,7
@@
uuidcache_init(void)
return;
}
return;
}
- for(firstPass = 1; firstPass >= 0; firstPass--) {
+ for(
int
firstPass = 1; firstPass >= 0; firstPass--) {
fseek(procpt, 0, SEEK_SET);
while(fgets(line, sizeof(line), procpt)) {
if(sscanf(line, " %d %d %d %[^\n ]",
fseek(procpt, 0, SEEK_SET);
while(fgets(line, sizeof(line), procpt)) {
if(sscanf(line, " %d %d %d %[^\n ]",
@@
-311,14
+317,13
@@
static char *
get_spec_by_uuid(const char *s)
{
char uuid[16];
get_spec_by_uuid(const char *s)
{
char uuid[16];
- int i;
if(strlen(s) != 36
|| s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-') {
goto bad_uuid;
}
if(strlen(s) != 36
|| s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-') {
goto bad_uuid;
}
- for(i=0; i<16; i++) {
+ for(i
nt i
=0; i<16; i++) {
if(*s == '-') {
s++;
}
if(*s == '-') {
s++;
}
@@
-375,7
+380,6
@@
static char *get_device_name(const char *optstr)
static cu_mount_t *cu_mount_listmntent (void)
{
cu_mount_t *last = *list;
static cu_mount_t *cu_mount_listmntent (void)
{
cu_mount_t *last = *list;
- struct tabmntent *p;
struct mntent *mnt;
struct tabmntent *mntlist;
struct mntent *mnt;
struct tabmntent *mntlist;
@@
-387,7
+391,7
@@
static cu_mount_t *cu_mount_listmntent (void)
#endif /* COLLECT_DEBUG */
}
#endif /* COLLECT_DEBUG */
}
- for(p = mntlist; p; p = p->next) {
+ for(
struct tabmntent *
p = mntlist; p; p = p->next) {
char *loop = NULL, *device = NULL;
mnt = p->ment;
char *loop = NULL, *device = NULL;
mnt = p->ment;
@@
-429,22
+433,21
@@
static cu_mount_t *cu_mount_listmntent (void)
#elif HAVE_GETVFSSTAT || HAVE_GETFSSTAT
static cu_mount_t *cu_mount_getfsstat (void)
{
#elif HAVE_GETVFSSTAT || HAVE_GETFSSTAT
static cu_mount_t *cu_mount_getfsstat (void)
{
-#if HAVE_GETVFSSTAT
-# define STRUCT_STATFS struct statvfs
-# define CMD_STATFS getvfsstat
-# define FLAGS_STATFS ST_NOWAIT
-/* #endif HAVE_GETVFSSTAT */
-#elif HAVE_GETFSSTAT
+#if HAVE_GETFSSTAT
# define STRUCT_STATFS struct statfs
# define CMD_STATFS getfsstat
# define FLAGS_STATFS MNT_NOWAIT
# define STRUCT_STATFS struct statfs
# define CMD_STATFS getfsstat
# define FLAGS_STATFS MNT_NOWAIT
-#endif /* HAVE_GETFSSTAT */
+/* #endif HAVE_GETFSSTAT */
+#elif HAVE_GETVFSSTAT
+# define STRUCT_STATFS struct statvfs
+# define CMD_STATFS getvfsstat
+# define FLAGS_STATFS ST_NOWAIT
+#endif /* HAVE_GETVFSSTAT */
int bufsize;
STRUCT_STATFS *buf;
int num;
int bufsize;
STRUCT_STATFS *buf;
int num;
- int i;
cu_mount_t *first = NULL;
cu_mount_t *last = NULL;
cu_mount_t *first = NULL;
cu_mount_t *last = NULL;
@@
-461,10
+464,8
@@
static cu_mount_t *cu_mount_getfsstat (void)
return (NULL);
}
return (NULL);
}
- if ((buf = (STRUCT_STATFS *) malloc (bufsize * sizeof (STRUCT_STATFS)))
- == NULL)
+ if ((buf = calloc (bufsize, sizeof (*buf))) == NULL)
return (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 */
/* The bufsize needs to be passed in bytes. Really. This is not in the
* manpage.. -octo */
@@
-479,12
+480,11
@@
static cu_mount_t *cu_mount_getfsstat (void)
return (NULL);
}
return (NULL);
}
- for (i = 0; i < num; i++)
+ for (i
nt i
= 0; i < num; i++)
{
{
- if ((new =
malloc (sizeof (cu_mount_t
))) == NULL)
+ if ((new =
calloc (1, sizeof (*new
))) == NULL)
break;
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);
/* Copy values from `struct mnttab' */
new->dir = sstrdup (buf[i].f_mntonname);
new->spec_device = sstrdup (buf[i].f_mntfromname);
@@
-535,10
+535,9
@@
static cu_mount_t *cu_mount_gen_getmntent (void)
while (getmntent (fp, &mt) == 0)
{
while (getmntent (fp, &mt) == 0)
{
- if ((new =
malloc (sizeof (cu_mount_t
))) == NULL)
+ if ((new =
calloc (1, sizeof (*new
))) == NULL)
break;
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);
/* Copy values from `struct mnttab' */
new->dir = sstrdup (mt.mnt_mountp);
new->spec_device = sstrdup (mt.mnt_special);
@@
-593,9
+592,8
@@
static cu_mount_t *cu_mount_getmntent (void)
while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) ))
{
while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) ))
{
- if ((new =
malloc (sizeof (cu_mount_t
))) == NULL)
+ if ((new =
calloc (1, sizeof (*new
))) == NULL)
break;
break;
- memset (new, '\0', sizeof (cu_mount_t));
/* Copy values from `struct mntent *' */
new->dir = sstrdup (me.mnt_dir);
/* Copy values from `struct mntent *' */
new->dir = sstrdup (me.mnt_dir);
@@
-650,10
+648,9
@@
static cu_mount_t *cu_mount_getmntent (void)
while ((me = getmntent (fp)) != NULL)
{
while ((me = getmntent (fp)) != NULL)
{
- if ((new =
malloc (sizeof (cu_mount_t
))) == NULL)
+ if ((new =
calloc (1, sizeof (*new
))) == NULL)
break;
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);
/* Copy values from `struct mntent *' */
new->dir = sstrdup (me->mnt_dir);
new->spec_device = sstrdup (me->mnt_fsname);
@@
-740,10
+737,9
@@
cu_mount_t *cu_mount_getlist(cu_mount_t **list)
void cu_mount_freelist (cu_mount_t *list)
{
void cu_mount_freelist (cu_mount_t *list)
{
- cu_mount_t *this;
cu_mount_t *next;
cu_mount_t *next;
- for (this = list; this != NULL; this = next)
+ for (
cu_mount_t *
this = list; this != NULL; this = next)
{
next = this->next;
{
next = this->next;
@@
-798,7
+794,7
@@
cu_mount_checkoption(char *line, const char *keyword, int full)
} /* char *cu_mount_checkoption(char *line, char *keyword, int full) */
char *
} /* char *cu_mount_checkoption(char *line, char *keyword, int full) */
char *
-cu_mount_getoptionvalue(char *line, char *keyword)
+cu_mount_getoptionvalue(char *line, c
onst c
har *keyword)
{
char *r;
{
char *r;
@@
-814,13
+810,13
@@
cu_mount_getoptionvalue(char *line, char *keyword)
if((p-r) == 1) {
return NULL;
}
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;
sstrncpy(m, r, p-r+1);
return m;
}
}
return r;
-} /* char *cu_mount_getoptionvalue(char *line, char *keyword) */
+} /* char *cu_mount_getoptionvalue(char *line, c
onst c
har *keyword) */
int
cu_mount_type(const char *type)
int
cu_mount_type(const char *type)