systemd/0023-delay-to-restart-when-a-service-can-not-be-auto-restarted.patch
xujing 826fd825d6 sync and backport some patches
systemd-journald: Fix journal file descriptors leak problems.
systemd: Activation service must be restarted when it is already started and re-actived by dbus
systemd-core: fix problem of dbus service can not be started
systemd-core: Delay to restart when a service can not be auto-restarted when there is one STOP_JOB for the service
core: fix SIGABRT on empty exec command argv
journalctl: never fail at flushing when the flushed flag is set
timesync: fix wrong type for receiving timestamp in nanoseconds
udev: fix potential memleak
(cherry picked from commit d0907552a565ed01a4f9da4dd27168b3726f9236)
2022-03-30 10:15:27 +08:00

44 lines
1.9 KiB
Diff

From 9315c29e4fdfa19c90bb483a364b017881f5cef7 Mon Sep 17 00:00:00 2001
From: huangkaibin <huangkaibin@huawei.com>
Date: Sat, 21 Apr 2018 17:18:19 +0800
Subject: [PATCH] systemd-core: Delay to restart when a service can not be
auto-restarted when there is one STOP_JOB for the service
When a service current has a STOP job has not scheduled yet,
and also if the service is already scheduled with an auto-restart
with restart-second configured as 0, the service will not be restarted successfully,
and systemd will go into an endless loop to restart the service.
This is because restart-second is 0 and timer task has higher priority than IO tasks when there priority
is same(both with 0), so the STOP job has no chance to be scheduled, and systemd will go into the endless loop
to handle the time task.
This patch fix this problem by delaying 1 second to restart the service to cause STOP job to be scheduled.
---
src/core/service.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/core/service.c b/src/core/service.c
index ad9c028..8217447 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -1716,14 +1716,15 @@ fail:
static void service_enter_restart(Service *s) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
+ int restart_usec;
assert(s);
if (unit_has_job_type(UNIT(s), JOB_STOP)) {
/* Don't restart things if we are going down anyway */
log_unit_info(UNIT(s), "Stop job pending for unit, delaying automatic restart.");
-
- r = service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->restart_usec));
+ restart_usec = (s->restart_usec == 0) ? 1*USEC_PER_SEC : s->restart_usec;
+ r = service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), restart_usec));
if (r < 0)
goto fail;
--
1.8.3.1