summaryrefslogtreecommitdiff
path: root/source3/lib/server_mutex.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-03-10 21:08:29 +0100
committerVolker Lendecke <vl@samba.org>2008-03-10 21:08:45 +0100
commit1ebfc66b2c145289d1e1314e8415d9e3c6f405ae (patch)
tree30b3ca059640ecc963a8744c2a69ef4151dbac7b /source3/lib/server_mutex.c
parentd634ab06b34990b6eecee751435f2436ff76ec44 (diff)
downloadsamba-1ebfc66b2c145289d1e1314e8415d9e3c6f405ae.tar.gz
samba-1ebfc66b2c145289d1e1314e8415d9e3c6f405ae.tar.bz2
samba-1ebfc66b2c145289d1e1314e8415d9e3c6f405ae.zip
Use a separate tdb for mutexes
Another preparation to convert secrets.c to dbwrap: The dbwrap API does not provide a sane tdb_lock_with_timeout abstraction. In the clustered case the DC mutex is needed per-node anyway, so it is perfectly fine to use a local mutex only. (This used to be commit f94a63cd8f94490780ad9331da229c0bcb2ca5d6)
Diffstat (limited to 'source3/lib/server_mutex.c')
-rw-r--r--source3/lib/server_mutex.c57
1 files changed, 40 insertions, 17 deletions
diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c
index 2700aa103b..43c0de1975 100644
--- a/source3/lib/server_mutex.c
+++ b/source3/lib/server_mutex.c
@@ -28,28 +28,51 @@
This locking allows smbd's mutlithread architecture to look
like the single-connection that NT makes. */
-static char *mutex_server_name;
+struct named_mutex {
+ struct tdb_wrap *tdb;
+ char *name;
+};
-bool grab_server_mutex(const char *name)
+static int unlock_named_mutex(struct named_mutex *mutex)
{
- mutex_server_name = SMB_STRDUP(name);
- if (!mutex_server_name) {
- DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name));
- return False;
+ tdb_unlock_bystring(mutex->tdb->tdb, mutex->name);
+ return 0;
+}
+
+struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
+ int timeout)
+{
+ struct named_mutex *result;
+
+ result = talloc(mem_ctx, struct named_mutex);
+ if (result == NULL) {
+ DEBUG(0, ("talloc failed\n"));
+ return NULL;
}
- 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;
+
+ result->name = talloc_strdup(result, name);
+ if (result->name == NULL) {
+ DEBUG(0, ("talloc failed\n"));
+ TALLOC_FREE(result);
+ return NULL;
}
- return True;
-}
+ result->tdb = tdb_wrap_open(result, lock_path("mutex.tdb"), 0,
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ if (result->tdb == NULL) {
+ DEBUG(1, ("Could not open mutex.tdb: %s\n",
+ strerror(errno)));
+ TALLOC_FREE(result);
+ return NULL;
+ }
-void release_server_mutex(void)
-{
- if (mutex_server_name) {
- secrets_named_mutex_release(mutex_server_name);
- SAFE_FREE(mutex_server_name);
+ if (tdb_lock_bystring_with_timeout(result->tdb->tdb, name,
+ timeout) == -1) {
+ DEBUG(1, ("Could not get the lock for %s\n", name));
+ TALLOC_FREE(result);
+ return NULL;
}
+
+ talloc_set_destructor(result, unlock_named_mutex);
+ return result;
}