summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-08-17 04:11:10 +0200
committerGravatar Martin Szulecki2010-10-04 00:34:32 +0200
commite5ec41f50ec05eaea1804b879baa09e92f687a96 (patch)
tree8b122d3bf86ad2b4c9d81b1ee6701022193011c0 /tools
parent0ce860bfd858a79fd27015eaea22b1b62ebe34a2 (diff)
downloadlibimobiledevice-e5ec41f50ec05eaea1804b879baa09e92f687a96.tar.gz
libimobiledevice-e5ec41f50ec05eaea1804b879baa09e92f687a96.tar.bz2
idevicebackup: try multiple times to lock for sync
otherwise, the sync in progress screen might keep showing up until you swipe to cancel on the device
Diffstat (limited to 'tools')
-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;
}
}