From dea4adf58b095ae1f66cceddb7c2309da35ff97d Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 11 Dec 2021 12:04:00 -0500
Subject: [PATCH] Fix compat with older macos

---
 indra/newview/llappviewermacosx.cpp | 13 ++++++++++---
 indra/newview/llmachineid.cpp       | 11 +++++++++--
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp
index 045bc2dbf3f..41dc6f41b70 100644
--- a/indra/newview/llappviewermacosx.cpp
+++ b/indra/newview/llappviewermacosx.cpp
@@ -394,9 +394,16 @@ std::string LLAppViewerMacOSX::generateSerialNumber()
 
 	// JC: Sample code from http://developer.apple.com/technotes/tn/tn1103.html
 	CFStringRef serialNumber = NULL;
-    io_service_t    platformExpert = IOServiceGetMatchingService(kIOMainPortDefault,
-																 IOServiceMatching("IOPlatformExpertDevice"));
-	if (platformExpert)
+    io_service_t platformExpert = NULL;
+    if (__builtin_available(macOS 12.0, *)) {
+        platformExpert = IOServiceGetMatchingService(kIOMainPortDefault,
+                                                                     IOServiceMatching("IOPlatformExpertDevice"));
+    } else {
+        platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
+                                                                     IOServiceMatching("IOPlatformExpertDevice"));
+    }
+    
+    if (platformExpert)
     {
 		serialNumber = (CFStringRef) IORegistryEntryCreateCFProperty(platformExpert,
 																	 CFSTR(kIOPlatformSerialNumberKey),
diff --git a/indra/newview/llmachineid.cpp b/indra/newview/llmachineid.cpp
index eebe8ae80c9..5fa9cc5602c 100644
--- a/indra/newview/llmachineid.cpp
+++ b/indra/newview/llmachineid.cpp
@@ -350,8 +350,15 @@ bool LLWMIMethods::getGenericSerialNumber(const BSTR &select, const LPCWSTR &var
 bool getSerialNumber(unsigned char *unique_id, size_t len)
 {
     CFStringRef serial_cf_str = NULL;
-    io_service_t platformExpert = IOServiceGetMatchingService(kIOMainPortDefault,
-                                                                 IOServiceMatching("IOPlatformExpertDevice"));
+    io_service_t platformExpert = NULL;
+    if (__builtin_available(macOS 12.0, *)) {
+        platformExpert = IOServiceGetMatchingService(kIOMainPortDefault,
+                                                                  IOServiceMatching("IOPlatformExpertDevice"));
+    } else {
+        platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,
+                                                                  IOServiceMatching("IOPlatformExpertDevice"));
+    }
+    
     if (platformExpert)
     {
         serial_cf_str = (CFStringRef) IORegistryEntryCreateCFProperty(platformExpert,
-- 
GitLab