From e1e14420a63bf766fdd05a1560dfe09f7cda4df6 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 27 May 2016 12:52:12 +1000 Subject: [PATCH] ctdb-tests: Re-use set_blocking instead of re-definition Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/comm.c | 19 ++++--------------- ctdb/tests/src/pkt_read_test.c | 19 ++++--------------- ctdb/tests/src/pkt_write_test.c | 19 ++++--------------- ctdb/wscript | 3 ++- 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/ctdb/common/comm.c b/ctdb/common/comm.c index 1bbb46050b5..7f370da9b8f 100644 --- a/ctdb/common/comm.c +++ b/ctdb/common/comm.c @@ -24,26 +24,13 @@ #include #include +#include "lib/util/blocking.h" #include "lib/util/tevent_unix.h" #include "pkt_read.h" #include "pkt_write.h" #include "comm.h" -static bool set_nonblocking(int fd) -{ - int v; - - v = fcntl(fd, F_GETFL, 0); - if (v == -1) { - return false; - } - if (fcntl(fd, F_SETFL, v | O_NONBLOCK) == -1) { - return false; - } - return true; -} - /* * Communication endpoint around a socket */ @@ -78,6 +65,7 @@ int comm_setup(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, struct comm_context **result) { struct comm_context *comm; + int ret; if (fd < 0) { return EINVAL; @@ -88,7 +76,8 @@ int comm_setup(TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd, } /* Socket queue relies on non-blocking sockets. */ - if (!set_nonblocking(fd)) { + ret = set_blocking(fd, false); + if (ret == -1) { return EIO; } diff --git a/ctdb/tests/src/pkt_read_test.c b/ctdb/tests/src/pkt_read_test.c index 2e4d37934aa..a3ebe0af8f8 100644 --- a/ctdb/tests/src/pkt_read_test.c +++ b/ctdb/tests/src/pkt_read_test.c @@ -22,6 +22,8 @@ #include +#include "lib/util/blocking.h" + #include "common/pkt_read.c" static void writer(int fd) @@ -210,20 +212,6 @@ static void reader(int fd, bool fixed) talloc_free(mem_ctx); } -static bool set_nonblocking(int fd) -{ - int v; - - v = fcntl(fd, F_GETFL, 0); - if (v == -1) { - return false; - } - if (fcntl(fd, F_SETFL, v | O_NONBLOCK) == -1) { - return false; - } - return true; -} - static void reader_test(bool fixed) { int fd[2]; @@ -244,7 +232,8 @@ static void reader_test(bool fixed) } close(fd[1]); - if (!set_nonblocking(fd[0])) { + ret = set_blocking(fd[0], false); + if (ret == -1) { exit(1); } diff --git a/ctdb/tests/src/pkt_write_test.c b/ctdb/tests/src/pkt_write_test.c index 191e8b3e894..3872670880d 100644 --- a/ctdb/tests/src/pkt_write_test.c +++ b/ctdb/tests/src/pkt_write_test.c @@ -22,6 +22,8 @@ #include +#include "lib/util/blocking.h" + #include "common/pkt_read.c" #include "common/pkt_write.c" @@ -326,20 +328,6 @@ static void reader(int fd) talloc_free(mem_ctx); } -static bool set_nonblocking(int fd) -{ - int v; - - v = fcntl(fd, F_GETFL, 0); - if (v == -1) { - return false; - } - if (fcntl(fd, F_SETFL, v | O_NONBLOCK) == -1) { - return false; - } - return true; -} - int main(void) { int fd[2]; @@ -360,7 +348,8 @@ int main(void) } close(fd[1]); - if (!set_nonblocking(fd[0])) { + ret = set_blocking(fd[0], false); + if (ret == -1) { exit(1); } diff --git a/ctdb/wscript b/ctdb/wscript index 44c376db65b..6a411dadb44 100755 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -656,7 +656,8 @@ def build(bld): bld.SAMBA_BINARY(target, source=src, - deps='talloc tevent tdb tevent-util LIBASYNC_REQ', + deps='''talloc tevent tdb tevent-util + LIBASYNC_REQ samba-util''', install_path='${CTDB_TEST_LIBDIR}') bld.SAMBA_BINARY('reqid_test', -- 2.34.1