s3:dbwrap_watch: split out db_watched_record_fini() from db_watched_record_destructor()
authorStefan Metzmacher <metze@samba.org>
Sun, 26 Jun 2022 08:58:21 +0000 (10:58 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 26 Jul 2022 13:40:34 +0000 (13:40 +0000)
That makes it easier to understand that db_watched_record_init() and
db_watched_record_fini() wrap any caller activity on the record,
either during do_locked or between fetch_locked and the related
destructor.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/dbwrap/dbwrap_watch.c

index 4ad09b3543eab33df6878678cf42da43f036de71..bad34686f118175c1bcab35691e745cf0caf4331 100644 (file)
@@ -324,7 +324,7 @@ static void dbwrap_watched_add_watcher(
        state->status = dbwrap_record_storev(rec, dbufs, ARRAY_SIZE(dbufs), 0);
 }
 
-static int db_watched_record_destructor(struct db_watched_record *wrec)
+static void db_watched_record_fini(struct db_watched_record *wrec)
 {
        struct dbwrap_watched_add_watcher_state state = { .w = wrec->added };
        struct db_context *backend = dbwrap_record_get_db(wrec->backend.rec);
@@ -332,7 +332,7 @@ static int db_watched_record_destructor(struct db_watched_record *wrec)
        NTSTATUS status;
 
        if (wrec->added.pid.pid == 0) {
-               return 0;
+               return;
        }
 
        status = dbwrap_do_locked(
@@ -340,13 +340,20 @@ static int db_watched_record_destructor(struct db_watched_record *wrec)
        if (!NT_STATUS_IS_OK(status)) {
                DBG_WARNING("dbwrap_do_locked failed: %s\n",
                            nt_errstr(status));
-               return 0;
+               return;
        }
        if (!NT_STATUS_IS_OK(state.status)) {
                DBG_WARNING("dbwrap_watched_add_watcher failed: %s\n",
                            nt_errstr(state.status));
-               return 0;
+               return;
        }
+
+       return;
+}
+
+static int db_watched_record_destructor(struct db_watched_record *wrec)
+{
+       db_watched_record_fini(wrec);
        return 0;
 }
 
@@ -386,7 +393,7 @@ static void dbwrap_watched_do_locked_fn(
 
        state->fn(&rec, rec.value, state->private_data);
 
-       db_watched_record_destructor(&wrec);
+       db_watched_record_fini(&wrec);
 }
 
 static NTSTATUS dbwrap_watched_do_locked(struct db_context *db, TDB_DATA key,