torture: Check the return code of kill().
authorAndreas Schneider <asn@samba.org>
Thu, 2 Oct 2014 04:28:10 +0000 (06:28 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 20 Oct 2014 14:48:21 +0000 (16:48 +0200)
CID #73654

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
tests/torture.c

index 02ddc963c59a09327c7febe5aa37c55d8a5ae0af..eab36de9c1a366e0e88b7cbbe4f63cdcf9bbc57b 100644 (file)
@@ -48,6 +48,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
+#include <stdbool.h>
 
 #define TORTURE_ECHO_SRV_IPV4 "127.0.0.10"
 /* socket wrapper IPv6 prefix  fd00::5357:5fxx */
@@ -259,6 +260,8 @@ void torture_teardown_echo_srv(void **state)
        ssize_t rc;
        pid_t pid;
        int fd;
+       bool is_running = true;
+       int count;
 
        /* read the pidfile */
        fd = open(s->srv_pidfile, O_RDONLY);
@@ -281,11 +284,20 @@ void torture_teardown_echo_srv(void **state)
 
        pid = (pid_t)(tmp & 0xFFFF);
 
-       /* Make sure the daemon goes away! */
-       kill(pid, SIGTERM);
+       for (count = 0; count < 10; count++) {
+               /* Make sure the daemon goes away! */
+               kill(pid, SIGTERM);
 
-       kill(pid, 0);
-       if (rc == 0) {
+               usleep(200);
+
+               rc = kill(pid, 0);
+               if (rc != 0) {
+                       is_running = false;
+                       break;
+               }
+       }
+
+       if (is_running) {
                fprintf(stderr,
                        "WARNING the echo server is still running!\n");
        }