]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/log: the log lock has magical properties
authorVMware, Inc <>
Mon, 26 Jul 2010 19:08:50 +0000 (12:08 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 26 Jul 2010 19:08:50 +0000 (12:08 -0700)
The log facility must use a lock. If the lock acquisition routine
were to use Log/Warning an infinite recursion is set up:

Log -> Lock -> Log -> Lock ...

It makes it imperitive that the log facility lock never have the
potential to emit a message. We just don't know where a developer
will place a Log/Warning.

The fix for this is an alternative lock creation routine, limited
to the recursive lock required for the log facility, that allows
the specification of a new parameter - beSilent (damn it!).

Ultimately this works because the core locking logic is inherently
silent; only the statistics code, if present, has to be bypassed.

Since this ultimately fixes a PR, the work-around to this issue
can also be removed.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/userlock.h
open-vm-tools/lib/lock/ulRec.c

index eb54e6352dcbb3b77eb0edc3fb6df968154d919d..92c95b6f2aa3b6b091ca9f33eb0b18016e782136 100644 (file)
@@ -75,6 +75,10 @@ Bool MXUser_TimedWaitCondVarExclLock(MXUserExclLock *lock,
 MXUserRecLock *MXUser_CreateRecLock(const char *name,
                                     MX_Rank rank);
 
+MXUserRecLock *MXUser_CreateRecLockEx(const char *name,
+                                      MX_Rank rank,
+                                      Bool beSilent);
+
 void MXUser_AcquireRecLock(MXUserRecLock *lock);
 Bool MXUser_TryAcquireRecLock(MXUserRecLock *lock);
 void MXUser_ReleaseRecLock(MXUserRecLock *lock);
index f16efca5d4337f76e84ce8ea2a03fbbfdc5259b6..87c2be922037394df1ed3b813d92e2e30f67bf09 100644 (file)
@@ -170,9 +170,10 @@ MXUserDumpRecLock(MXUserHeader *header)  // IN:
 /*
  *-----------------------------------------------------------------------------
  *
- * MXUser_CreateRecLock --
+ * MXUser_CreateRecLockEx --
  *
- *      Create a recursive lock.
+ *      Create a recursive lock specifying if the lock must always be
+ *      silent - never logging any messages.
  *
  *      Only the owner (thread) of a recursive lock may recurse on it.
  *
@@ -187,8 +188,9 @@ MXUserDumpRecLock(MXUserHeader *header)  // IN:
  */
 
 MXUserRecLock *
-MXUser_CreateRecLock(const char *userName,  // IN:
-                     MX_Rank rank)          // IN:
+MXUser_CreateRecLockEx(const char *userName,  // IN:
+                       MX_Rank rank,          // IN:
+                       Bool beSilent)         // IN:
 {
    char *properName;
    MXUserStats *stats;
@@ -219,25 +221,56 @@ MXUser_CreateRecLock(const char *userName,  // IN:
 #if defined(MXUSER_STATS)
    lock->header.statsFunc = MXUserStatsActionRec;
    lock->header.identifier = MXUserAllocID();
-
-   stats = Util_SafeCalloc(1, sizeof(*stats));
-#else
-   stats = NULL;
 #endif
 
-   Atomic_WritePtr(&lock->statsMem, stats);
+   if (beSilent) {
+      stats = NULL;
+   } else {
+#if defined(MXUSER_STATS)
+      stats = Util_SafeCalloc(1, sizeof(*stats));
 
-   if (stats) {
       MXUserAcquisitionStatsSetUp(&stats->acquisitionStats);
       MXUserBasicStatsSetUp(&stats->heldStats, MXUSER_STAT_CLASS_HELD);
+#else
+      stats = NULL;
+#endif
    }
 
+   Atomic_WritePtr(&lock->statsMem, stats);
+
    MXUserAddToList(&lock->header);
 
    return lock;
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * MXUser_CreateRecLock --
+ *
+ *      Create a recursive lock.
+ *
+ *      Only the owner (thread) of a recursive lock may recurse on it.
+ *
+ * Results:
+ *      NULL  Creation failed
+ *      !NULL Creation succeeded
+ *
+ * Side effects:
+ *      None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+MXUserRecLock *
+MXUser_CreateRecLock(const char *userName,  // IN:
+                     MX_Rank rank)          // IN:
+{
+   return MXUser_CreateRecLockEx(userName, rank, FALSE);
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *