ctdb-tests: Make sure child processes are waited on after termination
authorAmitay Isaacs <amitay@gmail.com>
Wed, 22 Nov 2017 00:08:14 +0000 (11:08 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 24 Nov 2017 10:49:19 +0000 (11:49 +0100)
Looks like the if a process holding fcntl lock (on pid file) is killed,
then the lock is not released till the process is reaped using either
wait() or waitpid().

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

index 505ff78e768582dcbb3e9e90c2f77d6cacae457a..5641d37bcd1d9410d8121b3035e9a32481bf9c0c 100644 (file)
@@ -984,6 +984,10 @@ static void test5(TALLOC_CTX *mem_ctx, const char *pidfile,
 
        ret = kill(pid_server, SIGTERM);
        assert(ret == 0);
+
+       pid = waitpid(pid_server, &ret, 0);
+       assert(pid == pid_server);
+       assert(WEXITSTATUS(ret) == 0);
 }
 
 /*
@@ -1272,8 +1276,9 @@ static void test6(TALLOC_CTX *mem_ctx, const char *pidfile,
 
        test6_client(sockpath);
 
-       pid = wait(&ret);
-       assert(pid != -1);
+       pid = waitpid(pid_server, &ret, 0);
+       assert(pid == pid_server);
+       assert(WEXITSTATUS(ret) == 0);
 }
 
 /*
@@ -1731,6 +1736,10 @@ static void test10(TALLOC_CTX *mem_ctx, const char *pidfile,
        ret = kill (pid, SIGKILL);
        assert(ret == 0);
 
+       pid2 = waitpid(pid, &ret, 0);
+       assert(pid2 == pid);
+       assert(WEXITSTATUS(ret) == 0);
+
        ret = stat(sockpath, &st);
        assert(ret == 0);