mirror of
https://github.com/samba-team/samba.git
synced 2025-02-10 13:57:47 +03:00
ctdb-tests: Add a sock_daemon test for PID file contention
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
b67cc00c93
commit
4cb560386a
@ -65,3 +65,10 @@ test6[PID]: daemon started, pid=PID
|
|||||||
test6[PID]: Shutting down
|
test6[PID]: Shutting down
|
||||||
EOF
|
EOF
|
||||||
unit_test sock_daemon_test "$pidfile" "$sockpath" 6
|
unit_test sock_daemon_test "$pidfile" "$sockpath" 6
|
||||||
|
|
||||||
|
ok <<EOF
|
||||||
|
test7[PID]: daemon started, pid=PID
|
||||||
|
test7[PID]: Received signal 15
|
||||||
|
test7[PID]: Shutting down
|
||||||
|
EOF
|
||||||
|
unit_test sock_daemon_test "$pidfile" "$sockpath" 7
|
||||||
|
@ -990,6 +990,81 @@ static void test6(TALLOC_CTX *mem_ctx, const char *pidfile,
|
|||||||
assert(pid != -1);
|
assert(pid != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test7
|
||||||
|
*
|
||||||
|
* Start daemon twice, confirm PID file contention
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void test7(TALLOC_CTX *mem_ctx, const char *pidfile,
|
||||||
|
const char *sockpath)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
int fd[2];
|
||||||
|
pid_t pid, pid2;
|
||||||
|
int ret;
|
||||||
|
struct tevent_context *ev;
|
||||||
|
struct sock_daemon_context *sockd;
|
||||||
|
ssize_t n;
|
||||||
|
|
||||||
|
ret = pipe(fd);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
pid = fork();
|
||||||
|
assert(pid != -1);
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
close(fd[0]);
|
||||||
|
|
||||||
|
ev = tevent_context_init(mem_ctx);
|
||||||
|
assert(ev != NULL);
|
||||||
|
|
||||||
|
/* Reuse test2 funcs for the startup synchronisation */
|
||||||
|
ret = sock_daemon_setup(mem_ctx, "test7", "file:", "NOTICE",
|
||||||
|
&test2_funcs, &fd[1], &sockd);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
ret = sock_daemon_run(ev, sockd, pidfile, -1);
|
||||||
|
assert(ret == EINTR);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd[1]);
|
||||||
|
|
||||||
|
n = read(fd[0], &ret, sizeof(ret));
|
||||||
|
assert(n == sizeof(ret));
|
||||||
|
assert(ret == 1);
|
||||||
|
|
||||||
|
ret = stat(pidfile, &st);
|
||||||
|
assert(ret == 0);
|
||||||
|
assert(S_ISREG(st.st_mode));
|
||||||
|
|
||||||
|
ev = tevent_context_init(mem_ctx);
|
||||||
|
assert(ev != NULL);
|
||||||
|
|
||||||
|
/* Reuse test2 funcs for the startup synchronisation */
|
||||||
|
ret = sock_daemon_setup(mem_ctx, "test7-parent", "file:", "NOTICE",
|
||||||
|
&test2_funcs, &fd[1], &sockd);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
ret = sock_daemon_run(ev, sockd, pidfile, -1);
|
||||||
|
assert(ret == EEXIST);
|
||||||
|
|
||||||
|
ret = kill(pid, SIGTERM);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
n = read(fd[0], &ret, sizeof(ret));
|
||||||
|
assert(n == sizeof(ret));
|
||||||
|
assert(ret == 3);
|
||||||
|
|
||||||
|
pid2 = waitpid(pid, &ret, 0);
|
||||||
|
assert(pid2 == pid);
|
||||||
|
assert(WEXITSTATUS(ret) == 0);
|
||||||
|
|
||||||
|
close(fd[0]);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
TALLOC_CTX *mem_ctx;
|
TALLOC_CTX *mem_ctx;
|
||||||
@ -1033,6 +1108,10 @@ int main(int argc, const char **argv)
|
|||||||
test6(mem_ctx, pidfile, sockpath);
|
test6(mem_ctx, pidfile, sockpath);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
test7(mem_ctx, pidfile, sockpath);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unknown test number %d\n", num);
|
fprintf(stderr, "Unknown test number %d\n", num);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user