summaryrefslogtreecommitdiff
path: root/src/process
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-09-28 18:38:27 -0400
committerRich Felker <dalias@aerifal.cx>2020-09-28 18:56:20 -0400
commit34904d830a9fd1f6fc47218f38c111698303d2fe (patch)
treec43e8b5659386f5a3ed4f5e749d389f2fb91027b /src/process
parenta5aff1972c9e3981566414b09a28e331ccd2be5d (diff)
downloadmusl-34904d830a9fd1f6fc47218f38c111698303d2fe.tar.gz
fix fork of processes with active async io contexts
previously, if a file descriptor had aio operations pending in the parent before fork, attempting to close it in the child would attempt to cancel a thread belonging to the parent. this could deadlock, fail, or crash the whole process of the cancellation signal handler was not yet installed in the parent. in addition, further use of aio from the child could malfunction or deadlock. POSIX specifies that async io operations are not inherited by the child on fork, so clear the entire aio fd map in the child, and take the aio map lock (with signals blocked) across the fork so that the lock is kept in a consistent state.
Diffstat (limited to 'src/process')
-rw-r--r--src/process/fork.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/process/fork.c b/src/process/fork.c
index 7e984ff8..dbaa9402 100644
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -10,6 +10,7 @@ static void dummy(int x)
}
weak_alias(dummy, __fork_handler);
+weak_alias(dummy, __aio_atfork);
pid_t fork(void)
{
@@ -17,6 +18,7 @@ pid_t fork(void)
sigset_t set;
__fork_handler(-1);
__block_all_sigs(&set);
+ __aio_atfork(-1);
#ifdef SYS_fork
ret = __syscall(SYS_fork);
#else
@@ -32,6 +34,7 @@ pid_t fork(void)
libc.threads_minus_1 = 0;
if (libc.need_locks) libc.need_locks = -1;
}
+ __aio_atfork(!ret);
__restore_sigs(&set);
__fork_handler(!ret);
return __syscall_ret(ret);