2019-11-04 00:01:55 +03:00
|
|
|
/*
|
2019-03-08 12:07:49 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-09-09 00:41:39 +03:00
|
|
|
*
|
2019-03-08 12:07:49 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-09-09 00:41:39 +03:00
|
|
|
*/
|
|
|
|
|
2016-03-09 21:33:20 +03:00
|
|
|
#import "FBControlCoreGlobalConfiguration.h"
|
2015-09-09 00:41:39 +03:00
|
|
|
|
2017-08-17 02:55:25 +03:00
|
|
|
#import <Foundation/Foundation.h>
|
2016-05-17 17:04:57 +03:00
|
|
|
|
2016-03-09 21:33:20 +03:00
|
|
|
#import "FBControlCoreLogger.h"
|
2015-09-09 00:41:39 +03:00
|
|
|
|
2016-06-16 22:09:47 +03:00
|
|
|
NSString *const FBControlCoreStderrLogging = @"FBCONTROLCORE_LOGGING";
|
|
|
|
NSString *const FBControlCoreDebugLogging = @"FBCONTROLCORE_DEBUG_LOGGING";
|
2018-02-16 13:54:34 +03:00
|
|
|
NSString *const ConfirmShimsAreSignedEnv = @"FBCONTROLCORE_CONFIRM_SIGNED_SHIMS";
|
2015-12-15 21:57:20 +03:00
|
|
|
|
2016-03-09 21:33:20 +03:00
|
|
|
static id<FBControlCoreLogger> logger;
|
2016-01-26 20:30:32 +03:00
|
|
|
|
2016-03-09 21:33:20 +03:00
|
|
|
@implementation FBControlCoreGlobalConfiguration
|
2015-09-09 00:41:39 +03:00
|
|
|
|
2015-12-23 15:57:46 +03:00
|
|
|
+ (NSTimeInterval)fastTimeout
|
|
|
|
{
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSTimeInterval)regularTimeout
|
|
|
|
{
|
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSTimeInterval)slowTimeout
|
|
|
|
{
|
|
|
|
return 120;
|
|
|
|
}
|
|
|
|
|
2016-03-09 21:33:20 +03:00
|
|
|
+ (id<FBControlCoreLogger>)defaultLogger
|
2015-12-18 12:36:00 +03:00
|
|
|
{
|
2016-01-26 20:30:32 +03:00
|
|
|
if (logger) {
|
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
logger = [self createDefaultLogger];
|
2015-12-29 17:32:53 +03:00
|
|
|
return logger;
|
2015-12-18 12:36:00 +03:00
|
|
|
}
|
|
|
|
|
2017-03-22 19:37:47 +03:00
|
|
|
+ (void)setDefaultLogger:(id<FBControlCoreLogger>)defaultLogger
|
|
|
|
{
|
|
|
|
if (logger) {
|
2017-12-15 18:04:04 +03:00
|
|
|
[defaultLogger.debug logFormat:@"Overriding the Default Logger with %@", defaultLogger];
|
2017-03-22 19:37:47 +03:00
|
|
|
}
|
|
|
|
logger = defaultLogger;
|
|
|
|
}
|
|
|
|
|
2018-02-16 13:54:34 +03:00
|
|
|
+ (BOOL)confirmCodesignaturesAreValid
|
|
|
|
{
|
|
|
|
return NSProcessInfo.processInfo.environment[ConfirmShimsAreSignedEnv].boolValue;
|
|
|
|
}
|
|
|
|
|
2015-12-18 12:36:00 +03:00
|
|
|
+ (NSString *)description
|
|
|
|
{
|
2018-07-02 13:41:52 +03:00
|
|
|
return [NSString stringWithFormat:@"Default Logger %@", logger];
|
2015-12-18 12:36:00 +03:00
|
|
|
}
|
|
|
|
|
2016-09-19 16:44:13 +03:00
|
|
|
- (NSString *)description
|
|
|
|
{
|
|
|
|
return [FBControlCoreGlobalConfiguration description];
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:53:48 +03:00
|
|
|
+ (NSDictionary<NSString *, NSString *> *)safeSubprocessEnvironment
|
|
|
|
{
|
|
|
|
NSDictionary<NSString *, NSString *> *env = NSProcessInfo.processInfo.environment;
|
|
|
|
NSMutableDictionary<NSString *, NSString *> *modified = NSMutableDictionary.dictionary;
|
|
|
|
for (NSString *key in env) {
|
|
|
|
if ([key containsString:@"TERMCAP"]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
modified[key] = env[key];
|
|
|
|
}
|
|
|
|
return [modified copy];
|
|
|
|
}
|
|
|
|
|
2016-01-26 20:30:32 +03:00
|
|
|
#pragma mark Private
|
|
|
|
|
2016-03-09 21:33:20 +03:00
|
|
|
+ (id<FBControlCoreLogger>)createDefaultLogger
|
2016-01-26 20:30:32 +03:00
|
|
|
{
|
2018-07-02 13:41:52 +03:00
|
|
|
return [FBControlCoreLogger systemLoggerWritingToStderr:self.stderrLoggingEnabledByDefault withDebugLogging:self.debugLoggingEnabledByDefault];
|
2016-01-26 20:30:32 +03:00
|
|
|
}
|
|
|
|
|
2018-07-02 13:41:52 +03:00
|
|
|
+ (BOOL)stderrLoggingEnabledByDefault
|
2016-01-26 20:30:32 +03:00
|
|
|
{
|
2018-07-02 13:41:52 +03:00
|
|
|
return [NSProcessInfo.processInfo.environment[FBControlCoreStderrLogging] boolValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (BOOL)debugLoggingEnabledByDefault
|
|
|
|
{
|
|
|
|
return [NSProcessInfo.processInfo.environment[FBControlCoreDebugLogging] boolValue];
|
2016-01-26 20:30:32 +03:00
|
|
|
}
|
|
|
|
|
2017-03-22 19:37:47 +03:00
|
|
|
+ (nullable id)readValueForKey:(NSString *)key fromPlistAtPath:(NSString *)plistPath
|
2015-12-29 18:17:23 +03:00
|
|
|
{
|
2017-03-22 19:37:47 +03:00
|
|
|
NSCAssert([NSFileManager.defaultManager fileExistsAtPath:plistPath], @"plist does not exist at path '%@'", plistPath);
|
|
|
|
NSDictionary *infoPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
|
|
|
|
NSCAssert(infoPlist, @"Could not read plist at '%@'", plistPath);
|
|
|
|
id value = infoPlist[key];
|
|
|
|
NSCAssert(value, @"'%@' does not exist in plist '%@'", key, infoPlist.allKeys);
|
|
|
|
return value;
|
2015-12-29 18:17:23 +03:00
|
|
|
}
|
|
|
|
|
2017-03-22 19:37:47 +03:00
|
|
|
@end
|