]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Add g_lock_ctx_init_backend()
authorVolker Lendecke <vl@samba.org>
Tue, 5 Nov 2019 15:36:44 +0000 (16:36 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 22 Nov 2019 23:57:48 +0000 (23:57 +0000)
This will allow using the g_lock.c logic on other databases as well

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/g_lock.h
source3/lib/g_lock.c

index 5280a324f928a0fd806c00acea74a9a9d9989636..5e12ffe4b952f04f18211f88d53b36cdae4db986 100644 (file)
@@ -30,6 +30,10 @@ enum g_lock_type {
        G_LOCK_WRITE = 1,
 };
 
+struct g_lock_ctx *g_lock_ctx_init_backend(
+       TALLOC_CTX *mem_ctx,
+       struct messaging_context *msg,
+       struct db_context **backend);
 struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
                                   struct messaging_context *msg);
 
index d2ff6796628529890a1afd3f30c55e67b861f724..ae551fd2b161e59e64a589d7f85beff36857abe1 100644 (file)
@@ -151,12 +151,12 @@ static NTSTATUS g_lock_store(struct db_record *rec, struct g_lock *lck,
        return dbwrap_record_storev(rec, dbufs, ARRAY_SIZE(dbufs), 0);
 }
 
-struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
-                                  struct messaging_context *msg)
+struct g_lock_ctx *g_lock_ctx_init_backend(
+       TALLOC_CTX *mem_ctx,
+       struct messaging_context *msg,
+       struct db_context **backend)
 {
        struct g_lock_ctx *result;
-       struct db_context *backend;
-       char *db_path;
 
        result = talloc(mem_ctx, struct g_lock_ctx);
        if (result == NULL) {
@@ -164,31 +164,44 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
        }
        result->msg = msg;
 
-       db_path = lock_path(talloc_tos(), "g_lock.tdb");
-       if (db_path == NULL) {
+       result->db = db_open_watched(result, backend, msg);
+       if (result->db == NULL) {
+               DBG_WARNING("db_open_watched failed\n");
                TALLOC_FREE(result);
                return NULL;
        }
+       return result;
+}
+
+struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
+                                  struct messaging_context *msg)
+{
+       char *db_path = NULL;
+       struct db_context *backend = NULL;
+       struct g_lock_ctx *ctx = NULL;
+
+       db_path = lock_path(mem_ctx, "g_lock.tdb");
+       if (db_path == NULL) {
+               return NULL;
+       }
 
-       backend = db_open(result, db_path, 0,
-                         TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
-                         O_RDWR|O_CREAT, 0600,
-                         DBWRAP_LOCK_ORDER_3,
-                         DBWRAP_FLAG_NONE);
+       backend = db_open(
+               mem_ctx,
+               db_path,
+               0,
+               TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
+               O_RDWR|O_CREAT,
+               0600,
+               DBWRAP_LOCK_ORDER_3,
+               DBWRAP_FLAG_NONE);
        TALLOC_FREE(db_path);
        if (backend == NULL) {
                DBG_WARNING("Could not open g_lock.tdb\n");
-               TALLOC_FREE(result);
                return NULL;
        }
 
-       result->db = db_open_watched(result, &backend, msg);
-       if (result->db == NULL) {
-               DBG_WARNING("db_open_watched failed\n");
-               TALLOC_FREE(result);
-               return NULL;
-       }
-       return result;
+       ctx = g_lock_ctx_init_backend(mem_ctx, msg, &backend);
+       return ctx;
 }
 
 static bool g_lock_conflicts(enum g_lock_type l1, enum g_lock_type l2)