Fix race condition in alarm lock processing noticed by Richard Sharpe <realrichardsha...
authorJeremy Allison <jra@samba.org>
Thu, 8 Jan 2009 18:56:36 +0000 (10:56 -0800)
committerKarolin Seeger <kseeger@samba.org>
Mon, 12 Jan 2009 09:12:04 +0000 (10:12 +0100)
"It seems to me that if the lock is already held by another process when we
enter this code, there is a race between the timeout and the granting. If
the lock is subsequently granted, the process releasing the lock will signal
the wait variable (or whatever) and our process will be scheduled. However,
if the timeout occurs before we are scheduled, the timeout will be delivered
first.

We will have the lock but will forget we have the lock, and never release
it."
Jeremy.
(cherry picked from commit 8904b83ce6c69db31dc2ce4c05e8e8ee3db5ec3b)

source/lib/util_tdb.c

index d267a924e5578138df34ac42c4435d9e36359cae..c41df91488f685eb3a0465cc29ecd81855bfc491 100644 (file)
@@ -81,7 +81,7 @@ static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key,
                alarm(0);
                tdb_setalarm_sigptr(tdb, NULL);
                CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
-               if (gotalarm) {
+               if (gotalarm && (ret == -1)) {
                        DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
                                timeout, key.dptr, tdb_name(tdb)));
                        /* TODO: If we time out waiting for a lock, it might