]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: introduce unit_fork_and_watch_rm_rf()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 25 Aug 2019 08:57:08 +0000 (17:57 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Aug 2019 14:09:54 +0000 (23:09 +0900)
src/core/service.c
src/core/unit.c
src/core/unit.h

index 7e923c663d1d5ac196c507d67a2459d010d3df6e..0fffe11c49e84f12a6e4e2e1ef8cfaa6ecb99cb2 100644 (file)
@@ -30,7 +30,6 @@
 #include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
-#include "rm-rf.h"
 #include "serialize.h"
 #include "service.h"
 #include "signal-util.h"
@@ -4252,7 +4251,6 @@ static int service_exit_status(Unit *u) {
 static int service_clean(Unit *u, ExecCleanMask mask) {
         _cleanup_strv_free_ char **l = NULL;
         Service *s = SERVICE(u);
-        pid_t pid;
         int r;
 
         assert(s);
@@ -4277,36 +4275,16 @@ static int service_clean(Unit *u, ExecCleanMask mask) {
         if (r < 0)
                 goto fail;
 
-        r = unit_fork_helper_process(UNIT(s), "(sd-rmrf)", &pid);
-        if (r < 0)
-                goto fail;
-        if (r == 0) {
-                int ret = EXIT_SUCCESS;
-                char **i;
-
-                STRV_FOREACH(i, l) {
-                        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);
+        r = unit_fork_and_watch_rm_rf(u, l, &s->control_pid);
         if (r < 0)
                 goto fail;
 
-        s->control_pid = pid;
-
         service_set_state(s, SERVICE_CLEANING);
 
         return 0;
 
 fail:
-        log_unit_warning_errno(UNIT(s), r, "Failed to initiate cleaning: %m");
+        log_unit_warning_errno(u, r, "Failed to initiate cleaning: %m");
         s->clean_result = SERVICE_FAILURE_RESOURCES;
         s->timer_event_source = sd_event_source_unref(s->timer_event_source);
         return r;
index 31ed473f91057829b77e620a7caa00f6394b5bb3..5224015c706efe6cb12c6b9ce82d7028009c9a4f 100644 (file)
@@ -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);
index 4732d72202979548befd5e946b675e12842ba8d6..d5f4413cd812bce49c55ac5eca814b04f1dcdc31 100644 (file)
@@ -824,6 +824,7 @@ bool unit_shall_confirm_spawn(Unit *u);
 int unit_set_exec_params(Unit *s, ExecParameters *p);
 
 int unit_fork_helper_process(Unit *u, const char *name, pid_t *ret);
+int unit_fork_and_watch_rm_rf(Unit *u, char **paths, pid_t *ret_pid);
 
 void unit_remove_dependencies(Unit *u, UnitDependencyMask mask);