From c32c868ab8b2b95724550d0130782c0767fc3bab Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Tue, 19 Jan 2021 09:26:31 -0300 Subject: 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 --- posix/unistd.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'posix/unistd.h') diff --git a/posix/unistd.h b/posix/unistd.h index d9d8929f71..217c6c5363 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -781,6 +781,13 @@ extern __pid_t fork (void) __THROWNL; extern __pid_t vfork (void) __THROW; #endif /* Use misc or XPG < 7. */ +#ifdef __USE_GNU +/* This is similar to fork, however it does not run the atfork handlers + neither reinitialize any internal locks in multithread case. + Different than fork, _Fork is async-signal-safe. */ +extern __pid_t _Fork (void) __THROW; +#endif + /* Return the pathname of the terminal FD is open on, or NULL on errors. The returned storage is good only until the next call to this function. */ -- cgit v1.2.3