From 894a30ef3f40b3f6c97f221a30e024264ef53cbf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Sep 2023 12:09:53 +0200 Subject: core: don't manually destroy timer when we can't spawn a child Let's stop manually destroying the timers when we fail to spawn a child. We don't do this in any of the similar codepaths in any of the unit types, only in two specific ones in socket/swap. Destroying the timer is unnecessary, since this is done anyway in the _set_state() call of each unit type if not appropriate, and every failure path here runs through that anyway. This brings all these similar codepaths into sync. --- src/core/socket.c | 10 +++------- src/core/swap.c | 14 +++++--------- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/core/socket.c b/src/core/socket.c index 3e569327c8..a485db67c5 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1976,7 +1976,7 @@ static int socket_chown(Socket *s, PidRef *ret_pid) { r = socket_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_usec)); if (r < 0) - goto fail; + return r; /* We have to resolve the user names out-of-process, hence * let's fork here. It's messy, but well, what can we do? */ @@ -2032,18 +2032,14 @@ static int socket_chown(Socket *s, PidRef *ret_pid) { r = pidref_set_pid(&pidref, pid); if (r < 0) - goto fail; + return r; r = unit_watch_pid(UNIT(s), pidref.pid, /* exclusive= */ true); if (r < 0) - goto fail; + return r; *ret_pid = TAKE_PIDREF(pidref); return 0; - -fail: - s->timer_event_source = sd_event_source_disable_unref(s->timer_event_source); - return r; } static void socket_enter_dead(Socket *s, SocketResult f) { diff --git a/src/core/swap.c b/src/core/swap.c index 386725c847..c467008fb2 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -677,11 +677,11 @@ static int swap_spawn(Swap *s, ExecCommand *c, PidRef *ret_pid) { r = swap_arm_timer(s, usec_add(now(CLOCK_MONOTONIC), s->timeout_usec)); if (r < 0) - goto fail; + return r; r = unit_set_exec_params(UNIT(s), &exec_params); if (r < 0) - goto fail; + return r; r = exec_spawn(UNIT(s), c, @@ -691,22 +691,18 @@ static int swap_spawn(Swap *s, ExecCommand *c, PidRef *ret_pid) { &s->cgroup_context, &pid); if (r < 0) - goto fail; + return r; r = pidref_set_pid(&pidref, pid); if (r < 0) - goto fail; + return r; r = unit_watch_pid(UNIT(s), pidref.pid, /* exclusive= */ true); if (r < 0) - goto fail; + return r; *ret_pid = TAKE_PIDREF(pidref); return 0; - -fail: - s->timer_event_source = sd_event_source_disable_unref(s->timer_event_source); - return r; } static void swap_enter_dead(Swap *s, SwapResult f) { -- cgit v1.2.3