You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
5.0 KiB
119 lines
5.0 KiB
7 months ago
|
From 917b03f2b5ccdd668a49da7df72baaddd338c071 Mon Sep 17 00:00:00 2001
|
||
|
From: Lennart Poettering <lennart@poettering.net>
|
||
|
Date: Mon, 2 Jan 2023 15:06:10 +0100
|
||
|
Subject: [PATCH] pid1: rework service_arm_timer() to optionally take a
|
||
|
relative time value
|
||
|
|
||
|
In most cases this is actually what we want, hence simplify this case.
|
||
|
|
||
|
(cherry picked from commit e5d6dcce7f852b978251d062afb2fcba16714eb9)
|
||
|
|
||
|
Related: RHEL-6090
|
||
|
---
|
||
|
src/core/service.c | 24 ++++++++++++------------
|
||
|
1 file changed, 12 insertions(+), 12 deletions(-)
|
||
|
|
||
|
diff --git a/src/core/service.c b/src/core/service.c
|
||
|
index 1e14cdc6ca..aa76b4ad9a 100644
|
||
|
--- a/src/core/service.c
|
||
|
+++ b/src/core/service.c
|
||
|
@@ -530,13 +530,13 @@ static usec_t service_running_timeout(Service *s) {
|
||
|
delta);
|
||
|
}
|
||
|
|
||
|
-static int service_arm_timer(Service *s, usec_t usec) {
|
||
|
+static int service_arm_timer(Service *s, bool relative, usec_t usec) {
|
||
|
int r;
|
||
|
|
||
|
assert(s);
|
||
|
|
||
|
if (s->timer_event_source) {
|
||
|
- r = sd_event_source_set_time(s->timer_event_source, usec);
|
||
|
+ r = (relative ? sd_event_source_set_time_relative : sd_event_source_set_time)(s->timer_event_source, usec);
|
||
|
if (r < 0)
|
||
|
return r;
|
||
|
|
||
|
@@ -546,7 +546,7 @@ static int service_arm_timer(Service *s, usec_t usec) {
|
||
|
if (usec == USEC_INFINITY)
|
||
|
return 0;
|
||
|
|
||
|
- r = sd_event_add_time(
|
||
|
+ r = (relative ? sd_event_add_time_relative : sd_event_add_time)(
|
||
|
UNIT(s)->manager->event,
|
||
|
&s->timer_event_source,
|
||
|
CLOCK_MONOTONIC,
|
||
|
@@ -1195,7 +1195,7 @@ static int service_coldplug(Unit *u) {
|
||
|
if (s->deserialized_state == s->state)
|
||
|
return 0;
|
||
|
|
||
|
- r = service_arm_timer(s, service_coldplug_timeout(s));
|
||
|
+ r = service_arm_timer(s, /* relative= */ false, service_coldplug_timeout(s));
|
||
|
if (r < 0)
|
||
|
return r;
|
||
|
|
||
|
@@ -1538,7 +1538,7 @@ static int service_spawn_internal(
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
- r = service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), timeout));
|
||
|
+ r = service_arm_timer(s, /* relative= */ true, timeout);
|
||
|
if (r < 0)
|
||
|
return r;
|
||
|
|
||
|
@@ -1857,7 +1857,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
|
||
|
if (s->will_auto_restart) {
|
||
|
s->will_auto_restart = false;
|
||
|
|
||
|
- r = service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->restart_usec));
|
||
|
+ r = service_arm_timer(s, /* relative= */ true, s->restart_usec);
|
||
|
if (r < 0) {
|
||
|
s->n_keep_fd_store--;
|
||
|
goto fail;
|
||
|
@@ -1989,8 +1989,8 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
|
||
|
goto fail;
|
||
|
|
||
|
if (r > 0) {
|
||
|
- r = service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC),
|
||
|
- kill_operation == KILL_WATCHDOG ? service_timeout_abort_usec(s) : s->timeout_stop_usec));
|
||
|
+ r = service_arm_timer(s, /* relative= */ true,
|
||
|
+ kill_operation == KILL_WATCHDOG ? service_timeout_abort_usec(s) : s->timeout_stop_usec);
|
||
|
if (r < 0)
|
||
|
goto fail;
|
||
|
|
||
|
@@ -2020,7 +2020,7 @@ static void service_enter_stop_by_notify(Service *s) {
|
||
|
|
||
|
(void) unit_enqueue_rewatch_pids(UNIT(s));
|
||
|
|
||
|
- service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_stop_usec));
|
||
|
+ service_arm_timer(s, /* relative= */ true, s->timeout_stop_usec);
|
||
|
|
||
|
/* The service told us it's stopping, so it's as if we SIGTERM'd it. */
|
||
|
service_set_state(s, SERVICE_STOP_SIGTERM);
|
||
|
@@ -2099,7 +2099,7 @@ static void service_enter_running(Service *s, ServiceResult f) {
|
||
|
service_enter_stop_by_notify(s);
|
||
|
else {
|
||
|
service_set_state(s, SERVICE_RUNNING);
|
||
|
- service_arm_timer(s, service_running_timeout(s));
|
||
|
+ service_arm_timer(s, /* relative= */ false, service_running_timeout(s));
|
||
|
}
|
||
|
|
||
|
} else if (s->remain_after_exit)
|
||
|
@@ -2398,7 +2398,7 @@ static void service_enter_reload_by_notify(Service *s) {
|
||
|
|
||
|
assert(s);
|
||
|
|
||
|
- service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_start_usec));
|
||
|
+ service_arm_timer(s, /* relative= */ true, s->timeout_start_usec);
|
||
|
service_set_state(s, SERVICE_RELOAD);
|
||
|
|
||
|
/* service_enter_reload_by_notify is never called during a reload, thus no loops are possible. */
|
||
|
@@ -4570,7 +4570,7 @@ static int service_clean(Unit *u, ExecCleanMask mask) {
|
||
|
s->control_command = NULL;
|
||
|
s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
|
||
|
|
||
|
- r = service_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->exec_context.timeout_clean_usec));
|
||
|
+ r = service_arm_timer(s, /* relative= */ true, s->exec_context.timeout_clean_usec);
|
||
|
if (r < 0)
|
||
|
goto fail;
|
||
|
|