Skip to content

Commit 043ff20

Browse files
Crashlytics: Add dispatch_once for opening sdk log file (#5904)
1 parent e03a8d9 commit 043ff20

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Crashlytics/Crashlytics/Helpers/FIRCLSInternalLogging.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <dispatch/dispatch.h>
16+
1517
#include "FIRCLSInternalLogging.h"
1618
#include "FIRCLSContext.h"
1719
#include "FIRCLSGlobals.h"
@@ -31,9 +33,12 @@ void FIRCLSSDKFileLog(FIRCLSInternalLogLevel level, const char* format, ...) {
3133
return;
3234
}
3335

34-
if (_firclsContext.writable->internalLogging.logFd == -1) {
35-
_firclsContext.writable->internalLogging.logFd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
36-
}
36+
static dispatch_once_t onceToken;
37+
dispatch_once(&onceToken, ^{
38+
if (_firclsContext.writable->internalLogging.logFd == -1) {
39+
_firclsContext.writable->internalLogging.logFd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644);
40+
}
41+
});
3742

3843
const int fd = _firclsContext.writable->internalLogging.logFd;
3944
if (fd < 0) {

0 commit comments

Comments
 (0)