daandemeyer / rpms / systemd

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