diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-06-22 11:55:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-06-23 10:05:16 +0200 |
commit | 437f3e35b4d580ac99a52e307542aa4370854768 (patch) | |
tree | d3e69f4a5e4fb17a9a63e959a0126c2ff1b25a6e /src/shared/async.c | |
parent | shared: move async.[ch] from src/basic/ → src/shared/ (diff) | |
download | systemd-437f3e35b4d580ac99a52e307542aa4370854768.tar.xz systemd-437f3e35b4d580ac99a52e307542aa4370854768.zip |
async: add generic implementation of asynchronous_rm_rf()
This one doesn't use threads anymore. This is the last use of threads in
PID 1. Yay!
Fixes: #27287
Diffstat (limited to 'src/shared/async.c')
-rw-r--r-- | src/shared/async.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/shared/async.c b/src/shared/async.c index c0e1641cb2..a98f31d3b8 100644 --- a/src/shared/async.c +++ b/src/shared/async.c @@ -158,3 +158,28 @@ int asynchronous_close(int fd) { return -EBADF; /* return an invalidated fd */ } + +int asynchronous_rm_rf(const char *p, RemoveFlags flags) { + int r; + + assert(p); + + /* Forks off a child that destroys the specified path. This will be best effort only, i.e. the child + * will attempt to do its thing, but we won't wait for it or check its success. */ + + r = safe_fork("(sd-rmrf)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DETACH, NULL); + if (r != 0) + return r; + + /* Child */ + + r = rm_rf(p, flags); + if (r < 0) { + log_debug_errno(r, "Failed to rm -rf '%s', ignoring: %m", p); + _exit(EXIT_FAILURE); /* This is a detached process, hence noone really cares, but who knows + * maybe it's good for debugging/tracing to return an exit code + * indicative of our failure here. */ + } + + _exit(EXIT_SUCCESS); +} |