]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Internal branch sync. Included in this change:
authorVMware, Inc <>
Wed, 18 Sep 2013 03:20:14 +0000 (20:20 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:06:57 +0000 (22:06 -0700)
. dnd plugin: various cleanups
. asyncsocket: Fix for race conditions with sync operations on a 2nd thread

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/asyncsocket/asyncsocket.c
open-vm-tools/services/plugins/dndcp/dnd/dndLinux.c

index 6fec4a1d0a80309700c60fdc6c484b38d8749288..9c55b34d9e5c500cec423df8888f9eebc7d02410 100644 (file)
@@ -3190,18 +3190,41 @@ AsyncSocket_WaitForConnection(AsyncSocket *s,  // IN:
    Bool read;
    int error;
    VmTimeType now, done;
+   Bool removed = FALSE;
 
    ASSERT(s->asockType != ASYNCSOCKET_TYPE_NAMEDPIPE);
 
+   AsyncSocketLock(s);
+
    if (s->state == AsyncSocketConnected) {
-      return ASOCKERR_SUCCESS;
+      error = ASOCKERR_SUCCESS;
+      goto outHaveLock;
    }
 
    if (s->state != AsyncSocketListening &&
        s->state != AsyncSocketConnecting) {
-      return ASOCKERR_GENERIC;
+      error = ASOCKERR_GENERIC;
+      goto outHaveLock;
    }
 
+   /*
+   * A nuisance.  ConnectCallback() is either registered as a device or
+   * rtime callback depending on the prior return value of connect().
+   * So we try to remove it from both.
+   *
+   * XXX: For listening sockets, the callback is AsyncSocketAcceptCallback,
+   * which would need to be unregistered here and then be re-registered
+   * before returning.
+   */
+   if (s->state == AsyncSocketConnecting) {
+      removed = AsyncSocketPollRemove(s, TRUE, POLL_FLAG_WRITE,
+         AsyncSocketConnectCallback)
+         || AsyncSocketPollRemove(s, FALSE, 0, AsyncSocketConnectCallback);
+      ASSERT(removed);
+   }
+
+   AsyncSocketUnlock(s);
+
    read = s->state == AsyncSocketListening;
 
    now = Hostinfo_SystemTimerUS() / 1000;
@@ -3231,18 +3254,6 @@ AsyncSocket_WaitForConnection(AsyncSocket *s,  // IN:
             goto outHaveLock;
          }
       } else {
-         /*
-          * A nuisance.  ConnectCallback() is either registered as a device or
-          * rtime callback depending on the prior return value of connect().
-          * So we try to remove it from both.
-          */
-
-         Bool removed = FALSE;
-         removed = AsyncSocketPollRemove(s, TRUE, POLL_FLAG_WRITE,
-                                         AsyncSocketConnectCallback)
-            || AsyncSocketPollRemove(s, FALSE, 0, AsyncSocketConnectCallback);
-         ASSERT(removed);
-
          error = AsyncSocketConnectInternal(s);
          goto outHaveLock;
       }
index e7fea758fb6e7fcc47b7fdd7ce23cafa50bf2d1d..609a7fadaaff5bfa22f8f0a712b38443672333c0 100644 (file)
@@ -334,6 +334,8 @@ Bool
 DnD_AddBlockLegacy(int blockFd,                    // IN
                    const char *blockPath)          // IN
 {
+   LOG(1, ("%s: placing block on %s\n", __func__, blockPath));
+
    ASSERT(blockFd >= 0);
 
    if (VMBLOCK_CONTROL(blockFd, VMBLOCK_ADD_FILEBLOCK, blockPath) != 0) {
@@ -367,6 +369,8 @@ Bool
 DnD_RemoveBlockLegacy(int blockFd,                    // IN
                       const char *blockedPath)        // IN
 {
+   LOG(1, ("%s: removing block on %s\n", __func__, blockedPath));
+
    if (blockFd >= 0) {
       if (VMBLOCK_CONTROL(blockFd, VMBLOCK_DEL_FILEBLOCK, blockedPath) != 0) {
          Log("%s: Cannot delete block on %s (%s)\n",
@@ -429,6 +433,8 @@ Bool
 DnD_AddBlockFuse(int blockFd,                    // IN
                  const char *blockPath)          // IN
 {
+   LOG(1, ("%s: placing block on %s\n", __func__, blockPath));
+
    ASSERT(blockFd >= 0);
 
    if (VMBLOCK_CONTROL_FUSE(blockFd, VMBLOCK_FUSE_ADD_FILEBLOCK,
@@ -463,6 +469,8 @@ Bool
 DnD_RemoveBlockFuse(int blockFd,                    // IN
                     const char *blockedPath)        // IN
 {
+   LOG(1, ("%s: removing block on %s\n", __func__, blockedPath));
+
    if (blockFd >= 0) {
       if (VMBLOCK_CONTROL_FUSE(blockFd, VMBLOCK_FUSE_DEL_FILEBLOCK,
                                blockedPath) != 0) {