From aeba27d3a48fc4bbe06cf2f0d646711f7fb86d31 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 18 Jul 2018 19:00:42 +1000 Subject: ctdb-common: Add fd argument to ctdb_connection_list_read() This makes testing easier. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke (cherry picked from commit 3bf753e830c20183ef4f3278880d3be362e53bef) --- ctdb/protocol/protocol_util.c | 6 ++++-- ctdb/protocol/protocol_util.h | 4 +++- ctdb/tests/src/protocol_util_test.c | 18 ++++++------------ ctdb/tools/ctdb.c | 6 +++--- ctdb/tools/ctdb_killtcp.c | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'ctdb') diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 45c639d747f..77e79867443 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -640,7 +640,9 @@ static int ctdb_connection_list_read_line(char *line, void *private_data) return 0; } -int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, +int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, + int fd, + bool client_first, struct ctdb_connection_list **conn_list) { struct ctdb_connection_list_read_state state; @@ -657,7 +659,7 @@ int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, state.client_first = client_first; - ret = line_read(0, + ret = line_read(fd, 128, mem_ctx, ctdb_connection_list_read_line, diff --git a/ctdb/protocol/protocol_util.h b/ctdb/protocol/protocol_util.h index 66a49136576..347fe8a275a 100644 --- a/ctdb/protocol/protocol_util.h +++ b/ctdb/protocol/protocol_util.h @@ -66,7 +66,9 @@ int ctdb_connection_list_sort(struct ctdb_connection_list *conn_list); const char *ctdb_connection_list_to_string( TALLOC_CTX *mem_ctx, struct ctdb_connection_list *conn_list, bool client_first); -int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, bool client_first, +int ctdb_connection_list_read(TALLOC_CTX *mem_ctx, + int fd, + bool client_first, struct ctdb_connection_list **conn_list); #endif /* __CTDB_PROTOCOL_UTIL_H__ */ diff --git a/ctdb/tests/src/protocol_util_test.c b/ctdb/tests/src/protocol_util_test.c index eb7eb0ff88f..5608b13920c 100644 --- a/ctdb/tests/src/protocol_util_test.c +++ b/ctdb/tests/src/protocol_util_test.c @@ -153,7 +153,7 @@ static void test_connection_list_read(const char *s1, const char *s2) TALLOC_CTX *tmp_ctx; int pipefd[2]; pid_t pid; - struct ctdb_connection_list *conn_list; + struct ctdb_connection_list *conn_list = NULL; const char *t; int ret; @@ -182,14 +182,11 @@ static void test_connection_list_read(const char *s1, const char *s2) close(pipefd[1]); - ret = dup2(pipefd[0], STDIN_FILENO); - assert(ret != -1); + ret = ctdb_connection_list_read(tmp_ctx, pipefd[0], false, &conn_list); + assert(ret == 0); close(pipefd[0]); - ret = ctdb_connection_list_read(tmp_ctx, false, &conn_list); - assert(ret == 0); - ret = ctdb_connection_list_sort(conn_list); assert(ret == 0); @@ -206,7 +203,7 @@ static void test_connection_list_read_bad(const char *s1) TALLOC_CTX *tmp_ctx; int pipefd[2]; pid_t pid; - struct ctdb_connection_list *conn_list; + struct ctdb_connection_list *conn_list = NULL; int ret; tmp_ctx = talloc_new(NULL); @@ -234,14 +231,11 @@ static void test_connection_list_read_bad(const char *s1) close(pipefd[1]); - ret = dup2(pipefd[0], STDIN_FILENO); - assert(ret != -1); + ret = ctdb_connection_list_read(tmp_ctx, pipefd[0], false, &conn_list); + assert(ret == EINVAL); close(pipefd[0]); - ret = ctdb_connection_list_read(tmp_ctx, false, &conn_list); - assert(ret == EINVAL); - talloc_free(tmp_ctx); } diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index 2cb46b057f0..a6f8f2904dd 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -3023,7 +3023,7 @@ static int control_tickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, int i, num_failed; /* Client first but the src/dst logic is confused */ - ret = ctdb_connection_list_read(mem_ctx, false, &clist); + ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist); if (ret != 0) { return ret; } @@ -3241,7 +3241,7 @@ static int control_addtickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, struct tevent_req *req; /* Client first but the src/dst logic is confused */ - ret = ctdb_connection_list_read(mem_ctx, false, &clist); + ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist); if (ret != 0) { return ret; } @@ -3306,7 +3306,7 @@ static int control_deltickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb, struct tevent_req *req; /* Client first but the src/dst logic is confused */ - ret = ctdb_connection_list_read(mem_ctx, false, &clist); + ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist); if (ret != 0) { return ret; } diff --git a/ctdb/tools/ctdb_killtcp.c b/ctdb/tools/ctdb_killtcp.c index da497d21d57..b35331d02ed 100644 --- a/ctdb/tools/ctdb_killtcp.c +++ b/ctdb/tools/ctdb_killtcp.c @@ -372,7 +372,7 @@ int main(int argc, char **argv) goto fail; } } else { - ret = ctdb_connection_list_read(mem_ctx, true, &conn_list); + ret = ctdb_connection_list_read(mem_ctx, 0, true, &conn_list); if (ret != 0) { D_ERR("Unable to parse connections (%s)\n", strerror(ret)); -- cgit v1.2.1