Added "type" to the value_list_t struct.
[collectd.git] / src / battery.c
index 2e27e60..0522015 100644 (file)
@@ -77,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))
@@ -100,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
@@ -360,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)
@@ -438,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)