mirror of
https://github.com/google/santa.git
synced 2026-04-24 03:00:12 -04:00
exit when configuration file couldn't be opened
* when the configuration file couldn't be opened it failed silently and used empty configuration. Now it prints an error and quits with errorcode 1. * LOGE not used because of circular reference
This commit is contained in:
@@ -141,11 +141,27 @@ static NSString * const kMachineIDPlistKeyKey = @"MachineIDKey";
|
||||
}
|
||||
|
||||
- (void)reloadConfigData {
|
||||
_configData = [[NSDictionary dictionaryWithContentsOfFile:kConfigFilePath] mutableCopy];
|
||||
NSError* error = nil;
|
||||
|
||||
if (!_configData) {
|
||||
_configData = [NSMutableDictionary dictionary];
|
||||
NSData *readData = [NSData dataWithContentsOfFile:kConfigFilePath options:0 error:&error];
|
||||
|
||||
if (error) {
|
||||
fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"Could not open configuration file %@: %@", kConfigFilePath, [error localizedDescription]] UTF8String]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
CFErrorRef parseError = NULL;
|
||||
|
||||
NSDictionary *dictionary = (__bridge_transfer NSDictionary *)CFPropertyListCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)readData, kCFPropertyListImmutable, NULL, (CFErrorRef *)&parseError);
|
||||
|
||||
if (parseError) {
|
||||
fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"Could not parse configuration file %@: %@", kConfigFilePath, [(__bridge NSError *)parseError localizedDescription]] UTF8String]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
_configData = [dictionary mutableCopy];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user