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/lib | |
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/lib')
-rw-r--r-- | source/lib/messages.c | 69 | ||||
-rw-r--r-- | source/lib/server_mutex.c | 5 |
2 files changed, 2 insertions, 72 deletions
diff --git a/source/lib/messages.c b/source/lib/messages.c index 21470dff5c8..d9886a54daf 100644 --- a/source/lib/messages.c +++ b/source/lib/messages.c @@ -471,73 +471,4 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, *n_sent = msg_all.n_sent; return True; } - -static 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. - * - * @param name A string identifying the name of the mutex. - */ - -BOOL message_named_mutex(char *name, unsigned int timeout) -{ - TDB_DATA key; - int ret; - void (*oldsig_handler)(int) = NULL; - - if (!message_init()) - return False; - - key.dptr = name; - key.dsize = strlen(name)+1; - - if (timeout) { - gotalarm = 0; - oldsig_handler = CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig); - alarm(timeout); - } - - ret = tdb_chainlock(tdb, key); - - if (timeout) { - alarm(0); - CatchSignal(SIGALRM, SIGNAL_CAST oldsig_handler); - if (gotalarm) - return False; - } - - if (ret == 0) - DEBUG(10,("message_named_mutex: got mutex for %s\n", name )); - - return (ret == 0); -} - -/** - * Unlock a named mutex. - * - * @param name A string identifying the name of the mutex. - */ - -void message_named_mutex_release(char *name) -{ - TDB_DATA key; - - key.dptr = name; - key.dsize = strlen(name)+1; - - tdb_chainunlock(tdb, key); - DEBUG(10,("message_named_mutex: released mutex for %s\n", name )); -} - /** @} **/ diff --git a/source/lib/server_mutex.c b/source/lib/server_mutex.c index 416d77564d7..3e5512c7342 100644 --- a/source/lib/server_mutex.c +++ b/source/lib/server_mutex.c @@ -38,7 +38,7 @@ BOOL grab_server_mutex(const char *name) DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; } - if (!message_named_mutex(mutex_server_name, 20)) { + if (!secrets_named_mutex(mutex_server_name, 10)) { DEBUG(10,("grab_server_mutex: failed for %s\n", name)); SAFE_FREE(mutex_server_name); return False; @@ -50,8 +50,7 @@ BOOL grab_server_mutex(const char *name) void release_server_mutex(void) { if (mutex_server_name) { - message_named_mutex_release(mutex_server_name); + secrets_named_mutex_release(mutex_server_name); SAFE_FREE(mutex_server_name); } } - |