diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-23 11:36:44 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-23 11:39:45 +0200 |
commit | cbcf371abc328167fa869721c1add4850c793240 (patch) | |
tree | c56e231ce62f5a645b25616fb026e6c87f0b6ce3 /src/basic/fd-util.h | |
parent | 45a68ed3073a006c44703acf2928be156805ef9f (diff) | |
download | systemd-cbcf371abc328167fa869721c1add4850c793240.tar.gz |
Add variant of close_all_fds() that does not allocate and use it in freeze()
Even though it's just a fallback path, let's not be sloppy and allocate in
the crash handler.
> The deadlock happens because systemd crash in malloc() then in signal
> handler, it calls malloc() (close_all_fds()-> opendir()-> __alloc_dir())
> again. malloc() is not a signal-safe function, maybe we should re-think
> the logic here.
Fixes #20266.
Diffstat (limited to 'src/basic/fd-util.h')
-rw-r--r-- | src/basic/fd-util.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index d3c2944d86..61b6684cb3 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -56,7 +56,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL); int fd_nonblock(int fd, bool nonblock); int fd_cloexec(int fd, bool cloexec); -int close_all_fds(int except[], size_t n_except); +int close_all_fds_full(int except[], size_t n_except, bool allow_alloc); +static inline int close_all_fds(int except[], size_t n_except) { + return close_all_fds_full(except, n_except, true); +} int same_fd(int a, int b); |