summaryrefslogtreecommitdiffstats
path: root/tools/idevicebackup.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/idevicebackup.c')
-rw-r--r--tools/idevicebackup.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index 76ae1a0..867eaad 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -38,6 +38,9 @@
38#define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" 38#define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup"
39#define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" 39#define NP_SERVICE_NAME "com.apple.mobile.notification_proxy"
40 40
41#define LOCK_ATTEMPTS 50
42#define LOCK_WAIT 200000
43
41static mobilebackup_client_t mobilebackup = NULL; 44static mobilebackup_client_t mobilebackup = NULL;
42static lockdownd_client_t client = NULL; 45static lockdownd_client_t client = NULL;
43static idevice_t phone = NULL; 46static idevice_t phone = NULL;
@@ -873,12 +876,28 @@ int main(int argc, char *argv[])
873 afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); 876 afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile);
874 } 877 }
875 if (lockfile) { 878 if (lockfile) {
879 afc_error_t aerr;
876 do_post_notification(NP_SYNC_LOCK_REQUEST); 880 do_post_notification(NP_SYNC_LOCK_REQUEST);
877 if (afc_file_lock(afc, lockfile, AFC_LOCK_EX) == AFC_E_SUCCESS) { 881 for (i = 0; i < LOCK_ATTEMPTS; i++) {
878 do_post_notification(NP_SYNC_DID_START); 882 aerr = afc_file_lock(afc, lockfile, AFC_LOCK_EX);
879 } else { 883 if (aerr == AFC_E_SUCCESS) {
884 do_post_notification(NP_SYNC_DID_START);
885 break;
886 } else if (aerr == AFC_E_OP_WOULD_BLOCK) {
887 usleep(LOCK_WAIT);
888 continue;
889 } else {
890 fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr);
891 afc_file_close(afc, lockfile);
892 lockfile = 0;
893 cmd = CMD_LEAVE;
894 }
895 }
896 if (i == LOCK_ATTEMPTS) {
897 fprintf(stderr, "ERROR: timeout while locking for sync\n");
880 afc_file_close(afc, lockfile); 898 afc_file_close(afc, lockfile);
881 lockfile = 0; 899 lockfile = 0;
900 cmd = CMD_LEAVE;
882 } 901 }
883 } 902 }
884 903