]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dbwrap_watch: Move reallocating watchers to dbwrap_watched_watch_send()
authorVolker Lendecke <vl@samba.org>
Mon, 30 Sep 2019 09:25:59 +0000 (11:25 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 2 Oct 2019 08:01:41 +0000 (08:01 +0000)
Before 15a8af075a2 we did not have a separately allocated watchers
array and dbwrap_watched_save() could play (too) smart tricks with
dbwrap_record_storev(). Now that we always have watchers talloc'ed, we
can remove those smart tricks from dbwrap_watched_save() in the next
commit.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/dbwrap/dbwrap_watch.c

index 902643ca307d06beca5157467e2c5b9d3ce976a9..ec6fc19d0ae74ba0d5f80673986eb91d099f2eb4 100644 (file)
@@ -859,6 +859,8 @@ struct tevent_req *dbwrap_watched_watch_send(TALLOC_CTX *mem_ctx,
        struct db_watched_ctx *ctx = talloc_get_type_abort(
                db->private_data, struct db_watched_ctx);
        struct db_watched_subrec *subrec = NULL;
+       struct dbwrap_watch_rec *wrec = NULL;
+       uint8_t *watchers = NULL;
        struct tevent_req *req, *subreq;
        struct dbwrap_watched_watch_state *state;
        ssize_t needed;
@@ -920,8 +922,23 @@ struct tevent_req *dbwrap_watched_watch_send(TALLOC_CTX *mem_ctx,
        }
        tevent_req_set_callback(subreq, dbwrap_watched_watch_done, req);
 
-       status = dbwrap_watched_save(subrec->subrec, &subrec->wrec, &state->me,
-                                    &subrec->wrec.data, 1, 0);
+       wrec = &subrec->wrec;
+
+       watchers = talloc_realloc(
+               NULL,
+               wrec->watchers,
+               uint8_t,
+               (wrec->num_watchers + 1) * SERVER_ID_BUF_LENGTH);
+       if (tevent_req_nomem(watchers, req)) {
+               return tevent_req_post(req, ev);
+       }
+       server_id_put(&watchers[wrec->num_watchers * SERVER_ID_BUF_LENGTH],
+                     state->me);
+       wrec->watchers = watchers;
+       wrec->num_watchers += 1;
+
+       status = dbwrap_watched_save(
+               subrec->subrec, wrec, NULL, &wrec->data, 1, 0);
        if (tevent_req_nterror(req, status)) {
                return tevent_req_post(req, ev);
        }