dbwrap_watch: Test cleanup of dead watchers
authorVolker Lendecke <vl@samba.org>
Tue, 15 Oct 2019 08:55:25 +0000 (10:55 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 18 Oct 2019 21:06:33 +0000 (21:06 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_dbwrap_watch.c
source3/torture/torture.c

index 82259dcfe907a6f71db6b61cf56a0cccf15e9c2c..7842a78328df082938020d30b6be3b123d1b87e1 100644 (file)
@@ -16,6 +16,7 @@
 ^samba3.smbtorture_s3.crypt_server # expected to give ACCESS_DENIED as SMB1 encryption isn't used
 ^samba3.smbtorture_s3.*.LOCK12.*\(fileserver\)
 ^samba3.smbtorture_s3.*.LOCK12.*\(nt4_dc\)
+^samba3.smbtorture_s3.LOCAL-DBWRAP-WATCH3
 ^samba3.nbt.dgram.*netlogon2\(nt4_dc\)
 ^samba3.*rap.sam.*.useradd # Not provided by Samba 3
 ^samba3.*rap.sam.*.userdelete # Not provided by Samba 3
index 7b600ec64a24025dabcdc18dfbc09f0c21f340cb..a7b098d6518c2c9a9ab53d903f38032dba2a145d 100755 (executable)
@@ -213,6 +213,7 @@ local_tests = [
     "LOCAL-CANONICALIZE-PATH",
     "LOCAL-DBWRAP-WATCH1",
     "LOCAL-DBWRAP-WATCH2",
+    "LOCAL-DBWRAP-WATCH3",
     "LOCAL-DBWRAP-DO-LOCKED1",
     "LOCAL-G-LOCK1",
     "LOCAL-G-LOCK2",
index 578d784b4100f6359ec0454af451264cd1f1869a..f1896d5624ee4576175a0be5c2ca908a9ab7410e 100644 (file)
@@ -113,6 +113,7 @@ bool run_notify_bench2(int dummy);
 bool run_notify_bench3(int dummy);
 bool run_dbwrap_watch1(int dummy);
 bool run_dbwrap_watch2(int dummy);
+bool run_dbwrap_watch3(int dummy);
 bool run_dbwrap_do_locked1(int dummy);
 bool run_idmap_tdb_common_test(int dummy);
 bool run_local_dbwrap_ctdb(int dummy);
index 5ef6b105ca2ae229069e8ae663c50cdcd473e4ca..cdfd81175221aa6e81bbaaf906178c3b89feb578 100644 (file)
@@ -175,3 +175,106 @@ fail:
        TALLOC_FREE(ev);
        return ret;
 }
+
+/*
+ * Test autocleanup of dead watchers
+ */
+
+bool run_dbwrap_watch3(int dummy)
+{
+       struct tevent_context *ev = NULL;
+       struct messaging_context *msg = NULL;
+       struct db_context *backend = NULL;
+       struct db_context *db = NULL;
+       const char *keystr = "key";
+       TDB_DATA key = string_term_tdb_data(keystr);
+       NTSTATUS status;
+       bool ret = false;
+       pid_t child, waited;
+       int wstatus, exit_status;
+
+       BlockSignals(true, SIGCHLD);
+
+       child = fork();
+       if (child == -1) {
+               fprintf(stderr,
+                       "fork failed: %s\n",
+                       strerror(errno));
+               goto fail;
+       }
+
+       ev = samba_tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               fprintf(stderr, "tevent_context_init failed\n");
+               goto fail;
+       }
+       msg = messaging_init(ev, ev);
+       if (msg == NULL) {
+               fprintf(stderr, "messaging_init failed\n");
+               goto fail;
+       }
+       backend = db_open(msg, "test_watch.tdb", 0, TDB_CLEAR_IF_FIRST,
+                         O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1,
+                         DBWRAP_FLAG_NONE);
+       if (backend == NULL) {
+               fprintf(stderr, "db_open failed: %s\n", strerror(errno));
+               goto fail;
+       }
+
+       db = db_open_watched(ev, &backend, msg);
+       if (db == NULL) {
+               fprintf(stderr, "db_open_watched failed\n");
+               goto fail;
+       }
+
+       if (child == 0) {
+               struct db_record *rec = dbwrap_fetch_locked(db, db, key);
+               struct tevent_req *req = NULL;
+
+               if (rec == NULL) {
+                       fprintf(stderr, "dbwrap_fetch_locked failed\n");
+                       exit(1);
+               }
+
+               req = dbwrap_watched_watch_send(
+                       db, ev, rec, (struct server_id) { 0 });
+               if (req == NULL) {
+                       fprintf(stderr, "dbwrap_watched_watch_send failed\n");
+                       exit(2);
+               }
+
+               exit(0);
+       }
+
+       waited = waitpid(child, &wstatus, 0);
+       if (waited == -1) {
+               fprintf(stderr, "waitpid failed: %s\n", strerror(errno));
+               goto fail;
+       }
+       if (!WIFEXITED(wstatus)) {
+               fprintf(stderr, "child did not exit normally\n");
+               goto fail;
+       }
+
+       exit_status = WEXITSTATUS(wstatus);
+       if (exit_status != 0) {
+               fprintf(stderr, "exit status is %d\n", exit_status);
+               goto fail;
+       }
+
+       status = dbwrap_store_uint32_bystring(db, keystr, 1);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
+               fprintf(stderr,
+                       "dbwrap_store_uint32 returned %s\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       (void)unlink("test_watch.tdb");
+       ret = true;
+fail:
+       TALLOC_FREE(db);
+       TALLOC_FREE(msg);
+       TALLOC_FREE(ev);
+       return ret;
+}
index e498c162f11d3114823e5ba17cafaca8dde175aa..bfc2a2e24c95b6f498918b19e92c6c30418e741b 100644 (file)
@@ -14663,6 +14663,10 @@ static struct {
                .name  = "LOCAL-DBWRAP-WATCH2",
                .fn    = run_dbwrap_watch2,
        },
+       {
+               .name  = "LOCAL-DBWRAP-WATCH3",
+               .fn    = run_dbwrap_watch3,
+       },
        {
                .name  = "LOCAL-DBWRAP-DO-LOCKED1",
                .fn    = run_dbwrap_do_locked1,