diff options
author | Jeremy Allison <jra@samba.org> | 2002-03-26 22:36:27 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2002-03-26 22:36:27 +0000 |
commit | 1b9f1a368f2f37700cef357ab4bbc0389ec06378 (patch) | |
tree | 6edbd8b384e2798f9896eb845f02154323fbcbf2 /source/lib/messages.c | |
parent | 144f0481c8b05956bdc96461a82d530fa85e3c72 (diff) | |
download | samba-1b9f1a368f2f37700cef357ab4bbc0389ec06378.tar.gz samba-1b9f1a368f2f37700cef357ab4bbc0389ec06378.tar.xz samba-1b9f1a368f2f37700cef357ab4bbc0389ec06378.zip |
Don't hold the mutex for more than 20 seconds.
Jeremy.
Diffstat (limited to 'source/lib/messages.c')
-rw-r--r-- | source/lib/messages.c | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/source/lib/messages.c b/source/lib/messages.c index b745cbaf8bd..7d0da4b158b 100644 --- a/source/lib/messages.c +++ b/source/lib/messages.c @@ -464,6 +464,17 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, return True; } +static VOLATILE sig_atomic_t gotalarm; + +/*************************************************************** + Signal function to tell us we timed out. +****************************************************************/ + +static void gotalarm_sig(void) +{ + gotalarm = 1; +} + /** * Lock the messaging tdb based on a string - this is used as a primitive * form of mutex between smbd instances. @@ -471,16 +482,33 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, * @param name A string identifying the name of the mutex. */ -BOOL message_named_mutex(const char *name) +BOOL message_named_mutex(char *name, unsigned int timeout) { TDB_DATA key; + int ret; - if (!message_init()) return False; + if (!message_init()) + return False; key.dptr = name; key.dsize = strlen(name)+1; - return (tdb_chainlock(tdb, key) == 0); + if (timeout) { + gotalarm = 0; + 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 False; + } + + return (ret == 0); } /** @@ -489,7 +517,7 @@ BOOL message_named_mutex(const char *name) * @param name A string identifying the name of the mutex. */ -void message_named_mutex_release(const char *name) +void message_named_mutex_release(char *name) { TDB_DATA key; |