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