Skip to content

Commit

Permalink
Drop vfork support
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
bgamari committed Mar 13, 2023
1 parent 383181f commit 203aa08
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
14 changes: 2 additions & 12 deletions cbits/posix/fork_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@
#include <signal.h>
#endif

#if defined(HAVE_VFORK_H)
#include <vfork.h>
#endif

#include <Rts.h>

#if defined(HAVE_WORKING_VFORK)
#define myfork vfork
#elif defined(HAVE_WORKING_FORK)
#if defined(HAVE_WORKING_FORK)
#define myfork fork
// We don't need a fork command on Windows
#else
Expand Down Expand Up @@ -152,7 +146,7 @@ do_spawn_fork (char *const args[],
}
#endif

int pid = myfork();
int pid = fork();
switch(pid)
{
case -1:
Expand All @@ -164,10 +158,6 @@ do_spawn_fork (char *const args[],
return -1;

case 0:
// WARNING! We may now be in the child of vfork(), and any
// memory we modify below may also be seen in the parent
// process.

close(forkCommunicationFds[0]);
fcntl(forkCommunicationFds[1], F_SETFD, FD_CLOEXEC);

Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## unreleased

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

## 1.6.17.0 *February 2023*

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_CONFIG_HEADERS([include/HsProcessConfig.h])

AC_PROG_CC

dnl ** Working vfork?
dnl ** Working fork?
AC_FUNC_FORK

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

0 comments on commit 203aa08

Please sign in to comment.