summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christophe Fergeau2015-07-02 17:30:53 +0200
committerGravatar Nikias Bassen2016-07-14 03:15:58 +0200
commitfc9e1764ae65b9420bc1bf8e26307c21f542357b (patch)
tree519c82f3f5a1f1925e066ace75f047a299100104
parent75c6f68dde6ddaa7b7e0579d5f62eaf0d661511b (diff)
downloadlibusbmuxd-fc9e1764ae65b9420bc1bf8e26307c21f542357b.tar.gz
libusbmuxd-fc9e1764ae65b9420bc1bf8e26307c21f542357b.tar.bz2
Report pthread_kill/pthread_join errors in usbmuxd_unsubscribe
In order to avoid race condition between an usbmuxd_event_cb_t firing in a different thread and usbmuxd_unsubscribe() being called, libusbmuxd users must assume that once usbmuxd_unsubcribe() returns, no more usbmuxd_event_cb_t callbacks will fire, but also that those which were already started when usbmuxd_unsubcribe() is called will have completed. usbmuxd_unsubcribe() tries to guarantee this, but pthread_kill/pthread_join may fail, in which case this guarantee would not hold. This commit makes sure an error is reported to the caller when we get in this situation (though I'm not really sure how the caller could handle it).
-rw-r--r--src/libusbmuxd.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c
index 327746b..2897da6 100644
--- a/src/libusbmuxd.c
+++ b/src/libusbmuxd.c
@@ -806,6 +806,7 @@ USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
USBMUXD_API int usbmuxd_unsubscribe()
{
+ int res;
event_cb = NULL;
socket_shutdown(listenfd, SHUT_RDWR);
@@ -815,9 +816,13 @@ USBMUXD_API int usbmuxd_unsubscribe()
WaitForSingleObject(devmon, INFINITE);
}
#else
- if (pthread_kill(devmon, 0) == 0) {
+ res = pthread_kill(devmon, 0);
+ if (res == 0) {
pthread_cancel(devmon);
- pthread_join(devmon, NULL);
+ res = pthread_join(devmon, NULL);
+ }
+ if ((res != 0) && (res != ESRCH)) {
+ return res;
}
#endif