Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return an error code when timeout occurs while running an app. #307

Merged
merged 1 commit into from
Aug 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/ios-deploy/ios-deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

// Error codes we report on different failures, so scripts can distinguish between user app exit
// codes and our exit codes. For non app errors we use codes in reserved 128-255 range.
const int exitcode_timeout = 252;
const int exitcode_error = 253;
const int exitcode_app_crash = 254;

Expand Down Expand Up @@ -1657,37 +1658,42 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar

void timeout_callback(CFRunLoopTimerRef timer, void *info) {
if (found_device && (!detect_only)) {
// App running for too long
NSLog(@"[ !! ] App is running for too long");
exit(exitcode_timeout);
return;
} else if ((!found_device) && (!detect_only)) {
if(best_device_match != NULL) {
// Device not found timeout
if (best_device_match != NULL) {
NSLogVerbose(@"Handling best device match.");
handle_device(best_device_match);

CFRelease(best_device_match);
best_device_match = NULL;
}

if(!found_device)
if (!found_device)
on_error(@"Timed out waiting for device.");
}
else
{
if (!debug) {
NSLogOut(@"[....] No more devices found.");
}

if (detect_only && !found_device) {
exit(exitcode_error);
return;
} else {
int mypid = getpid();
if ((parent != 0) && (parent == mypid) && (child != 0))
{
NSLogVerbose(@"Timeout. Killing child (%d) tree.", child);
kill_ptree(child, SIGHUP);
}
}
exit(0);
// Device detection timeout
if (!debug) {
NSLogOut(@"[....] No more devices found.");
}

if (detect_only && !found_device) {
exit(exitcode_error);
return;
} else {
int mypid = getpid();
if ((parent != 0) && (parent == mypid) && (child != 0))
{
NSLogVerbose(@"Timeout. Killing child (%d) tree.", child);
kill_ptree(child, SIGHUP);
}
}
exit(0);
}
}

Expand Down