]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: don't manually destroy timer when we can't spawn a child
authorLennart Poettering <lennart@poettering.net>
Sat, 9 Sep 2023 10:09:53 +0000 (12:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 9 Sep 2023 12:10:54 +0000 (14:10 +0200)
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
src/core/swap.c

index 3e569327c85733ebdb6080add72ecac5741c2634..a485db67c531ef042c76339185558556e68250e7 100644 (file)
@@ -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) {
index 386725c8471015c2c0cb08b4dea60c3f3bf4d93c..c467008fb2f09ccb87a799810f1a23c2610221e6 100644 (file)
@@ -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) {