TALLOC_FREE(ev);
return ret;
}
+
+struct lock2_parser_state {
+ uint8_t *rdata;
+ bool ok;
+};
+
+static void lock2_parser(const struct g_lock_rec *locks,
+ size_t num_locks,
+ const uint8_t *data,
+ size_t datalen,
+ void *private_data)
+{
+ struct lock2_parser_state *state = private_data;
+
+ if (datalen != sizeof(uint8_t)) {
+ return;
+ }
+ *state->rdata = *data;
+ state->ok = true;
+}
+
+/*
+ * Test g_lock_write_data
+ */
+
+bool run_g_lock2(int dummy)
+{
+ struct tevent_context *ev = NULL;
+ struct messaging_context *msg = NULL;
+ struct g_lock_ctx *ctx = NULL;
+ const char *lockname = "lock2";
+ uint8_t data = 42;
+ uint8_t rdata;
+ struct lock2_parser_state state = { .rdata = &rdata };
+ NTSTATUS status;
+ bool ret = false;
+ bool ok;
+
+ ok = get_g_lock_ctx(talloc_tos(), &ev, &msg, &ctx);
+ if (!ok) {
+ goto fail;
+ }
+
+ status = g_lock_write_data(ctx, lockname, &data, sizeof(data));
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_LOCKED)) {
+ fprintf(stderr, "unlocked g_lock_write_data returned %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+ (struct timeval) { .tv_sec = 1 });
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_lock returned %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_write_data(ctx, lockname, &data, sizeof(data));
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_write_data failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_unlock(ctx, lockname);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_unlock failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = g_lock_dump(ctx, lockname, lock2_parser, &state);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "g_lock_dump failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ if (!state.ok) {
+ fprintf(stderr, "Could not parse data\n");
+ goto fail;
+ }
+ if (rdata != data) {
+ fprintf(stderr, "Returned %"PRIu8", expected %"PRIu8"\n",
+ rdata, data);
+ goto fail;
+ }
+
+ ret = true;
+fail:
+ TALLOC_FREE(ctx);
+ TALLOC_FREE(msg);
+ TALLOC_FREE(ev);
+ return ret;
+}
{ "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 },
{ "LOCAL-PTHREADPOOL-TEVENT", run_pthreadpool_tevent, 0 },
{ "LOCAL-G-LOCK1", run_g_lock1, 0 },
+ { "LOCAL-G-LOCK2", run_g_lock2, 0 },
{ "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
{ "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
{NULL, NULL, 0}};