ctdb-common: Add fd argument to ctdb_connection_list_read()
authorAmitay Isaacs <amitay@gmail.com>
Wed, 18 Jul 2018 09:00:42 +0000 (19:00 +1000)
committerKarolin Seeger <kseeger@samba.org>
Tue, 26 Mar 2019 07:49:18 +0000 (07:49 +0000)
This makes testing easier.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13520

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
(cherry picked from commit 3bf753e830c20183ef4f3278880d3be362e53bef)

ctdb/protocol/protocol_util.c
ctdb/protocol/protocol_util.h
ctdb/tests/src/protocol_util_test.c
ctdb/tools/ctdb.c
ctdb/tools/ctdb_killtcp.c

index 45c639d747f2f4b0af01ed564fe5b2f604fb4437..77e798674439fcde3ecd9803dbf5a44a1de4cb80 100644 (file)
@@ -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,
index 66a491365764ac76529f34abd6cd2d85730fb854..347fe8a275a452d6dc6d7d57d4c40bbdc7612001 100644 (file)
@@ -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__ */
index eb7eb0ff88f17a8b01cdeeecbd374aaad359ed22..5608b13920ca173359b225a74266b49a7227d7c7 100644 (file)
@@ -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);
 }
 
index 2cb46b057f00a790b85c9457b2299b615a821f11..a6f8f2904ddbfa9ee04920fc20fb73fd79239ea0 100644 (file)
@@ -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;
                }
index da497d21d57fcfeb9499ff824c70467250dde239..b35331d02edaf6e645508eeccb406de4a711bb75 100644 (file)
@@ -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));