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>
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;
state.client_first = client_first;
- ret = line_read(0,
+ ret = line_read(fd,
128,
mem_ctx,
ctdb_connection_list_read_line,
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__ */
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;
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);
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);
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);
}
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;
}
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;
}
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;
}
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));