Replace all occurrences of `strcpy' with `sstrncpy'.
[collectd.git] / src / disk.c
index 490da07..536c511 100644 (file)
@@ -164,8 +164,8 @@ static void disk_submit (const char *plugin_instance,
        vl.values = values;
        vl.values_len = 2;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname_g);
-       strcpy (vl.plugin, "disk");
+       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
        strncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
 
@@ -231,22 +231,14 @@ static int disk_read (void)
        int  disk_minor;
        char disk_name[64];
 
-       static complain_t complain_obj;
-
        /* Get the list of all disk objects. */
        if (IOServiceGetMatchingServices (io_master_port,
                                IOServiceMatching (kIOBlockStorageDriverClass),
                                &disk_list) != kIOReturnSuccess)
        {
-               plugin_complain (LOG_ERR, &complain_obj, "disk plugin: "
-                               "IOServiceGetMatchingServices failed.");
+               ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
                return (-1);
        }
-       else if (complain_obj.interval != 0)
-       {
-               plugin_relief (LOG_NOTICE, &complain_obj, "disk plugin: "
-                               "IOServiceGetMatchingServices succeeded.");
-       }
 
        while ((disk = IOIteratorNext (disk_list)) != 0)
        {
@@ -386,15 +378,12 @@ static int disk_read (void)
 
        diskstats_t *ds, *pre_ds;
 
-       static complain_t complain_obj;
-
        if ((fh = fopen ("/proc/diskstats", "r")) == NULL)
        {
-               if ((fh = fopen ("/proc/partitions", "r")) == NULL)
+               fh = fopen ("/proc/partitions", "r");
+               if (fh == NULL)
                {
-                       plugin_complain (LOG_ERR, &complain_obj,
-                                       "disk plugin: Failed to open /proc/"
-                                       "{diskstats,partitions}.");
+                       ERROR ("disk plugin: fopen (/proc/{diskstats,partitions}) failed.");
                        return (-1);
                }
 
@@ -402,9 +391,6 @@ static int disk_read (void)
                fieldshift = 1;
        }
 
-       plugin_relief (LOG_NOTICE, &complain_obj, "disk plugin: "
-                       "Succeeded to open /proc/{diskstats,partitions}.");
-
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
                char *disk_name;
@@ -417,7 +403,7 @@ static int disk_read (void)
                major = atoll (fields[0]);
                minor = atoll (fields[1]);
 
-               disk_name = fields[2];
+               disk_name = fields[2 + fieldshift];
 
                for (ds = disklist, pre_ds = disklist; ds != NULL; pre_ds = ds, ds = ds->next)
                        if (strcmp (disk_name, ds->name) == 0)
@@ -576,9 +562,8 @@ static int disk_read (void)
 
                if (is_disk)
                {
-                       if ((read_merged != -1LL) || (write_merged != -1LL))
-                               disk_submit (disk_name, "disk_merged",
-                                               read_merged, write_merged);
+                       disk_submit (disk_name, "disk_merged",
+                                       read_merged, write_merged);
                } /* if (is_disk) */
        } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */