[libvirt] [PATCH] Fix locking in virsh console

While I'm still fighting with console on FreeBSD, I decided to sumbit that fix as it seems to be useful on its own. With that change I'm able to run virsh on FreeBSD to connect to libvirtd on Linux and get console working properly there. Roman Bogorodskiy (1): Fix locking in virsh console tools/virsh-console.c | 5 +++++ 1 file changed, 5 insertions(+) -- 1.8.4.2

vshRunConsole() uses virCondWait() which is a wrapper around pthread_cond_wait(). On FreeBSD, pthread_cond_wait needs mutex to be locked, otherwise it immediately fails with EPERM. On Linux, the behaviour in this case is undefined. So lock the mutex before calling virCondWait(). --- tools/virsh-console.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/virsh-console.c b/tools/virsh-console.c index 9c39ac4..c664a3a 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -356,6 +356,8 @@ vshRunConsole(vshControl *ctl, if (virCondInit(&con->cond) < 0 || virMutexInit(&con->lock) < 0) goto cleanup; + virMutexLock(&con->lock); + con->stdinWatch = virEventAddHandle(STDIN_FILENO, VIR_EVENT_HANDLE_READABLE, virConsoleEventOnStdin, @@ -375,11 +377,14 @@ vshRunConsole(vshControl *ctl, while (!con->quit) { if (virCondWait(&con->cond, &con->lock) < 0) { + virMutexUnlock(&con->lock); VIR_ERROR(_("unable to wait on console condition")); goto cleanup; } } + virMutexUnlock(&con->lock); + ret = 0; cleanup: -- 1.8.4.2

On Mon, Mar 10, 2014 at 03:04:15PM +0400, Roman Bogorodskiy wrote:
vshRunConsole() uses virCondWait() which is a wrapper around pthread_cond_wait(). On FreeBSD, pthread_cond_wait needs mutex to be locked, otherwise it immediately fails with EPERM. On Linux, the behaviour in this case is undefined.
So lock the mutex before calling virCondWait(). --- tools/virsh-console.c | 5 +++++ 1 file changed, 5 insertions(+)
ACK Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Daniel P. Berrange wrote:
On Mon, Mar 10, 2014 at 03:04:15PM +0400, Roman Bogorodskiy wrote:
vshRunConsole() uses virCondWait() which is a wrapper around pthread_cond_wait(). On FreeBSD, pthread_cond_wait needs mutex to be locked, otherwise it immediately fails with EPERM. On Linux, the behaviour in this case is undefined.
So lock the mutex before calling virCondWait(). --- tools/virsh-console.c | 5 +++++ 1 file changed, 5 insertions(+)
ACK
Pushed, thanks! Roman Bogorodskiy
participants (2)
-
Daniel P. Berrange
-
Roman Bogorodskiy