]> granicus.if.org Git - strace/commitdiff
tests/vfork-f.c: support platforms without vfork
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 7 Jan 2016 01:42:05 +0000 (01:42 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 7 Jan 2016 02:11:58 +0000 (02:11 +0000)
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.

tests/vfork-f.c

index 2b312060e87c0dd668c668d2510a101fb136d602..961141d6e9493f12462990bf387d140f114b798a 100644 (file)
@@ -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);