diff options
author | Jeremy Allison <jra@samba.org> | 2002-09-17 23:45:21 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-09-17 23:45:21 +0000 |
commit | a7781f91d8c1177210bffc199cd2f3b7ff993eaf (patch) | |
tree | 542caee08cea0b14d2d75ac6755fe4af34cb6710 /source/tdb | |
parent | f8a0e6ad8b25d405ff2bcb492974d2f0bef81036 (diff) | |
download | samba-a7781f91d8c1177210bffc199cd2f3b7ff993eaf.tar.gz samba-a7781f91d8c1177210bffc199cd2f3b7ff993eaf.tar.xz samba-a7781f91d8c1177210bffc199cd2f3b7ff993eaf.zip |
Never, *ever* hold a mutex lock in the message database where there may
be traversals being attempted. Yes, this was from bitter experience (and
an out of control server :-). Also allow callers to break out of a tdb_chainlock
with sigalarm if desired.
Jeremy.
Diffstat (limited to 'source/tdb')
-rw-r--r-- | source/tdb/tdb.c | 15 | ||||
-rw-r--r-- | source/tdb/tdb.h | 1 | ||||
-rw-r--r-- | source/tdb/tdbbackup.c | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c index 40e7dcd42c7..5bb75ffe077 100644 --- a/source/tdb/tdb.c +++ b/source/tdb/tdb.c @@ -34,6 +34,7 @@ #include <errno.h> #include <sys/mman.h> #include <sys/stat.h> +#include <signal.h> #include "tdb.h" #include "spinlock.h" #else @@ -160,6 +161,18 @@ 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. @@ -186,6 +199,8 @@ 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) { diff --git a/source/tdb/tdb.h b/source/tdb/tdb.h index 8cc908703f8..42b88aeb161 100644 --- a/source/tdb/tdb.h +++ b/source/tdb/tdb.h @@ -126,6 +126,7 @@ 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); diff --git a/source/tdb/tdbbackup.c b/source/tdb/tdbbackup.c index f59f98a90f5..36ba7db9188 100644 --- a/source/tdb/tdbbackup.c +++ b/source/tdb/tdbbackup.c @@ -53,6 +53,7 @@ #include <sys/stat.h> #include <sys/time.h> #include <ctype.h> +#include <signal.h> #include "tdb.h" static int failed; |