richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a9339c
From f7507f4bb5385ed0303451d812d220f14f341629 Mon Sep 17 00:00:00 2001
a9339c
From: Lennart Poettering <lennart@poettering.net>
a9339c
Date: Thu, 28 Jan 2016 18:48:42 +0100
a9339c
Subject: [PATCH] core: make sure "systemctl reload-or-try-restart is actually
a9339c
 a noop if a unit is not running
a9339c
a9339c
This makes sure we follow the same basic logic for try-restart if we have a try-reload.
a9339c
a9339c
Fixes #688
a9339c
a9339c
(cherry picked from commit 3282591dc30b2934a895c7403d2f0b0690260947)
a9339c
Resolves: #1191920
a9339c
---
a9339c
 src/core/dbus-unit.c | 2 +-
a9339c
 src/core/job.c       | 8 ++++++++
a9339c
 src/core/job.h       | 3 +++
a9339c
 src/core/unit.c      | 2 ++
a9339c
 4 files changed, 14 insertions(+), 1 deletion(-)
a9339c
a9339c
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
a9339c
index 1d0d6f67c..f0f75e01b 100644
a9339c
--- a/src/core/dbus-unit.c
a9339c
+++ b/src/core/dbus-unit.c
a9339c
@@ -850,7 +850,7 @@ int bus_unit_queue_job(
a9339c
                 if (type == JOB_RESTART)
a9339c
                         type = JOB_RELOAD_OR_START;
a9339c
                 else if (type == JOB_TRY_RESTART)
a9339c
-                        type = JOB_RELOAD;
a9339c
+                        type = JOB_TRY_RELOAD;
a9339c
         }
a9339c
 
a9339c
         r = mac_selinux_unit_access_check(
a9339c
diff --git a/src/core/job.c b/src/core/job.c
a9339c
index 1617e24c0..c9a43a4cb 100644
a9339c
--- a/src/core/job.c
a9339c
+++ b/src/core/job.c
a9339c
@@ -404,6 +404,13 @@ JobType job_type_collapse(JobType t, Unit *u) {
a9339c
 
a9339c
                 return JOB_RESTART;
a9339c
 
a9339c
+        case JOB_TRY_RELOAD:
a9339c
+                s = unit_active_state(u);
a9339c
+                if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s))
a9339c
+                        return JOB_NOP;
a9339c
+
a9339c
+                return JOB_RELOAD;
a9339c
+
a9339c
         case JOB_RELOAD_OR_START:
a9339c
                 s = unit_active_state(u);
a9339c
                 if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s))
a9339c
@@ -1212,6 +1219,7 @@ static const char* const job_type_table[_JOB_TYPE_MAX] = {
a9339c
         [JOB_RELOAD_OR_START] = "reload-or-start",
a9339c
         [JOB_RESTART] = "restart",
a9339c
         [JOB_TRY_RESTART] = "try-restart",
a9339c
+        [JOB_TRY_RELOAD] = "try-reload",
a9339c
         [JOB_NOP] = "nop",
a9339c
 };
a9339c
 
a9339c
diff --git a/src/core/job.h b/src/core/job.h
a9339c
index ce81607de..535052b48 100644
a9339c
--- a/src/core/job.h
a9339c
+++ b/src/core/job.h
a9339c
@@ -63,6 +63,9 @@ enum JobType {
a9339c
          * Thus we never need to merge it with anything. */
a9339c
         JOB_TRY_RESTART = _JOB_TYPE_MAX_IN_TRANSACTION, /* if running, stop and then start */
a9339c
 
a9339c
+        /* Similar to JOB_TRY_RESTART but collapses to JOB_RELOAD or JOB_NOP */
a9339c
+        JOB_TRY_RELOAD,
a9339c
+
a9339c
         /* JOB_RELOAD_OR_START won't enter into a transaction and cannot result
a9339c
          * from transaction merging (there's no way for JOB_RELOAD and
a9339c
          * JOB_START to meet in one transaction). It can result from a merge
a9339c
diff --git a/src/core/unit.c b/src/core/unit.c
a9339c
index 41d7b63d7..6d535ae12 100644
a9339c
--- a/src/core/unit.c
a9339c
+++ b/src/core/unit.c
a9339c
@@ -1868,6 +1868,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
a9339c
 
a9339c
                 case JOB_RELOAD:
a9339c
                 case JOB_RELOAD_OR_START:
a9339c
+                case JOB_TRY_RELOAD:
a9339c
 
a9339c
                         if (u->job->state == JOB_RUNNING) {
a9339c
                                 if (ns == UNIT_ACTIVE)
a9339c
@@ -2144,6 +2145,7 @@ bool unit_job_is_applicable(Unit *u, JobType j) {
a9339c
                 return unit_can_start(u);
a9339c
 
a9339c
         case JOB_RELOAD:
a9339c
+        case JOB_TRY_RELOAD:
a9339c
                 return unit_can_reload(u);
a9339c
 
a9339c
         case JOB_RELOAD_OR_START: