Skip to content

Commit 203aa08

Browse files
committed
Drop vfork support
`vfork` is something of a relic, originally introduced as a (rather unsafe) optimisation of `fork` in 3.0BSD, allowing the user to eliminate the cost of cloning the parent process's address space (as early BSDs would do) when `fork`ing with the intent of immediately `exec`ing. However, its design has long been considered a mistake (being nigh impossible to use safely in a multithreaded environment), its benefits have largely vanished (since modern operating systems rely on virtual memory to remap the parent's address space as copy-on-write instead of copying), and nearly all platforms now consider it to be an alias of `fork`. Remove `process`'s support for `vfork`. Fixes #261.
1 parent 383181f commit 203aa08

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

cbits/posix/fork_exec.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@
2929
#include <signal.h>
3030
#endif
3131

32-
#if defined(HAVE_VFORK_H)
33-
#include <vfork.h>
34-
#endif
35-
3632
#include <Rts.h>
3733

38-
#if defined(HAVE_WORKING_VFORK)
39-
#define myfork vfork
40-
#elif defined(HAVE_WORKING_FORK)
34+
#if defined(HAVE_WORKING_FORK)
4135
#define myfork fork
4236
// We don't need a fork command on Windows
4337
#else
@@ -152,7 +146,7 @@ do_spawn_fork (char *const args[],
152146
}
153147
#endif
154148

155-
int pid = myfork();
149+
int pid = fork();
156150
switch(pid)
157151
{
158152
case -1:
@@ -164,10 +158,6 @@ do_spawn_fork (char *const args[],
164158
return -1;
165159

166160
case 0:
167-
// WARNING! We may now be in the child of vfork(), and any
168-
// memory we modify below may also be seen in the parent
169-
// process.
170-
171161
close(forkCommunicationFds[0]);
172162
fcntl(forkCommunicationFds[1], F_SETFD, FD_CLOEXEC);
173163

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## unreleased
44

55
* Fix deadlock when waiting for process completion and process jobs [#273](https://github.com/haskell/process/issues/273)
6-
* Support delegate_ctlc on Windows. [#278](https://github.com/haskell/process/pull/278)
6+
* Support `delegate_ctlc` on Windows. [#278](https://github.com/haskell/process/pull/278)
7+
* Drop support for `vfork` [#261](https://github.com/haskell/process/pull/261)
78

89
## 1.6.17.0 *February 2023*
910

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AC_CONFIG_HEADERS([include/HsProcessConfig.h])
77

88
AC_PROG_CC
99

10-
dnl ** Working vfork?
10+
dnl ** Working fork?
1111
AC_FUNC_FORK
1212

1313
# check for specific header (.h) files that we are interested in

0 commit comments

Comments
 (0)