ctdb-tests: Add improved PID file check to test2
authorMartin Schwenke <martin@meltin.net>
Mon, 28 Aug 2017 06:00:53 +0000 (16:00 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 29 Aug 2017 09:14:09 +0000 (11:14 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/sock_daemon_test.c

index 98b9f066fc8af895201eab39ea0131f4e101b30a..988bb94e5459eb3988597895674bd71d06c7b9d1 100644 (file)
@@ -143,6 +143,8 @@ static void test2(TALLOC_CTX *mem_ctx, const char *pidfile,
        pid_t pid, pid2;
        int ret;
        ssize_t n;
+       int pidfile_fd;
+       char pidstr[20] = { 0 };
 
        ret = pipe(fd);
        assert(ret == 0);
@@ -179,6 +181,17 @@ static void test2(TALLOC_CTX *mem_ctx, const char *pidfile,
        assert(n == sizeof(ret));
        assert(ret == 1);
 
+       ret = stat(pidfile, &st);
+       assert(ret == 0);
+       assert(S_ISREG(st.st_mode));
+
+       pidfile_fd = open(pidfile, O_RDONLY, 0644);
+       assert(pidfile_fd != -1);
+       n = read(pidfile_fd, pidstr, sizeof(pidstr)-1);
+       assert(n != -1);
+       pid2 = (pid_t)atoi(pidstr);
+       assert(pid == pid2);
+
        ret = kill(pid, SIGHUP);
        assert(ret == 0);