disk plugin: Coding style changes.
authorRobert Viduya <robert@oit.gatech.edu>
Wed, 3 Jun 2015 12:34:37 +0000 (08:34 -0400)
committerFlorian Forster <octo@collectd.org>
Sat, 6 Jun 2015 19:07:57 +0000 (21:07 +0200)
I also reorganized the code to try to keep the CFReleases and
IOObjectReleases a little more manageable.

Signed-off-by: Florian Forster <octo@collectd.org>
src/disk.c

index 261570c..1c3dd98 100644 (file)
@@ -400,44 +400,32 @@ static int disk_read (void)
        CFStringRef             tmp_cf_string_ref;
        kern_return_t           status;
 
-       signed long long read_ops;
-       signed long long read_byt;
-       signed long long read_tme;
-       signed long long write_ops;
-       signed long long write_byt;
-       signed long long write_tme;
-
-       int  disk_major;
-       int  disk_minor;
+       signed long long read_ops, read_byt, read_tme;
+       signed long long write_ops, write_byt, write_tme;
+
+       int  disk_major, disk_minor;
        char disk_name[DATA_MAX_NAME_LEN];
        char child_disk_name_bsd[DATA_MAX_NAME_LEN], props_disk_name_bsd[DATA_MAX_NAME_LEN];
 
        /* Get the list of all disk objects. */
-       if (IOServiceGetMatchingServices (io_master_port,
-                               IOServiceMatching (kIOBlockStorageDriverClass),
-                               &disk_list) != kIOReturnSuccess)
-       {
+       if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) {
                ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
                return (-1);
        }
 
-       while ((disk = IOIteratorNext (disk_list)) != 0)
-       {
+       while ((disk = IOIteratorNext (disk_list)) != 0) {
                props_dict = NULL;
                stats_dict = NULL;
                child_dict = NULL;
 
                /* get child of disk entry and corresponding property dictionary */
-               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
-                               != kIOReturnSuccess)
-               {
+               if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) {
                        /* This fails for example for DVD/CD drives, which we want to ignore anyway */
                        DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
                        IOObjectRelease (disk);
                        continue;
                }
-               if ((IORegistryEntryCreateCFProperties (disk_child, &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
-                               || (child_dict == NULL)) {
+               if (IORegistryEntryCreateCFProperties (disk_child, (CFMutableDictionaryRef *) &child_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || child_dict == NULL) {
                        ERROR ("disk plugin: IORegistryEntryCreateCFProperties (disk_child) failed.");
                        IOObjectRelease (disk_child);
                        IOObjectRelease (disk);
@@ -446,11 +434,8 @@ static int disk_read (void)
 
                /* extract name and major/minor numbers */
                memset (child_disk_name_bsd, 0, sizeof (child_disk_name_bsd));
-               /* tmp_cf_string_ref doesn't need to be released. */
-               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict,
-                               CFSTR(kIOBSDNameKey));
-               if (tmp_cf_string_ref)
-               {
+               tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (child_dict, CFSTR(kIOBSDNameKey));
+               if (tmp_cf_string_ref) {
                        assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
                        CFStringGetCString (tmp_cf_string_ref, child_disk_name_bsd, sizeof (child_disk_name_bsd), kCFStringEncodingUTF8);
                }
@@ -461,8 +446,7 @@ static int disk_read (void)
                IOObjectRelease (disk_child);
 
                /* get property dictionary of the disk entry itself */
-               if ((IORegistryEntryCreateCFProperties (disk, &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
-                               || (props_dict == NULL)) {
+               if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess || props_dict == NULL) {
                        ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
                        IOObjectRelease (disk);
                        continue;
@@ -475,10 +459,8 @@ static int disk_read (void)
                        assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ());
                        CFStringGetCString (tmp_cf_string_ref, props_disk_name_bsd, sizeof (props_disk_name_bsd), kCFStringEncodingUTF8);
                }
-               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
-                               CFSTR (kIOBlockStorageDriverStatisticsKey));
-               if (stats_dict == NULL)
-               {
+               stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));
+               if (stats_dict == NULL) {
                        ERROR ("disk plugin: CFDictionaryGetValue (%s) failed.", kIOBlockStorageDriverStatisticsKey);
                        CFRelease (props_dict);
                        IOObjectRelease (disk);
@@ -517,9 +499,7 @@ static int disk_read (void)
                if ((read_ops != -1LL) || (write_ops != -1LL))
                        disk_submit (disk_name, "disk_ops", read_ops, write_ops);
                if ((read_tme != -1LL) || (write_tme != -1LL))
-                       disk_submit (disk_name, "disk_time",
-                                       read_tme / 1000,
-                                       write_tme / 1000);
+                       disk_submit (disk_name, "disk_time", read_tme / 1000, write_tme / 1000);
 
        }
        IOObjectRelease (disk_list);