daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
c2dfb7
From 4a1405998671caaaad5b24d4cef309c05175b1c1 Mon Sep 17 00:00:00 2001
c2dfb7
From: ypf791 <ypf791@gmail.com>
c2dfb7
Date: Fri, 19 Jul 2019 18:28:04 +0800
c2dfb7
Subject: [PATCH] core: coldplug possible nop_job
c2dfb7
c2dfb7
When a unit in a state INACTIVE or DEACTIVATING, JobType JOB_TRY_RESTART or
c2dfb7
JOB_TRY_RELOAD will be collapsed to JOB_NOP. And use u->nop_job instead
c2dfb7
of u->job.
c2dfb7
c2dfb7
If a JOB_NOP job is going on with a waiting state, a parallel daemon-reload
c2dfb7
just install it during deserialization. Without a coldplug, the job will
c2dfb7
not be in m->run_queue, which results in a hung try-restart or
c2dfb7
try-reload process.
c2dfb7
c2dfb7
Reproduce:
c2dfb7
c2dfb7
    run systemctl try-restart test.servcie (inactive) repeatly in a terminal.
c2dfb7
    run systemctl daemon-reload repeatly in other terminals.
c2dfb7
c2dfb7
After successful reproduce, systemctl list-jobs will list the hang job.
c2dfb7
c2dfb7
Upsteam:
c2dfb7
systemd/systemd#13124
c2dfb7
c2dfb7
(cherry picked from commit b49e14d5f3081dfcd363d8199a14c0924ae9152f)
c2dfb7
c2dfb7
Resolves: #1829798
c2dfb7
---
c2dfb7
 src/core/unit.c | 6 ++++--
c2dfb7
 1 file changed, 4 insertions(+), 2 deletions(-)
c2dfb7
c2dfb7
diff --git a/src/core/unit.c b/src/core/unit.c
c2dfb7
index 61799bf9e3..f57260727f 100644
c2dfb7
--- a/src/core/unit.c
c2dfb7
+++ b/src/core/unit.c
c2dfb7
@@ -3696,6 +3696,7 @@ int unit_add_node_dependency(Unit *u, const char *what, bool wants, UnitDependen
c2dfb7
 int unit_coldplug(Unit *u) {
c2dfb7
         int r = 0, q;
c2dfb7
         char **i;
c2dfb7
+        Job *uj;
c2dfb7
 
c2dfb7
         assert(u);
c2dfb7
 
c2dfb7
@@ -3718,8 +3719,9 @@ int unit_coldplug(Unit *u) {
c2dfb7
                         r = q;
c2dfb7
         }
c2dfb7
 
c2dfb7
-        if (u->job) {
c2dfb7
-                q = job_coldplug(u->job);
c2dfb7
+        uj = u->job ?: u->nop_job;
c2dfb7
+        if (uj) {
c2dfb7
+                q = job_coldplug(uj);
c2dfb7
                 if (q < 0 && r >= 0)
c2dfb7
                         r = q;
c2dfb7
         }