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