naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
3d81e0
From 59bce92b081cf0b52c4335461af7cbd003a11aeb Mon Sep 17 00:00:00 2001
3d81e0
From: chenglin130 <cheng.lin130@zte.com.cn>
3d81e0
Date: Sat, 9 Nov 2019 23:04:04 +0800
3d81e0
Subject: [PATCH] core: coldplug possible nop_job
3d81e0
3d81e0
When a unit in a state INACTIVE or DEACTIVATING, JobType JOB_TRY_RESTART or
3d81e0
JOB_TRY_RELOAD will be collapsed to JOB_NOP. And use u->nop_job instead
3d81e0
of u->job.
3d81e0
3d81e0
If a JOB_NOP job is going on with a waiting state, a parallel daemon-reload
3d81e0
just install it during deserialization. Without a coldplug, the job will
3d81e0
not be in m->run_queue, which results in a hung try-restart or
3d81e0
try-reload process.
3d81e0
3d81e0
Reproduce:
3d81e0
1. run systemctl try-restart test.servcie (inactive) repeatly in a terminal.
3d81e0
2. run systemctl daemon-reload repeatly in other terminals.
3d81e0
3d81e0
After successful reproduce, systemctl list-jobs will list the hang job.
3d81e0
3d81e0
Upsteam:
3d81e0
https://github.com/systemd/systemd/pull/13124
3d81e0
3d81e0
(cherry picked from commit 8ee652948b0255005e4c9d278ac06b30711d9dbd)
3d81e0
3d81e0
Resolves: #1847336
3d81e0
---
3d81e0
 src/core/unit.c | 6 ++++--
3d81e0
 1 file changed, 4 insertions(+), 2 deletions(-)
3d81e0
3d81e0
diff --git a/src/core/unit.c b/src/core/unit.c
3d81e0
index dc2df4c89c..856ebf3e64 100644
3d81e0
--- a/src/core/unit.c
3d81e0
+++ b/src/core/unit.c
3d81e0
@@ -2900,6 +2900,7 @@ static int unit_add_deserialized_job_coldplug(Unit *u) {
3d81e0
 
3d81e0
 int unit_coldplug(Unit *u, Hashmap *deferred_work) {
3d81e0
         int r;
3d81e0
+        Job *uj;
3d81e0
 
3d81e0
         assert(u);
3d81e0
 
3d81e0
@@ -2907,8 +2908,9 @@ int unit_coldplug(Unit *u, Hashmap *deferred_work) {
3d81e0
                 if ((r = UNIT_VTABLE(u)->coldplug(u, deferred_work)) < 0)
3d81e0
                         return r;
3d81e0
 
3d81e0
-        if (u->job) {
3d81e0
-                r = job_coldplug(u->job);
3d81e0
+        uj = u->job ?: u->nop_job;
3d81e0
+        if (uj) {
3d81e0
+                r = job_coldplug(uj);
3d81e0
                 if (r < 0)
3d81e0
                         return r;
3d81e0
         } else if (u->deserialized_job >= 0)