From f0836404b382747aeba03ee2cae9c3f16420fb66 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sat, 7 Apr 2012 15:37:37 +0200 Subject: libusbmuxd: use pthread_cancel to make usbmuxd_unsubscribe work properly This actually only affects inotify-enabled builds. Since the faulty SIGINT pthread 'killing' was replaced with a proper solution, this fix is required for the situation where usbmuxd isn't initially running or was terminated; in these cases libusbmuxd was hanging inside a read() system call (waiting for an inotify event) causing pthread_join in usbmuxd_unsubscribe() to wait infinitely. --- libusbmuxd/libusbmuxd.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c index 4195960..d9cbd71 100644 --- a/libusbmuxd/libusbmuxd.c +++ b/libusbmuxd/libusbmuxd.c @@ -580,6 +580,14 @@ int get_next_event(int sfd, usbmuxd_event_cb_t callback, void *user_data) return 0; } +static void device_monitor_cleanup(void* data) +{ + collection_free(&devices); + + close_socket(listenfd); + listenfd = -1; +} + /** * Device Monitor thread function. * @@ -589,6 +597,9 @@ static void *device_monitor(void *data) { collection_init(&devices); +#ifndef WIN32 + pthread_cleanup_push(device_monitor_cleanup, NULL); +#endif while (event_cb) { listenfd = usbmuxd_listen(); @@ -604,11 +615,11 @@ static void *device_monitor(void *data) } } - collection_free(&devices); - - close_socket(listenfd); - listenfd = -1; - +#ifndef WIN32 + pthread_cleanup_pop(1); +#else + device_monitor_cleanup(); +#endif return NULL; } @@ -649,6 +660,7 @@ int usbmuxd_unsubscribe() } #else if (pthread_kill(devmon, 0) == 0) { + pthread_cancel(devmon); pthread_join(devmon, NULL); } #endif -- cgit v1.1-32-gdbae