summaryrefslogtreecommitdiffstats
path: root/libusbmuxd/libusbmuxd.c
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/libusbmuxd.c
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/libusbmuxd.c')
-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)
580 return 0; 580 return 0;
581} 581}
582 582
583static void device_monitor_cleanup(void* data)
584{
585 collection_free(&devices);
586
587 close_socket(listenfd);
588 listenfd = -1;
589}
590
583/** 591/**
584 * Device Monitor thread function. 592 * Device Monitor thread function.
585 * 593 *
@@ -589,6 +597,9 @@ static void *device_monitor(void *data)
589{ 597{
590 collection_init(&devices); 598 collection_init(&devices);
591 599
600#ifndef WIN32
601 pthread_cleanup_push(device_monitor_cleanup, NULL);
602#endif
592 while (event_cb) { 603 while (event_cb) {
593 604
594 listenfd = usbmuxd_listen(); 605 listenfd = usbmuxd_listen();
@@ -604,11 +615,11 @@ static void *device_monitor(void *data)
604 } 615 }
605 } 616 }
606 617
607 collection_free(&devices); 618#ifndef WIN32
608 619 pthread_cleanup_pop(1);
609 close_socket(listenfd); 620#else
610 listenfd = -1; 621 device_monitor_cleanup();
611 622#endif
612 return NULL; 623 return NULL;
613} 624}
614 625
@@ -649,6 +660,7 @@ int usbmuxd_unsubscribe()
649 } 660 }
650#else 661#else
651 if (pthread_kill(devmon, 0) == 0) { 662 if (pthread_kill(devmon, 0) == 0) {
663 pthread_cancel(devmon);
652 pthread_join(devmon, NULL); 664 pthread_join(devmon, NULL);
653 } 665 }
654#endif 666#endif