ctdb-tests: Re-use set_blocking instead of re-definition
authorAmitay Isaacs <amitay@gmail.com>
Fri, 27 May 2016 02:52:12 +0000 (12:52 +1000)
committerAmitay Isaacs <amitay@samba.org>
Wed, 8 Jun 2016 08:33:19 +0000 (10:33 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/common/comm.c
ctdb/tests/src/pkt_read_test.c
ctdb/tests/src/pkt_write_test.c
ctdb/wscript

index 1bbb46050b5ae878bf926f7e4204e4e8130b4e85..7f370da9b8f1ec9873319f28cb5134da6b0323ae 100644 (file)
 #include <talloc.h>
 #include <tdb.h>
 
+#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;
        }
 
index 2e4d37934aaebda735d8c44b09230870e7e23db5..a3ebe0af8f8f6945001014e4070dafa755383999 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <assert.h>
 
+#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);
        }
 
index 191e8b3e8947c27f39a38ba8e20382bf8e70268e..3872670880dc9b3f2a048ed6dbf0c6f0fb95da66 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <assert.h>
 
+#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);
        }
 
index 44c376db65b8603e1ad1e147272060c9969a6d0b..6a411dadb443166af9a320c095ab03c8681c7e6b 100755 (executable)
@@ -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',