]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
[collectd 6] disk: cherry-pick "In macOS 12, `IOMasterPort` is deprecated in favor...
authorClay Caviness <clay@boobah.com>
Fri, 15 Jul 2022 17:29:11 +0000 (13:29 -0400)
committerMatthias Runge <mrunge@matthias-runge.de>
Sat, 11 Feb 2023 11:50:56 +0000 (12:50 +0100)
git cherry-pick 2711ebe7d671c ("In macOS 12, `IOMasterPort` is deprecated in favor of `IOMainPort`")
from the collectd 5 branch on top of the collectd 6 version of the plugin.

Original commit message:

In macOS 12, `IOMasterPort` is deprecated in favor of `IOMainPort`

```
src/battery.c:250:7: error: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]
      kIOMasterPortDefault, IOServiceNameMatching("battery"), &iterator);
      ^~~~~~~~~~~~~~~~~~~~
      kIOMainPortDefault
```

src/apple_sensors.c
src/battery.c
src/disk.c

index ad6e6c039b9b1435564702272074f837247646b4..52c74cfcd5dd09f46f8c4df6038ea78e69ee46d6 100644 (file)
 #include <IOKit/IOTypes.h>
 #endif
 
-static mach_port_t io_master_port = MACH_PORT_NULL;
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
+#define IOMainPort IOMasterPort
+#endif
+
+static mach_port_t io_main_port = MACH_PORT_NULL;
 
 static int as_init(void) {
   kern_return_t status;
 
-  if (io_master_port != MACH_PORT_NULL) {
-    mach_port_deallocate(mach_task_self(), io_master_port);
-    io_master_port = MACH_PORT_NULL;
+  if (io_main_port != MACH_PORT_NULL) {
+    mach_port_deallocate(mach_task_self(), io_main_port);
+    io_main_port = MACH_PORT_NULL;
   }
 
-  status = IOMasterPort(MACH_PORT_NULL, &io_master_port);
+  status = IOMainPort(MACH_PORT_NULL, &io_main_port);
   if (status != kIOReturnSuccess) {
-    ERROR("IOMasterPort failed: %s", mach_error_string(status));
-    io_master_port = MACH_PORT_NULL;
+    ERROR("IOMainPort failed: %s", mach_error_string(status));
+    io_main_port = MACH_PORT_NULL;
     return -1;
   }
 
@@ -94,11 +98,11 @@ static int as_read(void) {
   char inst[128];
   int value_int;
   double value_double;
-  if (!io_master_port || (io_master_port == MACH_PORT_NULL))
+  if (!io_main_port || (io_main_port == MACH_PORT_NULL))
     return -1;
 
   status = IOServiceGetMatchingServices(
-      io_master_port, IOServiceNameMatching("IOHWSensor"), &iterator);
+      io_main_port, IOServiceNameMatching("IOHWSensor"), &iterator);
   if (status != kIOReturnSuccess) {
     ERROR("IOServiceGetMatchingServices failed: %s", mach_error_string(status));
     return -1;
index 578f248fc1825a7aa8045c240b861103825f33af..7d75a60ea5a6c61a033c5f56a2ac3e6bf75914d4 100644 (file)
 /* No global variables */
 /* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
 
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
+#define kIOMainPortDefault kIOMasterPortDefault
+#endif
+
 #elif KERNEL_LINUX
 #define PROC_PMU_PATH_FORMAT "/proc/pmu/battery_%i"
 #define PROC_ACPI_PATH "/proc/acpi/battery"
@@ -247,7 +251,7 @@ static void get_via_generic_iokit(double *ret_capacity_full, /* {{{ */
   double temp_double;
 
   status = IOServiceGetMatchingServices(
-      kIOMasterPortDefault, IOServiceNameMatching("battery"), &iterator);
+      kIOMainPortDefault, IOServiceNameMatching("battery"), &iterator);
   if (status != kIOReturnSuccess) {
     DEBUG("IOServiceGetMatchingServices failed.");
     return;
index a4d74790ff86df2e9399913250136aecc31af844..95c43462cc647d5e52f0a2d35f8d73ccbd3c4e33 100644 (file)
 #include <sys/protosw.h>
 #endif
 
+#if (MAC_OS_X_VERSION_MIN_REQUIRED < 120000) // Before macOS 12 Monterey
+#define IOMainPort IOMasterPort
+#endif
+
 #if HAVE_IOKIT_IOKITLIB_H
-static mach_port_t io_master_port = MACH_PORT_NULL;
+static mach_port_t io_main_port = MACH_PORT_NULL;
 /* This defaults to false for backwards compatibility. Please fix in the next
  * major version. */
 static bool use_bsd_name;
@@ -207,15 +211,15 @@ static int disk_init(void) {
 #if HAVE_IOKIT_IOKITLIB_H
   kern_return_t status;
 
-  if (io_master_port != MACH_PORT_NULL) {
-    mach_port_deallocate(mach_task_self(), io_master_port);
-    io_master_port = MACH_PORT_NULL;
+  if (io_main_port != MACH_PORT_NULL) {
+    mach_port_deallocate(mach_task_self(), io_main_port);
+    io_main_port = MACH_PORT_NULL;
   }
 
-  status = IOMasterPort(MACH_PORT_NULL, &io_master_port);
+  status = IOMainPort(MACH_PORT_NULL, &io_main_port);
   if (status != kIOReturnSuccess) {
-    ERROR("IOMasterPort failed: %s", mach_error_string(status));
-    io_master_port = MACH_PORT_NULL;
+    ERROR("IOMainPort failed: %s", mach_error_string(status));
+    io_main_port = MACH_PORT_NULL;
     return -1;
   }
   /* #endif HAVE_IOKIT_IOKITLIB_H */
@@ -462,7 +466,7 @@ static int disk_read(void) {
 
   /* Get the list of all disk objects. */
   if (IOServiceGetMatchingServices(
-          io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
+          io_main_port, IOServiceMatching(kIOBlockStorageDriverClass),
           &disk_list) != kIOReturnSuccess) {
     ERROR("disk plugin: IOServiceGetMatchingServices failed.");
     return -1;