From 4f6f63ca5272f32bad2271fc9d147807e40d61d9 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Thu, 8 Dec 2022 13:37:36 -0500 Subject: [PATCH 01/15] attempt to query FirebaseSemaphorePrefix from Info.plist --- app/CMakeLists.txt | 4 +++- app/src/scheduler.cc | 6 ++++++ app/src/semaphore.h | 19 +++++++++++++------ app/src/util_ios.h | 5 +++++ app/src/util_ios.mm | 15 +++++++++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a12d42b2c6..063323e707 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -157,6 +157,7 @@ set(app_android_SRCS src/uuid.cc) set(app_ios_SRCS src/app_ios.mm + src/util_apple.mm src/util_ios.mm src/invites/ios/invites_receiver_internal_ios.mm src/invites/ios/invites_ios_startup.mm @@ -220,7 +221,8 @@ else() src/secure/user_secure_darwin_internal.mm src/filesystem_apple.mm src/locale_apple.mm - src/uuid_ios_darwin.mm) + src/uuid_ios_darwin.mm + src/util_apple.mm) else() # Linux requires libsecret. pkg_check_modules(LIBSECRET libsecret-1) diff --git a/app/src/scheduler.cc b/app/src/scheduler.cc index 00cefe7ff6..30889d5612 100644 --- a/app/src/scheduler.cc +++ b/app/src/scheduler.cc @@ -148,14 +148,20 @@ void Scheduler::WorkerThreadRoutine(void* data) { // 2. The top request in the queue is not due yet. if (!request) { if (sleep_time > 0) { + printf("DEDB TimedWait"); scheduler->sleep_sem_.TimedWait(sleep_time); + printf("DEDB TimedWait ended"); } else { + printf("DEDB Wait"); scheduler->sleep_sem_.Wait(); + printf("DEDB Wait end"); } // Drain the semaphore after wake + printf("DEDB draining Semaphore"); while (scheduler->sleep_sem_.TryWait()) { } + printf("DEDB draining Semaphore complete"); // Check if the scheduler is terminating after sleep. MutexLock lock(scheduler->request_mutex_); diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 316373d8a0..8830d83ad4 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -39,6 +39,7 @@ #if FIREBASE_PLATFORM_OSX || FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS #include "app/src/include/firebase/internal/mutex.h" #include "app/src/pthread_condvar.h" +#include "app/src/util_apple.h" #endif // FIREBASE_PLATFORM_OSX || FIREBASE_PLATFORM_IOS || // FIREBASE_PLATFORM_TVOS @@ -50,20 +51,26 @@ class Semaphore { #if FIREBASE_PLATFORM_OSX || FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS // MacOS requires named semaphores, and does not support unnamed. // Generate a unique string for the semaphore name: - static const char kPrefix[] = "/firebase-"; - // String length of the name prefix. - static const int kPprefixLen = sizeof(kPrefix); + // String length of the pointer, when printed to a string. static const int kPointerStringLength = 16; // Buffer size. the +1 is for the null terminator. - static const int kBufferSize = kPprefixLen + kPointerStringLength + 1; + static const int kBufferSize = kPointerStringLength + 1; char buffer[kBufferSize]; - snprintf(buffer, kBufferSize, "%s%016llx", kPrefix, + snprintf(buffer, kBufferSize, "%016llx", static_cast( // NOLINT reinterpret_cast(this))); - semaphore_ = sem_open(buffer, + std::string semaphore_name = util::GetCustomSemaphorePrefix(); + if (semaphore_name.empty()) { + semaphore_name = "/firebase-"; + } + + semaphore_name.append(buffer); + printf("DEDB Final Semaphore name: %s\n", semaphore_name.c_str()); + + semaphore_ = sem_open(semaphore_name.c_str(), O_CREAT | O_EXCL, // Create if it doesn't exist. S_IRUSR | S_IWUSR, // Only the owner can read/write. initial_count); diff --git a/app/src/util_ios.h b/app/src/util_ios.h index 25f77fb633..ac6c733c7f 100644 --- a/app/src/util_ios.h +++ b/app/src/util_ios.h @@ -251,6 +251,11 @@ void RunOnMainThread(void (*function_ptr)(void *function_data), void RunOnBackgroundThread(void (*function_ptr)(void *function_data), void *function_data); +// Attempts to query the custom semaphore prefix from the application's +// Info.plist file. Returns an empty string if a custom semahpore prefix +// wasn't conifgured. +std::string GetCustomSemaphorePrefix(); + // Class which caches function implementations for a class. // // Use this object to swizzle and cache method implementations. diff --git a/app/src/util_ios.mm b/app/src/util_ios.mm index c2d194ad87..f84cf39e71 100644 --- a/app/src/util_ios.mm +++ b/app/src/util_ios.mm @@ -326,6 +326,21 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data), void *func }); } +std::string GetCustomSemaphorePrefix() { +#error dave + NSBundle *mainBundle = [NSBundle mainBundle]; + if (mainBundle != nil) { + NSDictionary *dictionary = [mainBundle infoDictionary]; + if (dictionary != nil) { + NSString *customPrefix = [info_dictionary valueForKey:@"FirebaseSemaphorePrefix"]; + if (customPrefix != nil) { + return std::string(bundleName.customPrefix) + } + } + } + return std::string(); +} + const int ClassMethodImplementationCache::kRandomNameGenerationRetries = 1000; ClassMethodImplementationCache::ClassMethodImplementationCache() { From 92c58361e0476dc5e13087c383a4229e614001bd Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Thu, 8 Dec 2022 16:14:13 -0500 Subject: [PATCH 02/15] add util_apple files --- app/src/util_apple.h | 33 +++++++++++++++++++++++++++++++++ app/src/util_apple.mm | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 app/src/util_apple.h create mode 100644 app/src/util_apple.mm diff --git a/app/src/util_apple.h b/app/src/util_apple.h new file mode 100644 index 0000000000..c3c4239506 --- /dev/null +++ b/app/src/util_apple.h @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FIREBASE_APP_SRC_UTIL_APPLE_H_ +#define FIREBASE_APP_SRC_UTIL_APPLE_H_ + +#include + +namespace firebase { +namespace util { + +// Attempts to query the custom semaphore prefix from the application's +// Info.plist file. Returns an empty string if a custom semahpore prefix +// wasn't conifgured. +std::string GetCustomSemaphorePrefix(); + +} // namespace util +} // namespace firebase + +#endif // FIREBASE_APP_SRC_UTIL_IOS_H_ \ No newline at end of file diff --git a/app/src/util_apple.mm b/app/src/util_apple.mm new file mode 100644 index 0000000000..ec9932146b --- /dev/null +++ b/app/src/util_apple.mm @@ -0,0 +1,33 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "app/src/util_apple.h" + +#import + +std::string GetCustomSemaphorePrefix() { + NSBundle* mainBundle = [NSBundle mainBundle]; + if (mainBundle != nil) { + NSDictionary* dictionary = [mainBundle infoDictionary]; + if (dictionary != nil) { + NSString* customPrefix = [dictionary valueForKey:@"FirebaseSemaphorePrefix"]; + if (customPrefix != nil) { + return std::string(customPrefix.UTF8String); + } + } + } + return std::string(); +} \ No newline at end of file From b395150185f7cced174179072a6998f2627861a6 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Thu, 8 Dec 2022 18:03:08 -0500 Subject: [PATCH 03/15] remove cached util_ios changes --- app/src/util_ios.h | 5 ----- app/src/util_ios.mm | 15 --------------- 2 files changed, 20 deletions(-) diff --git a/app/src/util_ios.h b/app/src/util_ios.h index ac6c733c7f..25f77fb633 100644 --- a/app/src/util_ios.h +++ b/app/src/util_ios.h @@ -251,11 +251,6 @@ void RunOnMainThread(void (*function_ptr)(void *function_data), void RunOnBackgroundThread(void (*function_ptr)(void *function_data), void *function_data); -// Attempts to query the custom semaphore prefix from the application's -// Info.plist file. Returns an empty string if a custom semahpore prefix -// wasn't conifgured. -std::string GetCustomSemaphorePrefix(); - // Class which caches function implementations for a class. // // Use this object to swizzle and cache method implementations. diff --git a/app/src/util_ios.mm b/app/src/util_ios.mm index f84cf39e71..c2d194ad87 100644 --- a/app/src/util_ios.mm +++ b/app/src/util_ios.mm @@ -326,21 +326,6 @@ void RunOnBackgroundThread(void (*function_ptr)(void *function_data), void *func }); } -std::string GetCustomSemaphorePrefix() { -#error dave - NSBundle *mainBundle = [NSBundle mainBundle]; - if (mainBundle != nil) { - NSDictionary *dictionary = [mainBundle infoDictionary]; - if (dictionary != nil) { - NSString *customPrefix = [info_dictionary valueForKey:@"FirebaseSemaphorePrefix"]; - if (customPrefix != nil) { - return std::string(bundleName.customPrefix) - } - } - } - return std::string(); -} - const int ClassMethodImplementationCache::kRandomNameGenerationRetries = 1000; ClassMethodImplementationCache::ClassMethodImplementationCache() { From d010b7a6a2778ba85f1bf307cb9d02e292b9ddc4 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Fri, 9 Dec 2022 09:30:09 -0500 Subject: [PATCH 04/15] put GetCustomSemaphorePrefix() in firebase::util --- app/src/util_apple.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/util_apple.mm b/app/src/util_apple.mm index ec9932146b..65c458fac9 100644 --- a/app/src/util_apple.mm +++ b/app/src/util_apple.mm @@ -18,6 +18,9 @@ #import +namespace firebase { +namespace util { + std::string GetCustomSemaphorePrefix() { NSBundle* mainBundle = [NSBundle mainBundle]; if (mainBundle != nil) { @@ -30,4 +33,7 @@ } } return std::string(); -} \ No newline at end of file +} + +} // namespace util +} // namespace firebase From 2a6a8e3107bd06a9c445a647af7ee48e95dc7f7d Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Fri, 9 Dec 2022 10:13:29 -0500 Subject: [PATCH 05/15] some renames. Only applicable to macOS --- app/src/semaphore.h | 7 ++++++- app/src/util_apple.h | 2 +- app/src/util_apple.mm | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 8830d83ad4..12fc522739 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -62,10 +62,15 @@ class Semaphore { static_cast( // NOLINT reinterpret_cast(this))); - std::string semaphore_name = util::GetCustomSemaphorePrefix(); +#if FIREBASE_PLATFORM_OSX + // Sandbox mode is currently only available for macOS. + std::string semaphore_name = util::GetSandboxModeSemaphorePrefix(); if (semaphore_name.empty()) { semaphore_name = "/firebase-"; } +#else + std::string semaphore_name = "/firebase-"; +#endif // FIREBASE_PLATFORM_OSX semaphore_name.append(buffer); printf("DEDB Final Semaphore name: %s\n", semaphore_name.c_str()); diff --git a/app/src/util_apple.h b/app/src/util_apple.h index c3c4239506..456eda9902 100644 --- a/app/src/util_apple.h +++ b/app/src/util_apple.h @@ -25,7 +25,7 @@ namespace util { // Attempts to query the custom semaphore prefix from the application's // Info.plist file. Returns an empty string if a custom semahpore prefix // wasn't conifgured. -std::string GetCustomSemaphorePrefix(); +std::string GetSandboxModeSemaphorePrefix(); } // namespace util } // namespace firebase diff --git a/app/src/util_apple.mm b/app/src/util_apple.mm index 65c458fac9..dd0cd32fd0 100644 --- a/app/src/util_apple.mm +++ b/app/src/util_apple.mm @@ -21,12 +21,12 @@ namespace firebase { namespace util { -std::string GetCustomSemaphorePrefix() { +std::string GetSandboxModeSemaphorePrefix() { NSBundle* mainBundle = [NSBundle mainBundle]; if (mainBundle != nil) { NSDictionary* dictionary = [mainBundle infoDictionary]; if (dictionary != nil) { - NSString* customPrefix = [dictionary valueForKey:@"FirebaseSemaphorePrefix"]; + NSString* customPrefix = [dictionary valueForKey:@"FBAppGroupEntitlementName"]; if (customPrefix != nil) { return std::string(customPrefix.UTF8String); } From 597109b05180432470168b4787fc19ef5fe56f89 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Fri, 9 Dec 2022 14:22:27 -0500 Subject: [PATCH 06/15] append slash --- app/src/util_apple.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/util_apple.mm b/app/src/util_apple.mm index dd0cd32fd0..0d226e43f6 100644 --- a/app/src/util_apple.mm +++ b/app/src/util_apple.mm @@ -28,7 +28,7 @@ if (dictionary != nil) { NSString* customPrefix = [dictionary valueForKey:@"FBAppGroupEntitlementName"]; if (customPrefix != nil) { - return std::string(customPrefix.UTF8String); + return std::string(customPrefix.UTF8String).append("/"); } } } From e88d15e07570e3cdbbfa63f1bdbfc8167280ea2a Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Sat, 10 Dec 2022 10:46:45 -0500 Subject: [PATCH 07/15] revert scheduler debug logging --- app/src/scheduler.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/scheduler.cc b/app/src/scheduler.cc index 30889d5612..00cefe7ff6 100644 --- a/app/src/scheduler.cc +++ b/app/src/scheduler.cc @@ -148,20 +148,14 @@ void Scheduler::WorkerThreadRoutine(void* data) { // 2. The top request in the queue is not due yet. if (!request) { if (sleep_time > 0) { - printf("DEDB TimedWait"); scheduler->sleep_sem_.TimedWait(sleep_time); - printf("DEDB TimedWait ended"); } else { - printf("DEDB Wait"); scheduler->sleep_sem_.Wait(); - printf("DEDB Wait end"); } // Drain the semaphore after wake - printf("DEDB draining Semaphore"); while (scheduler->sleep_sem_.TryWait()) { } - printf("DEDB draining Semaphore complete"); // Check if the scheduler is terminating after sleep. MutexLock lock(scheduler->request_mutex_); From 31677d524e7ffc75d70dea6eefc51c529b0de58d Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Sat, 10 Dec 2022 11:13:46 -0500 Subject: [PATCH 08/15] proper semaphore creation detection for each platform --- app/src/semaphore.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 12fc522739..73985c0dba 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -73,7 +73,6 @@ class Semaphore { #endif // FIREBASE_PLATFORM_OSX semaphore_name.append(buffer); - printf("DEDB Final Semaphore name: %s\n", semaphore_name.c_str()); semaphore_ = sem_open(semaphore_name.c_str(), O_CREAT | O_EXCL, // Create if it doesn't exist. @@ -87,19 +86,21 @@ class Semaphore { bool success = (sem_unlink(buffer) == 0); assert(success); (void)success; + assert(semaphore_ != SEM_FAILED); #elif !FIREBASE_PLATFORM_WINDOWS // Android requires unnamed semaphores, and does not support sem_open semaphore_ = &semaphore_value_; bool success = sem_init(semaphore_, 0, initial_count) == 0; assert(success); (void)success; + assert(semaphore_ != -1); #else semaphore_ = CreateSemaphore(nullptr, // default security attributes initial_count, // initial count LONG_MAX, // maximum count nullptr); // unnamed semaphore -#endif assert(semaphore_ != nullptr); +#endif } ~Semaphore() { From 17827b9133b9dd704a68e4cb341c88686cee2d13 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Sat, 10 Dec 2022 11:31:31 -0500 Subject: [PATCH 09/15] release notes entry --- release_build_files/readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/release_build_files/readme.md b/release_build_files/readme.md index 683490c54d..d9c9e63d7d 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -642,6 +642,15 @@ workflow use only during the development of your app, not for publicly shipping code. ## Release Notes +### Upcoming +- Changes + - General (macOS): In order to support sandbox mode, apps can define a + key/value pair for FBAppGroupEntitlementName in Info.plist. The value + associated with this key will be used to prefix semaphore names + created internally by the Firebase C++ SDK so that they conform with + [macOS sandbox + requirements](https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW24). + ### 10.2.0 - Changes - General (Android): Update to Firebase Android BoM version 31.1.0. From 97ac04cd36eb02887c565fae15307eaab8116b6a Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Sat, 10 Dec 2022 11:32:48 -0500 Subject: [PATCH 10/15] lint fixes --- app/src/util_apple.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/util_apple.h b/app/src/util_apple.h index 456eda9902..2485c3621d 100644 --- a/app/src/util_apple.h +++ b/app/src/util_apple.h @@ -30,4 +30,4 @@ std::string GetSandboxModeSemaphorePrefix(); } // namespace util } // namespace firebase -#endif // FIREBASE_APP_SRC_UTIL_IOS_H_ \ No newline at end of file +#endif // FIREBASE_APP_SRC_UTIL_APPLE_H_ From 60d38ed2e5cbbc194a0ff97d8400094684dc331a Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Sat, 10 Dec 2022 17:21:44 -0500 Subject: [PATCH 11/15] linux semaphore pointer assertion --- app/src/semaphore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 73985c0dba..f9d4c6386e 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -93,7 +93,7 @@ class Semaphore { bool success = sem_init(semaphore_, 0, initial_count) == 0; assert(success); (void)success; - assert(semaphore_ != -1); + assert(semaphore_ != nullptr); #else semaphore_ = CreateSemaphore(nullptr, // default security attributes initial_count, // initial count From 0641785ec5f17e2119963ff09534619c937ce688 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Sat, 10 Dec 2022 20:25:51 -0500 Subject: [PATCH 12/15] unlink the full semaphore name on macOS --- app/src/semaphore.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/semaphore.h b/app/src/semaphore.h index f9d4c6386e..8e43603a4d 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -73,20 +73,25 @@ class Semaphore { #endif // FIREBASE_PLATFORM_OSX semaphore_name.append(buffer); + printf("semaphore name: %s\n", semaphore_name.c_str()); semaphore_ = sem_open(semaphore_name.c_str(), O_CREAT | O_EXCL, // Create if it doesn't exist. S_IRUSR | S_IWUSR, // Only the owner can read/write. initial_count); + printf("Semaphore: %p\n", semaphore_); + + assert(semaphore_ != SEM_FAILED); + // Remove the semaphore from the system registry, so other processes can't // grab it. (These are designed to just be passed around internally by // pointer, like unnamed semaphores. Mac OSX targets don't support unnamed // semaphores though, so we have to use named, and just treat them like // unnamed. - bool success = (sem_unlink(buffer) == 0); + bool success = (sem_unlink(semaphore_name.c_str()) == 0); assert(success); (void)success; - assert(semaphore_ != SEM_FAILED); + #elif !FIREBASE_PLATFORM_WINDOWS // Android requires unnamed semaphores, and does not support sem_open semaphore_ = &semaphore_value_; From 8edbe88b50f379572766343ffa0130a0cb99fba0 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Thu, 15 Dec 2022 11:26:22 -0500 Subject: [PATCH 13/15] remove printfs, assert macOS on nullptr --- app/src/semaphore.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 8e43603a4d..6c2f089216 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -73,15 +73,14 @@ class Semaphore { #endif // FIREBASE_PLATFORM_OSX semaphore_name.append(buffer); - printf("semaphore name: %s\n", semaphore_name.c_str()); semaphore_ = sem_open(semaphore_name.c_str(), O_CREAT | O_EXCL, // Create if it doesn't exist. S_IRUSR | S_IWUSR, // Only the owner can read/write. initial_count); - printf("Semaphore: %p\n", semaphore_); assert(semaphore_ != SEM_FAILED); + assert(semaphore_ != nullptr); // Remove the semaphore from the system registry, so other processes can't // grab it. (These are designed to just be passed around internally by @@ -91,7 +90,6 @@ class Semaphore { bool success = (sem_unlink(semaphore_name.c_str()) == 0); assert(success); (void)success; - #elif !FIREBASE_PLATFORM_WINDOWS // Android requires unnamed semaphores, and does not support sem_open semaphore_ = &semaphore_value_; From 771da3267367c3beef6dd055eb9e9dad975e22a2 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Tue, 20 Dec 2022 11:38:01 -0500 Subject: [PATCH 14/15] test semaphore creation on init. Better logging on macOS error --- app/src/app_desktop.cc | 4 ++++ app/src/semaphore.h | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/app_desktop.cc b/app/src/app_desktop.cc index ad0de8ed92..0276c163c9 100644 --- a/app/src/app_desktop.cc +++ b/app/src/app_desktop.cc @@ -29,6 +29,7 @@ #include "app/src/include/firebase/internal/common.h" #include "app/src/include/firebase/version.h" #include "app/src/log.h" +#include "app/src/semaphore.h" #include "app/src/util.h" namespace firebase { @@ -131,6 +132,9 @@ App* App::Create(const AppOptions& options, const char* name) { // NOLINT return app; } LogDebug("Creating Firebase App %s for %s", name, kFirebaseVersionString); + LogDebug("Validating semaphore creation."); + { firebase::Semaphore sem_test(0); } + AppOptions options_with_defaults = options; if (options_with_defaults.PopulateRequiredWithDefaults()) { app = new App(); diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 6c2f089216..8edbfc5e25 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -19,6 +19,7 @@ #include +#include "app/src/assert.h" #include "app/src/include/firebase/internal/platform.h" #include "app/src/time.h" @@ -40,6 +41,8 @@ #include "app/src/include/firebase/internal/mutex.h" #include "app/src/pthread_condvar.h" #include "app/src/util_apple.h" + +#define FIREBASE_SEMAPHORE_DEFAULT_PREFIX "/firebase-" #endif // FIREBASE_PLATFORM_OSX || FIREBASE_PLATFORM_IOS || // FIREBASE_PLATFORM_TVOS @@ -61,24 +64,31 @@ class Semaphore { snprintf(buffer, kBufferSize, "%016llx", static_cast( // NOLINT reinterpret_cast(this))); - #if FIREBASE_PLATFORM_OSX - // Sandbox mode is currently only available for macOS. + // Append custom semaphore names, if present, to support macOS Sandbox + // mode. std::string semaphore_name = util::GetSandboxModeSemaphorePrefix(); if (semaphore_name.empty()) { - semaphore_name = "/firebase-"; + semaphore_name = FIREBASE_SEMAPHORE_DEFAULT_PREFIX; } #else - std::string semaphore_name = "/firebase-"; + std::string semaphore_name = FIREBASE_SEMAPHORE_DEFAULT_PREFIX; #endif // FIREBASE_PLATFORM_OSX semaphore_name.append(buffer); - semaphore_ = sem_open(semaphore_name.c_str(), O_CREAT | O_EXCL, // Create if it doesn't exist. S_IRUSR | S_IWUSR, // Only the owner can read/write. initial_count); + // Check for errors. +#if FIREBASE_PLATFORM_OSX + FIREBASE_ASSERT_MESSAGE( + semaphore_ != SEM_FAILED, + "Failed to create semaphore. If running in sandbox mode be sure to " + "configure FBAppGroupEntitlementName in your app's Info.plist."); +#endif // FIREBASE_PLATFORM_OSX + assert(semaphore_ != SEM_FAILED); assert(semaphore_ != nullptr); From 586dbc8c0363c8c07dc25ef5cfe1352ab86702e5 Mon Sep 17 00:00:00 2001 From: "drsanta@google.com" Date: Tue, 20 Dec 2022 18:21:12 -0500 Subject: [PATCH 15/15] add Firebase to assert message. --- app/src/semaphore.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 8edbfc5e25..83a28468a0 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -85,8 +85,9 @@ class Semaphore { #if FIREBASE_PLATFORM_OSX FIREBASE_ASSERT_MESSAGE( semaphore_ != SEM_FAILED, - "Failed to create semaphore. If running in sandbox mode be sure to " - "configure FBAppGroupEntitlementName in your app's Info.plist."); + "Firebase failed to create semaphore. If running in sandbox mode be " + "sure to configure FBAppGroupEntitlementName in your app's " + "Info.plist."); #endif // FIREBASE_PLATFORM_OSX assert(semaphore_ != SEM_FAILED);