[CRIU] [PATCH 1/5] zdtm/fdt_shared: wait until children finish the preparation stage
Andrey Vagin
avagin at openvz.org
Sun Aug 23 15:26:23 PDT 2015
Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm/live/static/fdt_shared.c | 37 ++++++++++++++++++++++++++++++++++++
test/zdtm/live/static/file_locks02.c | 1 -
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/test/zdtm/live/static/fdt_shared.c b/test/zdtm/live/static/fdt_shared.c
index 35555a6..ee195c2 100644
--- a/test/zdtm/live/static/fdt_shared.c
+++ b/test/zdtm/live/static/fdt_shared.c
@@ -6,6 +6,7 @@
#include <sched.h>
#include <signal.h>
#include <sys/wait.h>
+#include <stdlib.h>
#include "zdtmtst.h"
@@ -19,6 +20,32 @@ TEST_OPTION(filename, string, "file name", 1);
#define TEST_FD 128
#define TEST_STRING "Hello World!"
+#define CHILDREN 4
+static int fork_pfd[2];
+
+static void forked()
+{
+ char c = 0;
+
+ if (write(fork_pfd[1], &c, 1) != 1) {
+ err("Unable to send a signal to the parent");
+ exit(5);
+ }
+}
+
+static void wait_children()
+{
+ int i;
+ char c;
+
+ for (i = 0; i < CHILDREN; i++) {
+ if (read(fork_pfd[0], &c, 1) != 1) {
+ err("Unable to read a signal from a child");
+ exit(5);
+ }
+ }
+}
+
static pid_t clone_child(int (*fn)(void *), int flags)
{
char stack[STACK_SIZE];
@@ -38,6 +65,7 @@ static int child2(void *_arg)
{
char buf[10];
+ forked();
test_waitsig();
if (read(TEST_FD, buf, sizeof(TEST_STRING)) != sizeof(TEST_STRING)) {
@@ -50,6 +78,7 @@ static int child2(void *_arg)
static int child3(void *_arg)
{
+ forked();
test_waitsig();
if (close(TEST_FD) != -1) {
@@ -74,6 +103,7 @@ static int child(void *_arg)
if (pid < 0)
return 1;
+ forked();
test_waitsig();
kill(pid2, SIGTERM);
@@ -113,6 +143,11 @@ int main(int argc, char ** argv)
test_init(argc, argv);
+ if (pipe(fork_pfd)) {
+ err("pipe");
+ return 1;
+ }
+
pid = clone_child(child, CLONE_FILES);
if (pid < 0)
return 1;
@@ -121,6 +156,8 @@ int main(int argc, char ** argv)
if (pid2 < 0)
return 1;
+ wait_children();
+
test_daemon();
test_waitsig();
diff --git a/test/zdtm/live/static/file_locks02.c b/test/zdtm/live/static/file_locks02.c
index ef4371c..b16cb06 100644
--- a/test/zdtm/live/static/file_locks02.c
+++ b/test/zdtm/live/static/file_locks02.c
@@ -80,7 +80,6 @@ int main(int argc, char **argv)
pid = fork();
if (pid == 0) {
- close(pf[1]);
read(pf[0], &pid, sizeof(pid));
exit(0);
}
--
2.1.0
More information about the CRIU
mailing list