From bd153422f28634bb6e53f13f80beb8289d405267 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 30 Sep 2020 13:32:59 -0400 Subject: implement _Fork and refactor fork using it the _Fork interface is defined for future issue of POSIX as the outcome of Austin Group issue 62, which drops the AS-safety requirement for fork, and provides an AS-safe replacement that does not run the registered atfork handlers. --- include/unistd.h | 1 + src/process/_Fork.c | 11 ++--------- src/process/fork.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 src/process/fork.c diff --git a/include/unistd.h b/include/unistd.h index 07584a23..13064026 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -82,6 +82,7 @@ unsigned sleep(unsigned); int pause(void); pid_t fork(void); +pid_t _Fork(void); int execve(const char *, char *const [], char *const []); int execv(const char *, char *const []); int execle(const char *, const char *, ...); diff --git a/src/process/_Fork.c b/src/process/_Fork.c index 17fb87ad..1f41197c 100644 --- a/src/process/_Fork.c +++ b/src/process/_Fork.c @@ -1,23 +1,17 @@ #include -#include #include #include "syscall.h" #include "libc.h" #include "lock.h" #include "pthread_impl.h" -static void dummy(int x) -{ -} - -weak_alias(dummy, __fork_handler); +static void dummy(int x) { } weak_alias(dummy, __aio_atfork); -pid_t fork(void) +pid_t _Fork(void) { pid_t ret; sigset_t set; - __fork_handler(-1); __block_all_sigs(&set); __aio_atfork(-1); LOCK(__abort_lock); @@ -39,6 +33,5 @@ pid_t fork(void) UNLOCK(__abort_lock); __aio_atfork(!ret); __restore_sigs(&set); - __fork_handler(!ret); return __syscall_ret(ret); } diff --git a/src/process/fork.c b/src/process/fork.c new file mode 100644 index 00000000..a12da01a --- /dev/null +++ b/src/process/fork.c @@ -0,0 +1,13 @@ +#include +#include "libc.h" + +static void dummy(int x) { } +weak_alias(dummy, __fork_handler); + +pid_t fork(void) +{ + __fork_handler(-1); + pid_t ret = _Fork(); + __fork_handler(!ret); + return ret; +} -- cgit v1.2.1