diff options
author | Jeremy Allison <jra@samba.org> | 2002-10-04 22:53:30 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-10-04 22:53:30 +0000 |
commit | 9c94d1a2f72b6fcbbd056804837fc8719806491b (patch) | |
tree | 71d5b825cc8bebd43bf319b604a003bcddf3cdd7 /source3/tdb/tdbutil.c | |
parent | fac6a13fd3cee8f3f4f7f8e3a2dbb700181c67c3 (diff) | |
download | samba-9c94d1a2f72b6fcbbd056804837fc8719806491b.tar.gz samba-9c94d1a2f72b6fcbbd056804837fc8719806491b.tar.bz2 samba-9c94d1a2f72b6fcbbd056804837fc8719806491b.zip |
Add a timeout to tdb_lock_bystring(). Ensure we never have more than
MAX_PRINT_JOBS in a queue.
Jeremy.
(This used to be commit bb58a08af459b4abae9d53ab98c15f40638ce52b)
Diffstat (limited to 'source3/tdb/tdbutil.c')
-rw-r--r-- | source3/tdb/tdbutil.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c index 1a3a8bb9a5..e7650033b8 100644 --- a/source3/tdb/tdbutil.c +++ b/source3/tdb/tdbutil.c @@ -24,18 +24,57 @@ /* 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; +} + +/**************************************************************************** + Lock a chain with timeout (in seconds). +****************************************************************************/ + +int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout) +{ + /* Allow tdb_chainlock to be interrupted by an alarm. */ + int ret; + gotalarm = 0; + tdb_set_lock_alarm(&gotalarm); + + if (timeout) { + CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); + alarm(timeout); + } + + ret = tdb_chainlock(tdb, key); + + if (timeout) { + alarm(0); + CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); + if (gotalarm) + return -1; + } + + return ret; +} + /**************************************************************************** - Lock a chain by string. + Lock a chain by string. Return -1 if timeout or lock failed. ****************************************************************************/ -int tdb_lock_bystring(TDB_CONTEXT *tdb, char *keyval) +int tdb_lock_bystring(TDB_CONTEXT *tdb, char *keyval, unsigned int timeout) { TDB_DATA key; key.dptr = keyval; key.dsize = strlen(keyval)+1; - return tdb_chainlock(tdb, key); + return tdb_chainlock_with_timeout(tdb, key, timeout); } /**************************************************************************** @@ -230,7 +269,7 @@ int32 tdb_change_int32_atomic(TDB_CONTEXT *tdb, char *keystr, int32 *oldval, int int32 val; int32 ret = -1; - if (tdb_lock_bystring(tdb, keystr) == -1) + if (tdb_lock_bystring(tdb, keystr,0) == -1) return -1; if ((val = tdb_fetch_int32(tdb, keystr)) == -1) { @@ -271,7 +310,7 @@ BOOL tdb_change_uint32_atomic(TDB_CONTEXT *tdb, char *keystr, uint32 *oldval, ui uint32 val; BOOL ret = False; - if (tdb_lock_bystring(tdb, keystr) == -1) + if (tdb_lock_bystring(tdb, keystr,0) == -1) return False; if (!tdb_fetch_uint32(tdb, keystr, &val)) { |