]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix locking in virsh console
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Mon, 10 Mar 2014 10:51:32 +0000 (14:51 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Mon, 10 Mar 2014 10:51:32 +0000 (14:51 +0400)
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

index 9c39ac42d285ba20dbbb7796abd7777f7f5db620..c664a3a6cd1996d60d0da36903d20e962a3b5211 100644 (file)
@@ -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: