Added "type" to the value_list_t struct.
[collectd.git] / src / battery.c
index 952c56c..0522015 100644 (file)
 #  include <IOKit/ps/IOPSKeys.h>
 #endif
 
-#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H || KERNEL_LINUX
-# define BATTERY_HAVE_READ 1
-#else
-# define BATTERY_HAVE_READ 0
+#if !HAVE_IOKIT_IOKITLIB_H && !HAVE_IOKIT_PS_IOPOWERSOURCES_H && !KERNEL_LINUX
+# error "No applicable input method."
 #endif
 
 #define INVALID_VALUE 47841.29
 
-#if BATTERY_HAVE_READ
 #if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
        /* No global variables */
 /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
@@ -80,7 +77,7 @@ static int battery_init (void)
        {
                len = snprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num);
 
-               if ((len >= sizeof (filename)) || (len < 0))
+               if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
                        break;
 
                if (access (filename, R_OK))
@@ -103,9 +100,10 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl
        vl.time = time (NULL);
        strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "battery");
-       strcpy (vl.plugin_instance, plugin_instance);
+       strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+       strncpy (vl.type, type, sizeof (vl.type));
 
-       plugin_dispatch_values (type, &vl);
+       plugin_dispatch_values (&vl);
 } /* void battery_submit */
 
 #if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
@@ -363,11 +361,11 @@ static int battery_read (void)
                double *valptr = NULL;
 
                len = snprintf (filename, sizeof (filename), battery_pmu_file, i);
-               if ((len >= sizeof (filename)) || (len < 0))
+               if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
                        continue;
 
                len = snprintf (batnum_str, sizeof (batnum_str), "%i", i);
-               if ((len >= sizeof (batnum_str)) || (len < 0))
+               if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str)))
                        continue;
 
                if ((fh = fopen (filename, "r")) == NULL)
@@ -441,7 +439,7 @@ static int battery_read (void)
                        len = snprintf (filename, sizeof (filename),
                                        "/proc/acpi/battery/%s/state",
                                        ent->d_name);
-                       if ((len >= sizeof (filename)) || (len < 0))
+                       if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
                                continue;
 
                        if ((fh = fopen (filename, "r")) == NULL)
@@ -523,12 +521,9 @@ static int battery_read (void)
 
        return (0);
 }
-#endif /* BATTERY_HAVE_READ */
 
 void module_register (void)
 {
-#if BATTERY_HAVE_READ
        plugin_register_init ("battery", battery_init);
        plugin_register_read ("battery", battery_read);
-#endif /* BATTERY_HAVE_READ */
 } /* void module_register */