Commit 4fe32e5d authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

zdtm: Fix fd01 cleanup

waitpid() does not return child pid, when child has not exited.
So, we can't use it to find pids of children.
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f48bf982
...@@ -22,11 +22,19 @@ int main(int argc, char **argv) ...@@ -22,11 +22,19 @@ int main(int argc, char **argv)
unsigned int i, max_nr, flags; unsigned int i, max_nr, flags;
int fd, status, ret; int fd, status, ret;
struct rlimit rlim; struct rlimit rlim;
futex_t *futex;
char buf[16]; char buf[16];
pid_t pid; pid_t pid;
test_init(argc, argv); test_init(argc, argv);
futex = mmap(NULL, sizeof(*futex), PROT_WRITE | PROT_READ, MAP_ANONYMOUS|MAP_SHARED, -1, 0);
if (futex == MAP_FAILED) {
fail("mmap");
exit(1);
}
futex_init(futex);
fd = open("/proc/sys/fs/nr_open", O_RDONLY); fd = open("/proc/sys/fs/nr_open", O_RDONLY);
if (fd < 0) { if (fd < 0) {
fail("Can't open /proc/sys/fs/nr_open"); fail("Can't open /proc/sys/fs/nr_open");
...@@ -86,7 +94,7 @@ int main(int argc, char **argv) ...@@ -86,7 +94,7 @@ int main(int argc, char **argv)
fail("fork"); fail("fork");
exit(1); exit(1);
} else if (!pid) { } else if (!pid) {
pause(); futex_wait_while(futex, 0);
exit(0); exit(0);
} }
} }
...@@ -95,9 +103,12 @@ int main(int argc, char **argv) ...@@ -95,9 +103,12 @@ int main(int argc, char **argv)
test_waitsig(); test_waitsig();
/* Cleanup */ /* Cleanup */
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { futex_set_and_wake(futex, 1);
if (kill(pid, SIGTERM) == 0) while (wait(&status) > 0) {
waitpid(-1, &status, 0); /* Ignore errors */ if (!WIFEXITED(status) || WEXITSTATUS(status)) {
fail("Wrong exit status: %d", status);
exit(1);
}
} }
pass(); pass();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment