diff options
-rw-r--r-- | tools/ideviceenterrecovery.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tools/ideviceenterrecovery.c b/tools/ideviceenterrecovery.c index 822c10a..0cc9936 100644 --- a/tools/ideviceenterrecovery.c +++ b/tools/ideviceenterrecovery.c @@ -92,25 +92,37 @@ int main(int argc, char *argv[]) ret = idevice_new(&device, udid); if (ret != IDEVICE_E_SUCCESS) { printf("No device found with udid %s.\n", udid); - return -1; + return 1; } if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new(device, &client, TOOL_NAME))) { - printf("ERROR: Could not connect to lockdownd, error code %d\n", ldret); + printf("ERROR: Could not connect to lockdownd: %s (%d)\n", lockdownd_strerror(ldret), ldret); idevice_free(device); - return -1; + return 1; } - /* run query and output information */ + int res = 0; printf("Telling device with udid %s to enter recovery mode.\n", udid); - if(lockdownd_enter_recovery(client) != LOCKDOWN_E_SUCCESS) - { + ldret = lockdownd_enter_recovery(client); + if (ldret == LOCKDOWN_E_SESSION_INACTIVE) { + lockdownd_client_free(client); + client = NULL; + if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &client, TOOL_NAME))) { + printf("ERROR: Could not connect to lockdownd: %s (%d)\n", lockdownd_strerror(ldret), ldret); + idevice_free(device); + return 1; + } + ldret = lockdownd_enter_recovery(client); + } + if (ldret != LOCKDOWN_E_SUCCESS) { printf("Failed to enter recovery mode.\n"); + res = 1; + } else { + printf("Device is successfully switching to recovery mode.\n"); } - printf("Device is successfully switching to recovery mode.\n"); lockdownd_client_free(client); idevice_free(device); - return 0; + return res; } |