summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-04-07 15:37:37 +0200
committerGravatar Nikias Bassen2012-04-07 15:37:37 +0200
commitf0836404b382747aeba03ee2cae9c3f16420fb66 (patch)
treeea02ee3c2bfe0b2e8cdb9e91a7bac5c880e5fd3d /libusbmuxd
parentfabab8cb80ea87419afa7a1ccf4627e5e56da5e5 (diff)
downloadusbmuxd-f0836404b382747aeba03ee2cae9c3f16420fb66.tar.gz
usbmuxd-f0836404b382747aeba03ee2cae9c3f16420fb66.tar.bz2
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.
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/libusbmuxd.c22
1 files 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