summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-08-23 00:08:16 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-08-23 00:08:16 +0900
commit52a12341f9854b9728607c073d2cae44544b5585 (patch)
tree97c57db3e170bb8e9c0ef44c9ff7d18da4e2cd22
parent95939aed212c4e01059ce237e0426ede2aaffd86 (diff)
downloadsystemd-52a12341f9854b9728607c073d2cae44544b5585.tar.gz
core: make RuntimeDirectoryPreserve= works with non-service units
-rw-r--r--src/core/mount.c4
-rw-r--r--src/core/service.c6
-rw-r--r--src/core/socket.c4
-rw-r--r--src/core/swap.c4
-rw-r--r--src/core/unit.c11
-rw-r--r--src/core/unit.h1
6 files changed, 22 insertions, 8 deletions
diff --git a/src/core/mount.c b/src/core/mount.c
index 4f37d3e9a9..959b8fbed2 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -826,7 +826,7 @@ static void mount_enter_dead(Mount *m, MountResult f) {
m->exec_runtime = exec_runtime_unref(m->exec_runtime, true);
- exec_context_destroy_runtime_directory(&m->exec_context, UNIT(m)->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
+ unit_destroy_runtime_directory(UNIT(m), &m->exec_context);
unit_unref_uid_gid(UNIT(m), true);
@@ -1996,6 +1996,8 @@ const UnitVTable mount_vtable = {
.active_state = mount_active_state,
.sub_state_to_string = mount_sub_state_to_string,
+ .will_restart = unit_will_restart_default,
+
.may_gc = mount_may_gc,
.sigchld_event = mount_sigchld_event,
diff --git a/src/core/service.c b/src/core/service.c
index d264b9a281..61e18de5fb 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1721,12 +1721,8 @@ static bool service_will_restart(Unit *u) {
return true;
if (s->state == SERVICE_AUTO_RESTART)
return true;
- if (!UNIT(s)->job)
- return false;
- if (UNIT(s)->job->type == JOB_START)
- return true;
- return false;
+ return unit_will_restart_default(u);
}
static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) {
diff --git a/src/core/socket.c b/src/core/socket.c
index 46fe405a17..e94d6feef9 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -2035,7 +2035,7 @@ static void socket_enter_dead(Socket *s, SocketResult f) {
s->exec_runtime = exec_runtime_unref(s->exec_runtime, true);
- exec_context_destroy_runtime_directory(&s->exec_context, UNIT(s)->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
+ unit_destroy_runtime_directory(UNIT(s), &s->exec_context);
unit_unref_uid_gid(UNIT(s), true);
@@ -3353,6 +3353,8 @@ const UnitVTable socket_vtable = {
.active_state = socket_active_state,
.sub_state_to_string = socket_sub_state_to_string,
+ .will_restart = unit_will_restart_default,
+
.may_gc = socket_may_gc,
.sigchld_event = socket_sigchld_event,
diff --git a/src/core/swap.c b/src/core/swap.c
index 74381c0c95..4ce9d06280 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -683,7 +683,7 @@ static void swap_enter_dead(Swap *s, SwapResult f) {
s->exec_runtime = exec_runtime_unref(s->exec_runtime, true);
- exec_context_destroy_runtime_directory(&s->exec_context, UNIT(s)->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
+ unit_destroy_runtime_directory(UNIT(s), &s->exec_context);
unit_unref_uid_gid(UNIT(s), true);
@@ -1529,6 +1529,8 @@ const UnitVTable swap_vtable = {
.active_state = swap_active_state,
.sub_state_to_string = swap_sub_state_to_string,
+ .will_restart = unit_will_restart_default,
+
.may_gc = swap_may_gc,
.sigchld_event = swap_sigchld_event,
diff --git a/src/core/unit.c b/src/core/unit.c
index ff979ffdd6..a2944cbc15 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -4069,6 +4069,17 @@ bool unit_active_or_pending(Unit *u) {
return false;
}
+bool unit_will_restart_default(Unit *u) {
+ assert(u);
+
+ if (!u->job)
+ return false;
+ if (u->job->type == JOB_START)
+ return true;
+
+ return false;
+}
+
bool unit_will_restart(Unit *u) {
assert(u);
diff --git a/src/core/unit.h b/src/core/unit.h
index 00436dc664..7f1d2f651c 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -752,6 +752,7 @@ const char *unit_slice_name(Unit *u);
bool unit_stop_pending(Unit *u) _pure_;
bool unit_inactive_or_pending(Unit *u) _pure_;
bool unit_active_or_pending(Unit *u);
+bool unit_will_restart_default(Unit *u);
bool unit_will_restart(Unit *u);
int unit_add_default_target_dependency(Unit *u, Unit *target);