1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

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 <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2018-07-18 19:00:42 +10:00 committed by Martin Schwenke
parent c9b42d27e6
commit 3bf753e830
5 changed files with 17 additions and 19 deletions

View 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,

View 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__ */

View 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);
}

View 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;
}

View 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));