From: Stefan Metzmacher Date: Thu, 30 Jun 2022 12:05:43 +0000 (+0200) Subject: s3:dbwrap_watch: split out a dbwrap_watched_watch_add_instance() helper X-Git-Tag: ldb-2.6.1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b173bf1569b4c099223a090f021465eee04747e;p=thirdparty%2Fsamba.git s3:dbwrap_watch: split out a dbwrap_watched_watch_add_instance() helper This will be used in other places soon. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c index 2615c2f5148..6fbf305f0a5 100644 --- a/source3/lib/dbwrap/dbwrap_watch.c +++ b/source3/lib/dbwrap/dbwrap_watch.c @@ -810,6 +810,21 @@ struct db_context *db_open_watched(TALLOC_CTX *mem_ctx, return db; } +static uint64_t dbwrap_watched_watch_add_instance(struct db_record *rec) +{ + struct db_watched_record *wrec = db_record_get_watched_record(rec); + static uint64_t global_instance = 1; + + SMB_ASSERT(wrec->added.instance == 0); + + wrec->added = (struct dbwrap_watcher) { + .pid = wrec->self, + .instance = global_instance++, + }; + + return wrec->added.instance; +} + struct dbwrap_watched_watch_state { struct db_context *db; TDB_DATA key; @@ -836,8 +851,7 @@ struct tevent_req *dbwrap_watched_watch_send(TALLOC_CTX *mem_ctx, struct db_watched_record *wrec = db_record_get_watched_record(rec); struct tevent_req *req, *subreq; struct dbwrap_watched_watch_state *state; - - static uint64_t instance = 1; + uint64_t instance; req = tevent_req_create(mem_ctx, &state, struct dbwrap_watched_watch_state); @@ -852,16 +866,20 @@ struct tevent_req *dbwrap_watched_watch_send(TALLOC_CTX *mem_ctx, return tevent_req_post(req, ev); } - if (wrec->added.pid.pid != 0) { + if (wrec->added.instance == 0) { + /* + * Adding a new instance + */ + instance = dbwrap_watched_watch_add_instance(rec); + } else { tevent_req_nterror(req, NT_STATUS_REQUEST_NOT_ACCEPTED); return tevent_req_post(req, ev); } state->watcher = (struct dbwrap_watcher) { .pid = messaging_server_id(ctx->msg), - .instance = instance++, + .instance = instance, }; - wrec->added = state->watcher; state->key = tdb_data_talloc_copy(state, rec->key); if (tevent_req_nomem(state->key.dptr, req)) {