/**
* collectd - src/utils_mount.c
- * Copyright (C) 2005 Niki W. Waibel
+ * Copyright (C) 2005,2006 Niki W. Waibel
*
* This program is free software; you can redistribute it and/
* or modify it under the terms of the GNU General Public Li-
#define XFS_SUPER_MAGIC_STR "XFSB"
#define XFS_SUPER_MAGIC2_STR "BSFX"
#endif
+
#include "utils_debug.h"
#include "utils_mount.h"
# include <sys/mnttab.h>
#endif
-#ifndef MNTTAB
-# if defined(_PATH_MOUNTED)
-# define MNTTAB _PATH_MOUNTED
-# elif defined(MNT_MNTTAB)
-# define MNTTAB MNT_MNTTAB
-# elif defined(MNTTABNAME)
-# define MNTTAB MNTTABNAME
-# elif defined(KMTAB)
-# define MNTTAB KMTAB
-# else
-# define MNTTAB "/etc/mnttab"
-# endif
+#if HAVE_PATHS_H
+# include <paths.h>
+#endif
+
+#ifdef COLLECTD_MNTTAB
+# undef COLLECTD_MNTTAB
+#endif
+
+#if defined(_PATH_MOUNTED) /* glibc */
+# define COLLECTD_MNTTAB _PATH_MOUNTED
+#elif defined(MNTTAB) /* Solaris */
+# define COLLECTD_MNTTAB MNTTAB
+#elif defined(MNT_MNTTAB)
+# define COLLECTD_MNTTAB MNT_MNTTAB
+#elif defined(MNTTABNAME)
+# define COLLECTD_MNTTAB MNTTABNAME
+#elif defined(KMTAB)
+# define COLLECTD_MNTTAB KMTAB
+#else
+# define COLLECTD_MNTTAB "/etc/mnttab"
#endif
/* *** *** *** ********************************************* *** *** *** */
struct mntent *mnt;
struct tabmntent *mntlist;
- if(listmntent(&mntlist, MNTTAB, NULL, NULL) < 0) {
+ if(listmntent(&mntlist, COLLECTD_MNTTAB, NULL, NULL) < 0) {
DBG("calling listmntent() failed: %s", strerror(errno));
}
/* Get the number of mounted file systems */
if ((bufsize = getfsstat (NULL, 0, MNT_NOWAIT)) < 1)
+ {
+ DBG ("getfsstat failed: %s", strerror (errno));
return (NULL);
+ }
- if ((buf = (struct statfs *) malloc (bufsize * sizeof (struct statfs))) == NULL)
+ if ((buf = (struct statfs *) malloc (bufsize * sizeof (struct statfs)))
+ == NULL)
return (NULL);
memset (buf, '\0', bufsize * sizeof (struct statfs));
- /* FIXME: If `bufsize' in bytes or structures? */
- if ((num = getfsstat (buf, bufsize, MNT_NOWAIT)) < 1)
+ /* The bufsize needs to be passed in bytes. Really. This is not in the
+ * manpage.. -octo */
+ if ((num = getfsstat (buf, bufsize * sizeof (struct statfs), MNT_NOWAIT)) < 1)
{
+ DBG ("getfsstat failed: %s", strerror (errno));
free (buf);
return (NULL);
}
cu_mount_t *last = NULL;
cu_mount_t *new = NULL;
- if ((fp = fopen (MNTTAB, "r")) == NULL)
+ DBG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
+
+ if ((fp = fopen (COLLECTD_MNTTAB, "r")) == NULL)
+ {
+ syslog (LOG_ERR, "fopen (%s): %s", COLLECTD_MNTTAB, strerror (errno));
return (NULL);
+ }
while (getmntent (fp, &mt) == 0)
{
cu_mount_t *last = NULL;
cu_mount_t *new = NULL;
- if ((fp = setmntent (MNTTAB, "r")) == NULL)
+ DBG ("(void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
+
+ if ((fp = setmntent (COLLECTD_MNTTAB, "r")) == NULL)
+ {
+ syslog (LOG_ERR, "setmntent (%s): %s", COLLECTD_MNTTAB, strerror (errno));
return (NULL);
+ }
while ((me = getmntent (fp)) != NULL)
{
new->device = get_device_name (new->options);
new->next = NULL;
+ DBG ("new = {dir = %s, spec_device = %s, type = %s, options = %s, device = %s}",
+ new->dir, new->spec_device, new->type, new->options, new->device);
+
/* Append to list */
if (first == NULL)
{
endmntent (fp);
+ DBG ("return (0x%p)", (void *) first);
+
return (first);
}
#endif /* HAVE_GETMNTENT */
cu_mount_t *this;
cu_mount_t *next;
+ DBG ("(list = 0x%p)", (void *) list);
+
for (this = list; this != NULL; this = next)
{
next = this->next;