| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "shared-forward.h" |
| 5 |
|
| 6 |
/* These functions implement various potentially slow operations that are executed asynchronously. They are |
| 7 |
* carefully written to not use pthreads, but use fork() or clone() (without CLONE_VM) so that the child does |
| 8 |
* not share any memory with the parent process, and thus cannot possibly interfere with the malloc() |
| 9 |
* synchronization locks. |
| 10 |
* |
| 11 |
* Background: glibc only synchronizes malloc() locks when doing fork(), but not when doing clone() |
| 12 |
* (regardless if through glibc's own wrapper or ours). This means if another thread in the parent has the |
| 13 |
* malloc() lock taken while a thread is cloning, the mutex will remain locked in the child (but the other |
| 14 |
* thread won't exist there), with no chance to ever be unlocked again. This will result in deadlocks. Hence |
| 15 |
* one has to make the choice: either never use threads in the parent, or never do memory allocation in the |
| 16 |
* child, or never use clone()/clone3() and stick to fork() only. Because we need clone()/clone3() we opted |
| 17 |
* for avoiding threads. */ |
| 18 |
|
| 19 |
int asynchronous_sync(PidRef *ret_pid); |
| 20 |
int asynchronous_fsync(int fd, PidRef *ret_pid); |
| 21 |
|
| 22 |
int asynchronous_close(int fd); |
| 23 |
void asynchronous_close_many(const int fds[], size_t n_fds); |
| 24 |
|
| 25 |
DEFINE_TRIVIAL_CLEANUP_FUNC(int, asynchronous_close); |
| 26 |
|
| 27 |
int asynchronous_rm_rf(const char *p, RemoveFlags flags); |