about summary refs log tree commit diff
path: root/posix/fork.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-01-19 09:26:31 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-06-28 15:55:56 -0300
commitc32c868ab8b2b95724550d0130782c0767fc3bab (patch)
tree53b43a7f006fe8f549affb6b6d4d24b808a75465 /posix/fork.c
parentdd45734e322a03287d34d8af9b7da7b35cfddb8e (diff)
downloadglibc-c32c868ab8b2b95724550d0130782c0767fc3bab.tar.gz
glibc-c32c868ab8b2b95724550d0130782c0767fc3bab.tar.xz
glibc-c32c868ab8b2b95724550d0130782c0767fc3bab.zip
posix: Add _Fork [BZ #4737]
Austin Group issue 62 [1] dropped the async-signal-safe requirement
for fork and provided a async-signal-safe _Fork replacement that
does not run the atfork handlers.  It will be included in the next
POSIX standard.

It allow to close a long standing issue to make fork AS-safe (BZ#4737).
As indicated on the bug, besides the internal lock for the atfork
handlers itself; there is no guarantee that the handlers itself will
not introduce more AS-safe issues.

The idea is synchronize fork with the required internal locks to allow
children in multithread processes to use mostly of standard function
(even though POSIX states only AS-safe function should be used).  On
signal handles, _Fork should be used intead and only AS-safe functions
should be used.

For testing, the new tst-_Fork only check basic usage.  I also added
a new tst-mallocfork3 which uses the same strategy to check for
deadlock of tst-mallocfork2 but using threads instead of subprocesses
(and it does deadlock if it replaces _Fork with fork).

[1] https://austingroupbugs.net/view.php?id=62
Diffstat (limited to 'posix/fork.c')
-rw-r--r--posix/fork.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/posix/fork.c b/posix/fork.c
index 940d6a0955..c471f7b15f 100644
--- a/posix/fork.c
+++ b/posix/fork.c
@@ -41,7 +41,10 @@ __libc_fork (void)
 {
   /* Determine if we are running multiple threads.  We skip some fork
      handlers in the single-thread case, to make fork safer to use in
-     signal handlers.  */
+     signal handlers.  Although POSIX has dropped async-signal-safe
+     requirement for fork (Austin Group tracker issue #62) this is
+     best effort to make is async-signal-safe at least for single-thread
+     case.  */
   bool multiple_threads = __libc_single_threaded == 0;
 
   __run_fork_handlers (atfork_run_prepare, multiple_threads);