ctdb-tests: Add explicit wait to the fork_helper()
authorAmitay Isaacs <amitay@gmail.com>
Thu, 28 Jul 2016 06:21:44 +0000 (16:21 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 8 Aug 2016 06:17:33 +0000 (08:17 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12109

To create a client process that waits after connect(), instead of trying
to do a blocking write(), go to sleep.  The parent can then kill the client
process, once testing is done.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/src/porting_tests.c

index c9562876771e38abd5a56bb5674cee6953619a22..146218f2761f1e4f18931e0152d4f1727957f1d5 100644 (file)
@@ -132,16 +132,6 @@ static int socket_client_connect(void)
        return client;
 }
 
-static int socket_client_write(int client)
-{
-       int ret;
-
-       ret = sys_write(client, "\0", 1);
-       assert(ret == 1);
-
-       return 0;
-}
-
 static int socket_client_close(int client)
 {
        int ret;
@@ -164,8 +154,11 @@ static int fork_helper(void)
        assert(pid != -1);
 
        if (pid == 0) { // Child
+               pid = getppid();
                client = socket_client_connect();
-               socket_client_write(client);
+               while (kill(pid, 0) == 0) {
+                       sleep(1);
+               }
                socket_client_close(client);
                exit(0);
        } else {
@@ -204,6 +197,8 @@ static int test_ctdb_get_peer_pid(void)
 
        assert(peer_pid == globals.helper_pid);
 
+       kill(peer_pid, SIGTERM);
+
        close(fd);
        return 0;
 }