diff --git a/Crashlytics/Crashlytics/Helpers/FIRCLSInternalLogging.c b/Crashlytics/Crashlytics/Helpers/FIRCLSInternalLogging.c index d9e3daa0922..3f0ae71d431 100644 --- a/Crashlytics/Crashlytics/Helpers/FIRCLSInternalLogging.c +++ b/Crashlytics/Crashlytics/Helpers/FIRCLSInternalLogging.c @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "FIRCLSInternalLogging.h" #include "FIRCLSContext.h" #include "FIRCLSGlobals.h" @@ -31,9 +33,12 @@ void FIRCLSSDKFileLog(FIRCLSInternalLogLevel level, const char* format, ...) { return; } - if (_firclsContext.writable->internalLogging.logFd == -1) { - _firclsContext.writable->internalLogging.logFd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644); - } + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + if (_firclsContext.writable->internalLogging.logFd == -1) { + _firclsContext.writable->internalLogging.logFd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644); + } + }); const int fd = _firclsContext.writable->internalLogging.logFd; if (fd < 0) {