summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/idevicebackup.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index 616e03d..5b57a56 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -37,6 +37,9 @@
#define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup"
#define NP_SERVICE_NAME "com.apple.mobile.notification_proxy"
+#define LOCK_ATTEMPTS 50
+#define LOCK_WAIT 200000
+
static mobilebackup_client_t mobilebackup = NULL;
static lockdownd_client_t client = NULL;
static idevice_t phone = NULL;
@@ -609,12 +612,28 @@ int main(int argc, char *argv[])
uint64_t lockfile = 0;
afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile);
if (lockfile) {
+ afc_error_t aerr;
do_post_notification(NP_SYNC_LOCK_REQUEST);
- if (afc_file_lock(afc, lockfile, AFC_LOCK_EX) == AFC_E_SUCCESS) {
- do_post_notification(NP_SYNC_DID_START);
- } else {
+ for (i = 0; i < LOCK_ATTEMPTS; i++) {
+ aerr = afc_file_lock(afc, lockfile, AFC_LOCK_EX);
+ if (aerr == AFC_E_SUCCESS) {
+ do_post_notification(NP_SYNC_DID_START);
+ break;
+ } else if (aerr == AFC_E_OP_WOULD_BLOCK) {
+ usleep(LOCK_WAIT);
+ continue;
+ } else {
+ fprintf(stderr, "ERROR: could not lock file! error code: %d\n", aerr);
+ afc_file_close(afc, lockfile);
+ lockfile = 0;
+ cmd = CMD_LEAVE;
+ }
+ }
+ if (i == LOCK_ATTEMPTS) {
+ fprintf(stderr, "ERROR: timeout while locking for sync\n");
afc_file_close(afc, lockfile);
lockfile = 0;
+ cmd = CMD_LEAVE;
}
}