From: VMware, Inc <> Date: Mon, 26 Jul 2010 19:08:50 +0000 (-0700) Subject: lib/log: the log lock has magical properties X-Git-Tag: 2010.07.25-280253~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=17aec297772e701a8bdaf32fef92ddb08db3f470;p=thirdparty%2Fopen-vm-tools.git lib/log: the log lock has magical properties 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 --- diff --git a/open-vm-tools/lib/include/userlock.h b/open-vm-tools/lib/include/userlock.h index eb54e6352..92c95b6f2 100644 --- a/open-vm-tools/lib/include/userlock.h +++ b/open-vm-tools/lib/include/userlock.h @@ -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); diff --git a/open-vm-tools/lib/lock/ulRec.c b/open-vm-tools/lib/lock/ulRec.c index f16efca5d..87c2be922 100644 --- a/open-vm-tools/lib/lock/ulRec.c +++ b/open-vm-tools/lib/lock/ulRec.c @@ -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); +} + + /* *----------------------------------------------------------------------------- *