From ef914f101de98af51063979448e971fdf6c96ce8 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 10 Oct 2014 21:53:07 +0200 Subject: inotify: Work around race condition by adding a retry loop 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). --- src/libusbmuxd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index d38d850..af8636b 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -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; -- cgit v1.1-32-gdbae