Skip to content

Commit

Permalink
Merge pull request #307 from gusc/timeout-error-code
Browse files Browse the repository at this point in the history
Return an error code when timeout occurs while running an app.
  • Loading branch information
shazron authored Aug 9, 2017
2 parents 4124e66 + 5d55cec commit ce26934
Showing 1 changed file with 24 additions and 18 deletions.
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 @@ -1661,37 +1662,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

0 comments on commit ce26934

Please sign in to comment.