tdb_wrap: Remove tdb_wrap_open_ again
[kai/samba-autobuild/.git] / source3 / lib / server_mutex.c
index dc658191970f346d21666b9f19ecaf246bf6c9f6..43cf77b94d9fabcab1298a97a475e9cfac0004fa 100644 (file)
 
 #include "includes.h"
 #include "system/filesys.h"
-#include "lib/util/tdb_wrap.h"
+#include "lib/tdb_wrap/tdb_wrap.h"
 #include "util_tdb.h"
+#include "lib/param/param.h"
 
 /* For reasons known only to MS, many of their NT/Win2k versions
    need serialised access only.  Two connections at the same time
    may (in certain situations) cause connections to be reset,
    or access to be denied.
 
-   This locking allows smbd's mutlithread architecture to look
+   This locking allows smbd's multithread architecture to look
    like the single-connection that NT makes. */
 
 struct named_mutex {
@@ -46,6 +47,8 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
                                     int timeout)
 {
        struct named_mutex *result;
+       struct loadparm_context *lp_ctx;
+       const char *fname;
 
        result = talloc(mem_ctx, struct named_mutex);
        if (result == NULL) {
@@ -53,6 +56,13 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
                return NULL;
        }
 
+       lp_ctx = loadparm_init_s3(result, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(0, ("loadparm_init_s3 failed\n"));
+               talloc_free(result);
+               return NULL;
+       }
+
        result->name = talloc_strdup(result, name);
        if (result->name == NULL) {
                DEBUG(0, ("talloc failed\n"));
@@ -60,8 +70,16 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
                return NULL;
        }
 
-       result->tdb = tdb_wrap_open(result, lock_path("mutex.tdb"), 0,
-                                   TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+       fname = lock_path("mutex.tdb");
+
+       result->tdb = tdb_wrap_open(result, fname,
+                                   lpcfg_tdb_hash_size(lp_ctx, fname),
+                                   lpcfg_tdb_flags(lp_ctx,
+                                                   TDB_DEFAULT |
+                                                   TDB_CLEAR_IF_FIRST |
+                                                   TDB_INCOMPATIBLE_HASH),
+                                   O_RDWR|O_CREAT, 0600);
+       talloc_unlink(result, lp_ctx);
        if (result->tdb == NULL) {
                DEBUG(1, ("Could not open mutex.tdb: %s\n",
                          strerror(errno)));