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)
committerMartin Schwenke <martins@samba.org>
Sat, 28 Jul 2018 01:50:11 +0000 (03:50 +0200)
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>
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 7ce19c1f79c7bb2dd102e981c2f25509c054d99c..75427e44f50fa370e45b1179296c8ec037592438 100644 (file)
@@ -679,7 +679,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;
@@ -696,7 +698,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 fa7189c22a45805f007224298400c45fce54d77e..a51cbcdda98b7f5ec4bdf34906766655060ff51a 100644 (file)
@@ -69,7 +69,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 9b4729ec5eea52aa6c3e21b4ada4ef659294ce16..178ce1d6429704c896f41ee4df826768736de336 100644 (file)
@@ -183,7 +183,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;
 
@@ -212,14 +212,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);
 
@@ -236,7 +233,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);
@@ -264,14 +261,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 771632c03a1e208e237bb83d7320ad9de5f9b34a..0652a205dbdd60311f1c6ec5c43d554d745c6fd5 100644 (file)
@@ -3029,7 +3029,7 @@ static int control_tickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                unsigned int 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;
                }
@@ -3247,7 +3247,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;
                }
@@ -3312,7 +3312,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 bd5da0834b7ba45c10fcb73cc1c8cc93935d54d6..8537a57967006fc6024167d9bb30c81a9a29ba05 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));