summaryrefslogtreecommitdiff
path: root/src/core/unit.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-08-25 17:57:08 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-08-28 23:09:54 +0900
commit810ef3180ead97e678cbf7b1107c6fdb424c95de (patch)
tree3d5d9dde7e6fc78de32cbe3b4a02af8c31ce2c2d /src/core/unit.c
parent12213aed128456af33ff6131a14b637318227346 (diff)
downloadsystemd-810ef3180ead97e678cbf7b1107c6fdb424c95de.tar.gz
systemd-810ef3180ead97e678cbf7b1107c6fdb424c95de.tar.bz2
systemd-810ef3180ead97e678cbf7b1107c6fdb424c95de.zip
core: introduce unit_fork_and_watch_rm_rf()
Diffstat (limited to 'src/core/unit.c')
-rw-r--r--src/core/unit.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index 31ed473f91..5224015c70 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -38,6 +38,7 @@
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
+#include "rm-rf.h"
#include "serialize.h"
#include "set.h"
#include "signal-util.h"
@@ -5303,6 +5304,39 @@ int unit_fork_helper_process(Unit *u, const char *name, pid_t *ret) {
return 0;
}
+int unit_fork_and_watch_rm_rf(Unit *u, char **paths, pid_t *ret_pid) {
+ pid_t pid;
+ int r;
+
+ assert(u);
+ assert(ret_pid);
+
+ r = unit_fork_helper_process(u, "(sd-rmrf)", &pid);
+ if (r < 0)
+ return r;
+ if (r == 0) {
+ int ret = EXIT_SUCCESS;
+ char **i;
+
+ STRV_FOREACH(i, paths) {
+ r = rm_rf(*i, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_MISSING_OK);
+ if (r < 0) {
+ log_error_errno(r, "Failed to remove '%s': %m", *i);
+ ret = EXIT_FAILURE;
+ }
+ }
+
+ _exit(ret);
+ }
+
+ r = unit_watch_pid(u, pid, true);
+ if (r < 0)
+ return r;
+
+ *ret_pid = pid;
+ return 0;
+}
+
static void unit_update_dependency_mask(Unit *u, UnitDependency d, Unit *other, UnitDependencyInfo di) {
assert(u);
assert(d >= 0);