|
|
55853a |
From 3cc0f088de0daa7bb8732128f51b657d30409c03 Mon Sep 17 00:00:00 2001
|
|
|
55853a |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
55853a |
Date: Sat, 22 Oct 2016 22:16:02 -0400
|
|
|
55853a |
Subject: [PATCH] core: when restarting services, don't close fds
|
|
|
55853a |
|
|
|
55853a |
We would close all the stored fds in service_release_resources(), which of
|
|
|
55853a |
course broke the whole concept of storing fds over service restart.
|
|
|
55853a |
|
|
|
55853a |
Fixes #4408.
|
|
|
55853a |
|
|
|
55853a |
(cherry picked from commit f0bfbfac43b7faa68ef1bb2ad659c191b9ec85d2)
|
|
|
55853a |
(cherry picked from commit 4c271437cd695c31e76adb191013009689a7797c)
|
|
|
55853a |
(cherry picked from commit 10a6469f95c8b8fc43efb3916567e1f15f17bdcf)
|
|
|
55853a |
Resolves: #1798162
|
|
|
55853a |
---
|
|
|
55853a |
src/core/service.c | 22 +++++++++++++++-------
|
|
|
55853a |
src/core/unit.c | 6 ++++--
|
|
|
55853a |
src/core/unit.h | 2 +-
|
|
|
55853a |
3 files changed, 20 insertions(+), 10 deletions(-)
|
|
|
55853a |
|
|
|
55853a |
diff --git a/src/core/service.c b/src/core/service.c
|
|
|
55853a |
index 6b61ccac18..ad45a38270 100644
|
|
|
55853a |
--- a/src/core/service.c
|
|
|
55853a |
+++ b/src/core/service.c
|
|
|
55853a |
@@ -262,7 +262,17 @@ static void service_fd_store_unlink(ServiceFDStore *fs) {
|
|
|
55853a |
free(fs);
|
|
|
55853a |
}
|
|
|
55853a |
|
|
|
55853a |
-static void service_release_resources(Unit *u) {
|
|
|
55853a |
+static void service_release_fd_store(Service *s) {
|
|
|
55853a |
+ assert(s);
|
|
|
55853a |
+
|
|
|
55853a |
+ log_unit_debug(UNIT(s)->id, "Releasing all stored fds");
|
|
|
55853a |
+ while (s->fd_store)
|
|
|
55853a |
+ service_fd_store_unlink(s->fd_store);
|
|
|
55853a |
+
|
|
|
55853a |
+ assert(s->n_fd_store == 0);
|
|
|
55853a |
+}
|
|
|
55853a |
+
|
|
|
55853a |
+static void service_release_resources(Unit *u, bool inactive) {
|
|
|
55853a |
Service *s = SERVICE(u);
|
|
|
55853a |
|
|
|
55853a |
assert(s);
|
|
|
55853a |
@@ -270,12 +280,10 @@ static void service_release_resources(Unit *u) {
|
|
|
55853a |
if (!s->fd_store)
|
|
|
55853a |
return;
|
|
|
55853a |
|
|
|
55853a |
- log_debug("Releasing all resources for %s", u->id);
|
|
|
55853a |
-
|
|
|
55853a |
- while (s->fd_store)
|
|
|
55853a |
- service_fd_store_unlink(s->fd_store);
|
|
|
55853a |
+ log_unit_debug(u->id, "Releasing resources.");
|
|
|
55853a |
|
|
|
55853a |
- assert(s->n_fd_store == 0);
|
|
|
55853a |
+ if (inactive)
|
|
|
55853a |
+ service_release_fd_store(s);
|
|
|
55853a |
}
|
|
|
55853a |
|
|
|
55853a |
static void service_done(Unit *u) {
|
|
|
55853a |
@@ -323,7 +331,7 @@ static void service_done(Unit *u) {
|
|
|
55853a |
|
|
|
55853a |
s->timer_event_source = sd_event_source_unref(s->timer_event_source);
|
|
|
55853a |
|
|
|
55853a |
- service_release_resources(u);
|
|
|
55853a |
+ service_release_resources(u, true);
|
|
|
55853a |
}
|
|
|
55853a |
|
|
|
55853a |
static int on_fd_store_io(sd_event_source *e, int fd, uint32_t revents, void *userdata) {
|
|
|
55853a |
diff --git a/src/core/unit.c b/src/core/unit.c
|
|
|
55853a |
index cabbf8056e..33e0b7126b 100644
|
|
|
55853a |
--- a/src/core/unit.c
|
|
|
55853a |
+++ b/src/core/unit.c
|
|
|
55853a |
@@ -284,6 +284,7 @@ int unit_set_description(Unit *u, const char *description) {
|
|
|
55853a |
|
|
|
55853a |
bool unit_may_gc(Unit *u) {
|
|
|
55853a |
UnitActiveState state;
|
|
|
55853a |
+ bool inactive;
|
|
|
55853a |
assert(u);
|
|
|
55853a |
|
|
|
55853a |
/* Checks whether the unit is ready to be unloaded for garbage collection.
|
|
|
55853a |
@@ -301,16 +302,17 @@ bool unit_may_gc(Unit *u) {
|
|
|
55853a |
return false;
|
|
|
55853a |
|
|
|
55853a |
state = unit_active_state(u);
|
|
|
55853a |
+ inactive = state == UNIT_INACTIVE;
|
|
|
55853a |
|
|
|
55853a |
/* If the unit is inactive and failed and no job is queued for
|
|
|
55853a |
* it, then release its runtime resources */
|
|
|
55853a |
if (UNIT_IS_INACTIVE_OR_FAILED(state) &&
|
|
|
55853a |
UNIT_VTABLE(u)->release_resources)
|
|
|
55853a |
- UNIT_VTABLE(u)->release_resources(u);
|
|
|
55853a |
+ UNIT_VTABLE(u)->release_resources(u, inactive);
|
|
|
55853a |
|
|
|
55853a |
/* But we keep the unit object around for longer when it is
|
|
|
55853a |
* referenced or configured to not be gc'ed */
|
|
|
55853a |
- if (state != UNIT_INACTIVE)
|
|
|
55853a |
+ if (!inactive)
|
|
|
55853a |
return false;
|
|
|
55853a |
|
|
|
55853a |
if (UNIT_VTABLE(u)->no_gc)
|
|
|
55853a |
diff --git a/src/core/unit.h b/src/core/unit.h
|
|
|
55853a |
index a6e21d60ce..97a63f0f8b 100644
|
|
|
55853a |
--- a/src/core/unit.h
|
|
|
55853a |
+++ b/src/core/unit.h
|
|
|
55853a |
@@ -359,7 +359,7 @@ struct UnitVTable {
|
|
|
55853a |
|
|
|
55853a |
/* When the unit is not running and no job for it queued we
|
|
|
55853a |
* shall release its runtime resources */
|
|
|
55853a |
- void (*release_resources)(Unit *u);
|
|
|
55853a |
+ void (*release_resources)(Unit *u, bool inactive);
|
|
|
55853a |
|
|
|
55853a |
/* Return true when this unit is suitable for snapshotting */
|
|
|
55853a |
bool (*check_snapshot)(Unit *u);
|