aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-05-12 08:49:13 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-05-12 08:49:13 +0100
commit990e331218dba6b671854cec24f639ff45763d7d (patch)
treee97efe2c1972c4a9bc696072f2fcadd0cdeaea3c /tools/xenstore
parent20a817b0a72cbc330d1278552aa8d328940d1e7c (diff)
downloadxen-990e331218dba6b671854cec24f639ff45763d7d.tar.gz
xen-990e331218dba6b671854cec24f639ff45763d7d.tar.bz2
xen-990e331218dba6b671854cec24f639ff45763d7d.zip
xs: avoid pthread_join deadlock in xs_daemon_close
Doing a pthread_cancel and join on the reader thread while holding all the request/reply/watch mutexes can deadlock if the thread needs to take any of those mutexes to exit. Kill off the reader thread before taking any mutexes (which should be redundant if we're single-threaded at that point). Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r--tools/xenstore/xs.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 6a87ccf708..53e3d44345 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -260,10 +260,6 @@ void xs_daemon_destroy_postfork(struct xs_handle *h)
void xs_daemon_close(struct xs_handle *h)
{
- mutex_lock(&h->request_mutex);
- mutex_lock(&h->reply_mutex);
- mutex_lock(&h->watch_mutex);
-
#ifdef USE_PTHREAD
if (h->read_thr_exists) {
pthread_cancel(h->read_thr);
@@ -271,6 +267,10 @@ void xs_daemon_close(struct xs_handle *h)
}
#endif
+ mutex_lock(&h->request_mutex);
+ mutex_lock(&h->reply_mutex);
+ mutex_lock(&h->watch_mutex);
+
close_free_msgs(h);
mutex_unlock(&h->request_mutex);