Added verbose logging for #170

This commit is contained in:
Shazron Abdullah 2015-10-08 16:05:03 -07:00
parent 59904aa4c1
commit 612c3561fd

View File

@ -223,15 +223,28 @@ void on_sys_error(NSString* format, ...) {
on_error(@"%@ : %@", str, [NSString stringWithUTF8String:errstr]); on_error(@"%@ : %@", str, [NSString stringWithUTF8String:errstr]);
} }
void __NSLogOut(NSString* format, va_list valist) {
NSString* str = [[[NSString alloc] initWithFormat:format arguments:valist] autorelease];
[[str stringByAppendingString:@"\n"] writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:nil];
}
void NSLogOut(NSString* format, ...) { void NSLogOut(NSString* format, ...) {
va_list valist; va_list valist;
va_start(valist, format); va_start(valist, format);
NSString* str = [[[NSString alloc] initWithFormat:format arguments:valist] autorelease]; __NSLogOut(format, valist);
va_end(valist); va_end(valist);
[[str stringByAppendingString:@"\n"] writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:nil];
} }
void NSLogVerbose(NSString* format, ...) {
if (verbose) {
va_list valist;
va_start(valist, format);
__NSLogOut(format, valist);
va_end(valist);
}
}
BOOL mkdirp(NSString* path) { BOOL mkdirp(NSString* path) {
NSError* error = nil; NSError* error = nil;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:path BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:path
@ -468,11 +481,8 @@ CFStringRef get_device_full_name(const AMDeviceRef device) {
device_name = AMDeviceCopyValue(device, 0, CFSTR("DeviceName")), device_name = AMDeviceCopyValue(device, 0, CFSTR("DeviceName")),
model_name = get_device_hardware_name(device); model_name = get_device_hardware_name(device);
if (verbose) NSLogVerbose(@"Device Name: %@", device_name);
{ NSLogVerbose(@"Model Name: %@", model_name);
NSLogOut(@"Device Name: %@", device_name);
NSLogOut(@"Model Name: %@", model_name);
}
if(device_name != NULL && model_name != NULL) if(device_name != NULL && model_name != NULL)
{ {
@ -610,11 +620,9 @@ void mount_developer_image(AMDeviceRef device) {
CFStringRef image_path = copy_developer_disk_image_path(device); CFStringRef image_path = copy_developer_disk_image_path(device);
CFStringRef sig_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.signature"), image_path); CFStringRef sig_path = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@.signature"), image_path);
if (verbose) { NSLogVerbose(@"Device support path: %@", ds_path);
NSLogOut(@"Device support path: %@", ds_path); NSLogVerbose(@"Developer disk image: %@", image_path);
NSLogOut(@"Developer disk image: %@", image_path); CFRelease(ds_path);
}
CFRelease(ds_path);
FILE* sig = fopen(CFStringGetCStringPtr(sig_path, kCFStringEncodingMacRoman), "rb"); FILE* sig = fopen(CFStringGetCStringPtr(sig_path, kCFStringEncodingMacRoman), "rb");
void *sig_buf = malloc(128); void *sig_buf = malloc(128);
@ -1127,8 +1135,7 @@ void launch_debugger_and_exit(AMDeviceRef device, CFURLRef url) {
_exit(WEXITSTATUS(status)); _exit(WEXITSTATUS(status));
} else if (pid > 0) { } else if (pid > 0) {
child = pid; child = pid;
if (verbose) NSLogVerbose(@"Waiting for child [Child: %d][Parent: %d]\n", child, parent);
NSLogOut(@"Waiting for child [Child: %d][Parent: %d]\n", child, parent);
} else { } else {
on_sys_error(@"Fork failed"); on_sys_error(@"Fork failed");
} }
@ -1559,8 +1566,7 @@ void uninstall_app(AMDeviceRef device) {
} }
void handle_device(AMDeviceRef device) { void handle_device(AMDeviceRef device) {
//if (found_device) NSLogVerbose(@"Already found device? %d", found_device);
// return; // handle one device only
CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device), CFStringRef found_device_id = AMDeviceCopyDeviceIdentifier(device),
device_full_name = get_device_full_name(device), device_full_name = get_device_full_name(device),
@ -1715,8 +1721,10 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar
case ADNCI_MSG_CONNECTED: case ADNCI_MSG_CONNECTED:
if(device_id != NULL || !debug || AMDeviceGetInterfaceType(info->dev) != 2) { if(device_id != NULL || !debug || AMDeviceGetInterfaceType(info->dev) != 2) {
AMDeviceNotificationUnsubscribe(*notify); AMDeviceNotificationUnsubscribe(*notify);
NSLogVerbose(@"Handling device type: %d", AMDeviceGetInterfaceType(info->dev));
handle_device(info->dev); handle_device(info->dev);
} else if(best_device_match == NULL) { } else if(best_device_match == NULL) {
NSLogVerbose(@"Best device match: %d", AMDeviceGetInterfaceType(info->dev));
best_device_match = info->dev; best_device_match = info->dev;
CFRetain(best_device_match); CFRetain(best_device_match);
} }
@ -1728,6 +1736,7 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar
void timeout_callback(CFRunLoopTimerRef timer, void *info) { void timeout_callback(CFRunLoopTimerRef timer, void *info) {
if ((!found_device) && (!detect_only)) { if ((!found_device) && (!detect_only)) {
if(best_device_match != NULL) { if(best_device_match != NULL) {
NSLogVerbose(@"Handling best device match.");
handle_device(best_device_match); handle_device(best_device_match);
CFRelease(best_device_match); CFRelease(best_device_match);
@ -1750,11 +1759,8 @@ void timeout_callback(CFRunLoopTimerRef timer, void *info) {
int mypid = getpid(); int mypid = getpid();
if ((parent != 0) && (parent == mypid) && (child != 0)) if ((parent != 0) && (parent == mypid) && (child != 0))
{ {
if (verbose) NSLogVerbose(@"Timeout. Killing child (%d) tree.", child);
{ kill_ptree(child, SIGHUP);
NSLogOut(@"Timeout. Killing child (%d) tree.", child);
}
kill_ptree(child, SIGHUP);
} }
} }
exit(0); exit(0);