diff options
author | Amitay Isaacs <amitay@gmail.com> | 2017-11-17 13:11:12 +1100 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-11-21 05:03:17 +0100 |
commit | ba3e9e6eae62af0ee991945206e0ef2b3dba8acf (patch) | |
tree | 0216a557bbdf71eeb0a9e4c8063f93ff1e89d8f8 /ctdb | |
parent | 3b8f0cc21dd18e84ee78d0450d6f89435abf8dc1 (diff) | |
download | samba-ba3e9e6eae62af0ee991945206e0ef2b3dba8acf.tar.gz |
ctdb-tests: Create sock_daemon_funcs per test
This avoids defining sock_daemon functions that are not needed in the test.
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/tests/src/sock_daemon_test.c | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/ctdb/tests/src/sock_daemon_test.c b/ctdb/tests/src/sock_daemon_test.c index df86a73150a..d224ce85dc3 100644 --- a/ctdb/tests/src/sock_daemon_test.c +++ b/ctdb/tests/src/sock_daemon_test.c @@ -205,12 +205,6 @@ static void test2_shutdown(void *private_data) assert(nwritten == sizeof(ret)); } -static struct sock_daemon_funcs test2_funcs = { - .startup = test2_startup, - .reconfigure = test2_reconfigure, - .shutdown = test2_shutdown, -}; - static void test2(TALLOC_CTX *mem_ctx, const char *pidfile, const char *sockpath) { @@ -231,6 +225,11 @@ static void test2(TALLOC_CTX *mem_ctx, const char *pidfile, if (pid == 0) { struct tevent_context *ev; struct sock_daemon_context *sockd; + struct sock_daemon_funcs test2_funcs = { + .startup = test2_startup, + .reconfigure = test2_reconfigure, + .shutdown = test2_shutdown, + }; close(fd[0]); @@ -1091,6 +1090,7 @@ static void test6(TALLOC_CTX *mem_ctx, const char *pidfile, static void test7(TALLOC_CTX *mem_ctx, const char *pidfile, const char *sockpath) { + struct sock_daemon_funcs test7_funcs; struct stat st; int fd[2]; pid_t pid, pid2; @@ -1099,6 +1099,13 @@ static void test7(TALLOC_CTX *mem_ctx, const char *pidfile, struct sock_daemon_context *sockd; ssize_t n; + /* Reuse test2 funcs for the startup synchronisation */ + test7_funcs = (struct sock_daemon_funcs) { + .startup = test2_startup, + .reconfigure = test2_reconfigure, + .shutdown = test2_shutdown, + }; + ret = pipe(fd); assert(ret == 0); @@ -1111,9 +1118,8 @@ static void test7(TALLOC_CTX *mem_ctx, const char *pidfile, ev = tevent_context_init(mem_ctx); assert(ev != NULL); - /* Reuse test2 funcs for the startup synchronisation */ ret = sock_daemon_setup(mem_ctx, "test7", "file:", "NOTICE", - &test2_funcs, &fd[1], &sockd); + &test7_funcs, &fd[1], &sockd); assert(ret == 0); ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1); @@ -1135,9 +1141,8 @@ static void test7(TALLOC_CTX *mem_ctx, const char *pidfile, ev = tevent_context_init(mem_ctx); assert(ev != NULL); - /* Reuse test2 funcs for the startup synchronisation */ ret = sock_daemon_setup(mem_ctx, "test7-parent", "file:", "NOTICE", - &test2_funcs, &fd[1], &sockd); + &test7_funcs, &fd[1], &sockd); assert(ret == 0); ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1); @@ -1180,14 +1185,18 @@ static void test8(TALLOC_CTX *mem_ctx, const char *pidfile, assert(pid != -1); if (pid == 0) { + /* Reuse test2 funcs for the startup synchronisation */ + struct sock_daemon_funcs test8_funcs = { + .startup = test2_startup, + }; + close(fd[0]); ev = tevent_context_init(mem_ctx); assert(ev != NULL); - /* Reuse test2 funcs for the startup synchronisation */ ret = sock_daemon_setup(mem_ctx, "test8", "file:", "NOTICE", - &test2_funcs, &fd[1], &sockd); + &test8_funcs, &fd[1], &sockd); assert(ret == 0); ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1); @@ -1209,10 +1218,6 @@ static void test8(TALLOC_CTX *mem_ctx, const char *pidfile, ret = kill(pid, SIGTERM); assert(ret == 0); - n = read(fd[0], &ret, sizeof(ret)); - assert(n == sizeof(ret)); - assert(ret == 3); - pid2 = waitpid(pid, &ret, 0); assert(pid2 == pid); assert(WEXITSTATUS(ret) == 0); @@ -1226,14 +1231,18 @@ static void test8(TALLOC_CTX *mem_ctx, const char *pidfile, assert(pid != -1); if (pid == 0) { + /* Reuse test2 funcs for the startup synchronisation */ + struct sock_daemon_funcs test8_funcs = { + .startup = test2_startup, + }; + close(fd[0]); ev = tevent_context_init(mem_ctx); assert(ev != NULL); - /* Reuse test2 funcs for the startup synchronisation */ ret = sock_daemon_setup(mem_ctx, "test8", "file:", "NOTICE", - &test2_funcs, &fd[1], &sockd); + &test8_funcs, &fd[1], &sockd); assert(ret == 0); ret = sock_daemon_run(ev, sockd, pidfile, false, true, -1); @@ -1255,10 +1264,6 @@ static void test8(TALLOC_CTX *mem_ctx, const char *pidfile, ret = kill(pid, SIGTERM); assert(ret == 0); - n = read(fd[0], &ret, sizeof(ret)); - assert(n == sizeof(ret)); - assert(ret == 3); - pid2 = waitpid(pid, &ret, 0); assert(pid2 == pid); assert(WEXITSTATUS(ret) == 0); @@ -1292,14 +1297,18 @@ static void test9(TALLOC_CTX *mem_ctx, const char *pidfile, assert(pid != -1); if (pid == 0) { + /* Reuse test2 funcs for the startup synchronisation */ + struct sock_daemon_funcs test9_funcs = { + .startup = test2_startup, + }; + close(fd[0]); ev = tevent_context_init(mem_ctx); assert(ev != NULL); - /* Reuse test2 funcs for the startup synchronisation */ ret = sock_daemon_setup(mem_ctx, "test9", "file:", "NOTICE", - &test2_funcs, &fd[1], &sockd); + &test9_funcs, &fd[1], &sockd); assert(ret == 0); ret = sock_daemon_run(ev, sockd, pidfile, false, false, -1); @@ -1321,10 +1330,6 @@ static void test9(TALLOC_CTX *mem_ctx, const char *pidfile, ret = kill(pid, SIGTERM); assert(ret == 0); - n = read(fd[0], &ret, sizeof(ret)); - assert(n == sizeof(ret)); - assert(ret == 3); - pid2 = waitpid(pid, &ret, 0); assert(pid2 == pid); assert(WEXITSTATUS(ret) == 0); @@ -1338,14 +1343,19 @@ static void test9(TALLOC_CTX *mem_ctx, const char *pidfile, assert(pid != -1); if (pid == 0) { + /* Reuse test2 funcs for the startup synchronisation */ + struct sock_daemon_funcs test9_funcs = { + .startup = test2_startup, + .shutdown = test2_shutdown, + }; + close(fd[0]); ev = tevent_context_init(mem_ctx); assert(ev != NULL); - /* Reuse test2 funcs for the startup synchronisation */ ret = sock_daemon_setup(mem_ctx, "test9", "file:", "NOTICE", - &test2_funcs, &fd[1], &sockd); + &test9_funcs, &fd[1], &sockd); assert(ret == 0); ret = sock_daemon_run(ev, sockd, pidfile, true, false, -1); |