-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
>From a4cb43f512b25a750a7c674ae55db747a4ce096c Mon Sep 17 00:00:00 2001 From: Richard Jones <rjones@xxxxxxxxxx> Date: Wed, 24 Feb 2010 12:55:17 +0000 Subject: [PATCH] Ignore SIGWINCH in remote client call to poll(2) (RHBZ#567931). In bug 567931 we found that virt-top would exit occasionally when the terminal window was resized. Tracking this down it turned out that SIGWINCH was being delivered to the process at exactly the point where the libvirt remote driver was calling poll(2) waiting for a reply from libvirtd. This caused the poll(2) call to be interrupted (returning errno EINTR). However handling EINTR the same was as EAGAIN was not the solution to this problem since we found previously that this would break Ctrl-C handling (commit 47fec8eac2bb3). The correct solution is to mask out SIGWINCH for the duration of the poll(2) system call. The per-thread mask is changed and restored immediately after the call. Since we are using pthread_sigmask, this should not affect other threads, and since we restore the signal mask immediately afterwards it should not affect the current thread visibly either. Note use of ignore_value: It's not fatal if we cannot mask out SIGWINCH, and in any case pthread_sigmask never fails on Linux as long as you supply the correct arguments. I tested this patch and it cures the original problem with virt-top. --- src/remote/remote_driver.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 8914c39..00df300 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -87,6 +87,7 @@ #include "memory.h" #include "util.h" #include "event.h" +#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_REMOTE @@ -8386,6 +8387,7 @@ remoteIOEventLoop(virConnectPtr conn, struct remote_thread_call *tmp = priv->waitDispatch; struct remote_thread_call *prev; char ignore; + sigset_t oldmask, blockedsigs; fds[0].events = fds[0].revents = 0; fds[1].events = fds[1].revents = 0; @@ -8407,10 +8409,21 @@ remoteIOEventLoop(virConnectPtr conn, * can stuff themselves on the queue */ remoteDriverUnlock(priv); + /* Block SIGWINCH from interrupting poll in curses programs, + * then restore the original signal mask again immediately + * after the call (RHBZ#567931). + */ + sigemptyset (&blockedsigs); + sigaddset (&blockedsigs, SIGWINCH); + ignore_value (pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); + repoll: ret = poll(fds, ARRAY_CARDINALITY(fds), -1); if (ret < 0 && errno == EAGAIN) goto repoll; + + ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); + remoteDriverLock(priv); if (fds[1].revents) { -- 1.6.5.2
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list