]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Make AsyncSocket_Close() idempotent; move dec-ref out of AsyncSocket_Close().
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:27 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:27 +0000 (11:23 -0700)
Changes to common source files; not applicable to open-vm-tools.

open-vm-tools/lib/asyncsocket/asyncSocketBase.c
open-vm-tools/lib/asyncsocket/asyncSocketBase.h
open-vm-tools/lib/asyncsocket/asyncSocketInterface.c
open-vm-tools/lib/asyncsocket/asyncsocket.c
open-vm-tools/lib/file/file.c
open-vm-tools/lib/include/productState.h

index d91deceb767c1411fa61e822a93880b32b02101d..10fc2c808db9e40f6d05c2dd8e034bd622beeb8d 100644 (file)
@@ -309,6 +309,7 @@ AsyncSocketInitSocket(AsyncSocket *s,                          // IN/OUT
    s->id = Atomic_ReadInc32(&nextid);
    s->refCount = 1;
    s->vt = vtable;
+   s->inited = TRUE;
    if (pollParams) {
       s->pollParams = *pollParams;
    } else {
@@ -320,6 +321,38 @@ AsyncSocketInitSocket(AsyncSocket *s,                          // IN/OUT
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * AsyncSocketTeardownSocket --
+ *
+ *    Tear down the AsyncSocket base struct.  Currently this just
+ *    clears the inited flag and releases the initial (user) refcount.
+ *
+ * Results:
+ *    None.
+ *
+ * Side effects:
+ *    None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+AsyncSocketTeardownSocket(AsyncSocket *asock)         // IN/OUT
+{
+   /*
+    * Release the initial refcount created when we initialize the
+    * socket struct.
+    */
+   ASSERT(AsyncSocketIsLocked(asock));
+   ASSERT(asock->refCount >= 1);
+   ASSERT(asock->inited);
+   asock->inited = FALSE;
+   AsyncSocketRelease(asock);
+}
+
+
 /*
  *----------------------------------------------------------------------------
  *
index 13126fe40b35990be910a8c740345bded9ed89e5..1f176b5c6e6b464d5cc5676acef70b73d4368e1b 100644 (file)
@@ -50,6 +50,7 @@ struct AsyncSocket {
    AsyncSocketPollParams pollParams;
    AsyncSocketState state;
 
+   Bool inited;
    Bool errorSeen;
    AsyncSocketErrorFn errorFn;
    void *errorClientData;
@@ -67,6 +68,7 @@ struct AsyncSocket {
 void AsyncSocketInitSocket(AsyncSocket *asock,
                            AsyncSocketPollParams *params,
                            const AsyncSocketVTable *vtable);
+void AsyncSocketTeardownSocket(AsyncSocket *s);
 
 void AsyncSocketLock(AsyncSocket *asock);
 void AsyncSocketUnlock(AsyncSocket *asock);
index 0d50b51cbba32982e8287bf012896c63788a25ad..e4cd077fdc2bf3dbf464c5e1d5b3527ec0f55c8c 100644 (file)
@@ -919,7 +919,7 @@ AsyncSocket_Close(AsyncSocket *asock)         // IN
    if (VALID(asock, close)) {
       AsyncSocketLock(asock);
       ret = VT(asock)->close(asock);
-      AsyncSocketRelease(asock);
+      ASSERT(!asock->inited);
       AsyncSocketUnlock(asock);
    } else {
       ret = ASOCKERR_INVAL;
index fa46133173b2f2b8fa3b5c30268150cc23072304..3c7ee8b490329c03425e1fc6a465dfa9a48e64e8 100644 (file)
@@ -4442,6 +4442,7 @@ AsyncTCPSocketClose(AsyncSocket *base)   // IN
       }
    }
 
+   AsyncSocketTeardownSocket(base);
    return ASOCKERR_SUCCESS;
 }
 
index 456af1f62e918c5481ba721cc47ce587fd19f232..a34a9bb65a7566c4e08d1986d3186d7f97861496 100644 (file)
@@ -1603,6 +1603,10 @@ File_CreateDirectoryHierarchyEx(const char *pathName,   // IN:
    while (TRUE) {
       Bool failed;
       char *temp;
+#if defined(_WIN32)  
+      DWORD status;
+      DWORD statusNew;
+#endif
 
       index = FileFirstSlashIndex(pathName, index + 1);
 
@@ -1617,17 +1621,36 @@ File_CreateDirectoryHierarchyEx(const char *pathName,   // IN:
        * This is why we reverse the attempt and the check.
        */
 
+      /*
+       * Bugfix 1592498, set last error "Access denied" instead of
+       * "File not found". File_XXX have different implementations on
+       * Windows and Linux, this problem only happens on Windows.
+       */
       failed = !File_CreateDirectoryEx(temp, mask);
+#if defined(_WIN32)
+      status = GetLastError();
+      statusNew = ERROR_SUCCESS;
+#endif
 
       if (failed) {
          if (File_IsDirectory(temp)) {
             failed = FALSE;
+         } else {
+#if defined(_WIN32)
+            statusNew = GetLastError();
+#endif
          }
       } else if (topmostCreated != NULL && *topmostCreated == NULL) {
          *topmostCreated = temp;
          temp = NULL;
       }
 
+#if defined(_WIN32)
+      if (status == ERROR_ACCESS_DENIED && statusNew == ERROR_FILE_NOT_FOUND) {
+         SetLastError(status);
+      }
+#endif
+
       free(temp);
 
       if (failed) {
index d9463bb05e72c5bc07235bbe5e2dee94886dedad..b93897d7c0c578ce48613a18e3301258e7b84890 100644 (file)
@@ -51,7 +51,6 @@ typedef enum {
    PRODUCT_GANTRY       = 1 << 9,
    PRODUCT_VMACORETESTS = 1 << 10,
    PRODUCT_SRM          = 1 << 11,
-   PRODUCT_VIEWCRT      = 1 << 12,
    /* etc */
 } Product;
 typedef uint64 ProductMask;