Skip to content

Commit

Permalink
inotify: Work around race condition by adding a retry loop
Browse files Browse the repository at this point in the history
In certain circumstances usbmuxd might not have been started up when the
socket file creation event has occured. This causes connect_usbmuxd_socket()
to fail and usbmuxd_listen_inotify() is invoked again, but the socket file
creation event will not occur anymore. To fix this we retry to connect to
usbmuxd after waiting a second in case the first connection attempt failed
(with a maximum of 10 retries).
  • Loading branch information
nikias committed Oct 10, 2014
1 parent 471b226 commit ef914f1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libusbmuxd.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,14 @@ static int usbmuxd_listen_inotify()
pevent->len &&
pevent->name[0] != 0 &&
strcmp(pevent->name, USBMUXD_SOCKET_NAME) == 0) {
sfd = connect_usbmuxd_socket ();
/* retry if usbmuxd isn't ready yet */
int retry = 10;
while (--retry >= 0) {
if ((sfd = connect_usbmuxd_socket ()) >= 0) {
break;
}
sleep(1);
}
goto end;
}
i += EVENT_SIZE + pevent->len;
Expand Down

0 comments on commit ef914f1

Please sign in to comment.