r5779: Remove signal and timeout gubbage from tdb.
authorTim Potter <tpot@samba.org>
Sun, 13 Mar 2005 01:40:45 +0000 (01:40 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:11:03 +0000 (13:11 -0500)
(This used to be commit dbb56e9a59cf00d57b09ded6d60bf9424d5f1f4c)

source4/lib/tdb/common/tdb.c
source4/lib/tdb/common/tdbutil.c
source4/lib/tdb/include/tdb.h

index 90b586d487b8e2563dec8c9b7b54d2985f6933af..d9fabaeda9195c6de606646f70a25eb23fb0b256 100644 (file)
@@ -61,7 +61,6 @@
 #include <errno.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <signal.h>
 #include "tdb.h"
 #else
 #include "includes.h"
@@ -193,18 +192,6 @@ struct list_struct {
        */
 };
 
-/***************************************************************
- Allow a caller to set a "alarm" flag that tdb can check to abort
- a blocking lock on SIGALRM.
-***************************************************************/
-
-static sig_atomic_t *palarm_fired;
-
-void tdb_set_lock_alarm(sig_atomic_t *palarm)
-{
-       palarm_fired = palarm;
-}
-
 /* a byte range locking function - return 0 on success
    this functions locks/unlocks 1 byte at the specified offset.
 
@@ -231,27 +218,16 @@ static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset,
 
        do {
                ret = fcntl(tdb->fd,lck_type,&fl);
-               if (ret == -1 && errno == EINTR && palarm_fired && *palarm_fired)
-                       break;
        } while (ret == -1 && errno == EINTR);
 
        if (ret == -1) {
                if (!probe && lck_type != F_SETLK) {
                        /* Ensure error code is set for log fun to examine. */
-                       if (errno == EINTR && palarm_fired && *palarm_fired)
-                               tdb->ecode = TDB_ERR_LOCK_TIMEOUT;
-                       else
-                               tdb->ecode = TDB_ERR_LOCK;
+                       tdb->ecode = TDB_ERR_LOCK;
                        TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n", 
                                 tdb->fd, offset, rw_type, lck_type));
                }
-               /* Was it an alarm timeout ? */
-               if (errno == EINTR && palarm_fired && *palarm_fired) {
-                       TDB_LOG((tdb, 5, "tdb_brlock timed out (fd=%d) at offset %d rw_type=%d lck_type=%d\n", 
-                                tdb->fd, offset, rw_type, lck_type));
-                       return TDB_ERRCODE(TDB_ERR_LOCK_TIMEOUT, -1);
-               }
-               /* Otherwise - generic lock error. errno set by fcntl.
+               /* Generic lock error. errno set by fcntl.
                 * EAGAIN is an expected return from non-blocking
                 * locks. */
                if (errno != EAGAIN) {
index e3c56410544190f3cced309e6d6d5ba6bed00709..3f9b22759188d0653a0b4704595810bebd5cd3e7 100644 (file)
 /* these are little tdb utility functions that are meant to make
    dealing with a tdb database a little less cumbersome in Samba */
 
-static sig_atomic_t gotalarm;
-
-/***************************************************************
- Signal function to tell us we timed out.
-****************************************************************/
-
-static void gotalarm_sig(void)
-{
-       gotalarm = 1;
-}
-
-
-/*******************************************************************
- THIS is a copy of the function CatchSignal found in lib/signal.c
- I need to copy it there to avoid sucking all of the samba source
- into tdb.
-
- Catch a signal. This should implement the following semantics:
-
- 1) The handler remains installed after being called.
- 2) The signal should be blocked during handler execution.
-********************************************************************/
-
-static void (*TdbCatchSignal(int signum,void (*handler)(int )))(int)
-{
-#ifdef HAVE_SIGACTION
-       struct sigaction act;
-       struct sigaction oldact;
-
-       ZERO_STRUCT(act);
-
-       act.sa_handler = handler;
-#ifdef SA_RESTART
-       /*
-        * We *want* SIGALRM to interrupt a system call.
-        */
-       if(signum != SIGALRM)
-               act.sa_flags = SA_RESTART;
-#endif
-       sigemptyset(&act.sa_mask);
-       sigaddset(&act.sa_mask,signum);
-       sigaction(signum,&act,&oldact);
-       return oldact.sa_handler;
-#else /* !HAVE_SIGACTION */
-       /* FIXME: need to handle sigvec and systems with broken signal() */
-       return signal(signum, handler);
-#endif
-}
-
-
-
 /***************************************************************
  Make a TDB_DATA and keep the const warning in one place
 ****************************************************************/
@@ -92,53 +41,6 @@ static TDB_DATA make_tdb_data(const char *dptr, size_t dsize)
        return ret;
 }
 
-/****************************************************************************
- Lock a chain with timeout (in seconds).
-****************************************************************************/
-
-static int tdb_chainlock_with_timeout_internal(TDB_CONTEXT *tdb, TDB_DATA key, uint_t timeout, int rw_type)
-{
-       /* Allow tdb_chainlock to be interrupted by an alarm. */
-       int ret;
-       gotalarm = 0;
-       tdb_set_lock_alarm(&gotalarm);
-
-       if (timeout) {
-               TdbCatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
-               alarm(timeout);
-       }
-
-       if (rw_type == F_RDLCK)
-               ret = tdb_chainlock_read(tdb, key);
-       else
-               ret = tdb_chainlock(tdb, key);
-
-       if (timeout) {
-               alarm(0);
-               TdbCatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
-               if (gotalarm) {
-                       tdb->log_fn(tdb, 0, "tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
-                               timeout, key.dptr, tdb->name);
-                       /* TODO: If we time out waiting for a lock, it might
-                        * be nice to use F_GETLK to get the pid of the
-                        * process currently holding the lock and print that
-                        * as part of the debugging message. -- mbp */
-                       return -1;
-               }
-       }
-
-       return ret;
-}
-
-/****************************************************************************
- Write lock a chain. Return -1 if timeout or lock failed.
-****************************************************************************/
-
-int tdb_chainlock_with_timeout(TDB_CONTEXT *tdb, TDB_DATA key, uint_t timeout)
-{
-       return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
-}
-
 /****************************************************************************
  Lock a chain by string. Return -1 if timeout or lock failed.
 ****************************************************************************/
@@ -147,7 +49,7 @@ int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval, uint_t timeout)
 {
        TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1);
        
-       return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
+       return tdb_chainlock(tdb, key);
 }
 
 /****************************************************************************
@@ -169,7 +71,7 @@ int tdb_read_lock_bystring(TDB_CONTEXT *tdb, const char *keyval, uint_t timeout)
 {
        TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1);
        
-       return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_RDLCK);
+       return tdb_chainlock_read(tdb, key);
 }
 
 /****************************************************************************
index 1de5517d917467b431dd4320de3816b776995ecf..846b157758ade1b0b3ec73e37ec7b3a6ac3707d8 100644 (file)
@@ -138,7 +138,6 @@ int tdb_lockall(TDB_CONTEXT *tdb);
 void tdb_unlockall(TDB_CONTEXT *tdb);
 
 /* Low level locking functions: use with care */
-void tdb_set_lock_alarm(sig_atomic_t *palarm);
 int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key);
 int tdb_chainlock_read(TDB_CONTEXT *tdb, TDB_DATA key);