From: Dmitry V. Levin Date: Thu, 7 Jan 2016 01:42:05 +0000 (+0000) Subject: tests/vfork-f.c: support platforms without vfork X-Git-Tag: v4.12~676 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1eabdb3c99619a8f4ed22fd57310d29aac987ed8;p=strace tests/vfork-f.c: support platforms without vfork On some platforms, e.g. hppa glibc, vfork() is implemented using fork syscall, so the test cannot rely on the parent process remaining blocked until the child process either terminates or calls execve. * tests/vfork-f.c (main): Explicitly block the parent until the child either terminates or calls execve. --- diff --git a/tests/vfork-f.c b/tests/vfork-f.c index 2b312060..961141d6 100644 --- a/tests/vfork-f.c +++ b/tests/vfork-f.c @@ -51,11 +51,19 @@ int main(int ac, char **av, char **ep) logit("start"); - int fds[2]; + int child_wait_fds[2]; (void) close(0); - if (pipe(fds)) + if (pipe(child_wait_fds)) perror_msg_and_fail("pipe"); - if (fcntl(fds[1], F_SETFD, FD_CLOEXEC)) + if (fcntl(child_wait_fds[1], F_SETFD, FD_CLOEXEC)) + perror_msg_and_fail("fcntl"); + + int parent_wait_fds[2]; + if (pipe(parent_wait_fds)) + perror_msg_and_fail("pipe"); + if (fcntl(parent_wait_fds[0], F_SETFD, FD_CLOEXEC)) + perror_msg_and_fail("fcntl"); + if (fcntl(parent_wait_fds[1], F_SETFD, FD_CLOEXEC)) perror_msg_and_fail("fcntl"); char *const args[] = { av[0], (char *) "exec", NULL }; @@ -70,9 +78,12 @@ int main(int ac, char **av, char **ep) } close(0); + close(parent_wait_fds[1]); + if (read(parent_wait_fds[0], &parent_wait_fds[1], sizeof(int))) + perror_msg_and_fail("read"); logit("parent"); - close(fds[1]); + close(child_wait_fds[1]); int status; assert(wait(&status) == pid);