diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-18 22:30:28 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-19 05:38:06 +0200 |
commit | 8a7c535db1f40a0f7c43d4e36227ad172bf6a654 (patch) | |
tree | cbde1eebf6f28c9e77338294fc2c63a5fb3e44ac /lib/ntdb | |
parent | d48f6f884b2789828bb183249faf3918ec4e363a (diff) | |
download | samba-8a7c535db1f40a0f7c43d4e36227ad172bf6a654.tar.gz samba-8a7c535db1f40a0f7c43d4e36227ad172bf6a654.tar.bz2 samba-8a7c535db1f40a0f7c43d4e36227ad172bf6a654.zip |
ntdb: make fork test more thorough.
We document that the child of a fork() can do a brunlock() if the parent
does a brlock: we should not log an error when they do this.
Also, test the case where we fork() and return inside a parse function
(which is allowed).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb')
-rw-r--r-- | lib/ntdb/lock.c | 2 | ||||
-rw-r--r-- | lib/ntdb/test/api-fork-test.c | 36 |
2 files changed, 29 insertions, 9 deletions
diff --git a/lib/ntdb/lock.c b/lib/ntdb/lock.c index 167770d097..625a2c4934 100644 --- a/lib/ntdb/lock.c +++ b/lib/ntdb/lock.c @@ -232,7 +232,7 @@ static enum NTDB_ERROR ntdb_brunlock(struct ntdb_context *ntdb, return NTDB_SUCCESS; } - if (!check_lock_pid(ntdb, "ntdb_brunlock", true)) + if (!check_lock_pid(ntdb, "ntdb_brunlock", false)) return NTDB_ERR_LOCK; if (unlock(ntdb, rw_type, offset, len) == -1) { diff --git a/lib/ntdb/test/api-fork-test.c b/lib/ntdb/test/api-fork-test.c index 57bd686282..63003dad3a 100644 --- a/lib/ntdb/test/api-fork-test.c +++ b/lib/ntdb/test/api-fork-test.c @@ -22,12 +22,16 @@ #include <stdlib.h> #include "logging.h" +static bool am_child = false; + static enum NTDB_ERROR fork_in_parse(NTDB_DATA key, NTDB_DATA data, struct ntdb_context *ntdb) { int status; if (fork() == 0) { + am_child = true; + /* We expect this to fail. */ if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != NTDB_ERR_LOCK) exit(1); @@ -38,10 +42,7 @@ static enum NTDB_ERROR fork_in_parse(NTDB_DATA key, NTDB_DATA data, if (tap_log_messages != 2) exit(2); - ntdb_close(ntdb); - if (tap_log_messages != 2) - exit(3); - exit(0); + return NTDB_SUCCESS; } wait(&status); ok1(WIFEXITED(status) && WEXITSTATUS(status) == 0); @@ -83,11 +84,12 @@ int main(int argc, char *argv[]) if (tap_log_messages != 2) return 2; + /* Child can do this without any complaints. */ ntdb_chainunlock(ntdb, key); - if (tap_log_messages != 3) + if (tap_log_messages != 2) return 3; ntdb_close(ntdb); - if (tap_log_messages != 3) + if (tap_log_messages != 2) return 4; return 0; } @@ -107,6 +109,7 @@ int main(int argc, char *argv[]) if (tap_log_messages != 2) return 2; + /* Child can do this without any complaints. */ ntdb_unlockall(ntdb); if (tap_log_messages != 2) return 3; @@ -132,6 +135,7 @@ int main(int argc, char *argv[]) if (tap_log_messages != 2) return 2; + /* Child can do this without any complaints. */ ntdb_unlockall_read(ntdb); if (tap_log_messages != 2) return 3; @@ -148,6 +152,8 @@ int main(int argc, char *argv[]) /* If transactions is empty, noop "commit" succeeds. */ ok1(ntdb_delete(ntdb, key) == NTDB_SUCCESS); if (fork() == 0) { + int last_log_messages; + /* We expect this to fail. */ if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != NTDB_ERR_LOCK) return 1; @@ -158,11 +164,19 @@ int main(int argc, char *argv[]) if (tap_log_messages != 2) return 2; - if (ntdb_transaction_commit(ntdb) != NTDB_ERR_LOCK) + if (ntdb_transaction_prepare_commit(ntdb) + != NTDB_ERR_LOCK) return 3; + if (tap_log_messages == 2) + return 4; + last_log_messages = tap_log_messages; + /* Child can do this without any complaints. */ + ntdb_transaction_cancel(ntdb); + if (tap_log_messages != last_log_messages) + return 4; ntdb_close(ntdb); - if (tap_log_messages < 3) + if (tap_log_messages != last_log_messages) return 4; return 0; } @@ -173,6 +187,12 @@ int main(int argc, char *argv[]) ok1(ntdb_parse_record(ntdb, key, fork_in_parse, ntdb) == NTDB_SUCCESS); ntdb_close(ntdb); + if (am_child) { + /* Child can return from parse without complaints. */ + if (tap_log_messages != 2) + exit(3); + exit(0); + } ok1(tap_log_messages == 0); } return exit_status(); |