2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5 * SPDX-License-Identifier: GPL-2.0-or-later
17 logit_(const char *const str)
22 #define prefix "vfork-f."
23 #define logit(arg) logit_(prefix arg)
25 int main(int ac, char **av)
30 if (read(0, &ac, sizeof(int)))
37 int child_wait_fds[2];
39 if (pipe(child_wait_fds))
40 perror_msg_and_fail("pipe");
41 if (fcntl(child_wait_fds[1], F_SETFD, FD_CLOEXEC))
42 perror_msg_and_fail("fcntl");
44 int parent_wait_fds[2];
45 if (pipe(parent_wait_fds))
46 perror_msg_and_fail("pipe");
47 if (fcntl(parent_wait_fds[0], F_SETFD, FD_CLOEXEC))
48 perror_msg_and_fail("fcntl");
49 if (fcntl(parent_wait_fds[1], F_SETFD, FD_CLOEXEC))
50 perror_msg_and_fail("fcntl");
52 char *const args[] = { av[0], (char *) "", NULL };
56 perror_msg_and_fail("vfork");
59 if (logit("child") || execve(args[0], args, args + 1))
64 close(parent_wait_fds[1]);
66 if (read(parent_wait_fds[0], &parent_wait_fds[1], sizeof(int)))
67 perror_msg_and_fail("read");
69 close(child_wait_fds[1]);
72 assert(wait(&status) == pid);
75 pid_t ppid = getpid();
78 printf("%-5d chdir(\"%sstart\") = -1 ENOENT (%m)\n"
79 "%-5d chdir(\"%schild\") = -1 ENOENT (%m)\n"
80 "%-5d chdir(\"%sparent\") = -1 ENOENT (%m)\n"
81 "%-5d chdir(\"%sexec\") = -1 ENOENT (%m)\n"
82 "%-5d chdir(\"%sfinish\") = -1 ENOENT (%m)\n",