ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
65878a
From b659126834756a4476a5b020bcece486be1edb85 Mon Sep 17 00:00:00 2001
65878a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
65878a
Date: Mon, 2 Dec 2013 21:52:51 -0500
65878a
Subject: [PATCH] systemd: treat reload failure as failure
65878a
65878a
systemctl reload "suceeded" on stopped units, but it is documented
65878a
to fail in this case.
65878a
65878a
https://bugzilla.redhat.com/show_bug.cgi?id=1036845
65878a
---
65878a
 src/core/job.c  | 11 +++++++----
65878a
 src/core/job.h  |  3 ++-
65878a
 src/core/unit.c |  5 ++++-
65878a
 3 files changed, 13 insertions(+), 6 deletions(-)
65878a
65878a
diff --git a/src/core/job.c b/src/core/job.c
65878a
index bf1d956..5ea9803 100644
65878a
--- a/src/core/job.c
65878a
+++ b/src/core/job.c
65878a
@@ -528,7 +528,7 @@ int job_run_and_invalidate(Job *j) {
65878a
                         else if (t == UNIT_ACTIVATING)
65878a
                                 r = -EAGAIN;
65878a
                         else
65878a
-                                r = -ENOEXEC;
65878a
+                                r = -EBADR;
65878a
                         break;
65878a
                 }
65878a
 
65878a
@@ -557,8 +557,10 @@ int job_run_and_invalidate(Job *j) {
65878a
         if (j) {
65878a
                 if (r == -EALREADY)
65878a
                         r = job_finish_and_invalidate(j, JOB_DONE, true);
65878a
-                else if (r == -ENOEXEC)
65878a
+                else if (r == -EBADR)
65878a
                         r = job_finish_and_invalidate(j, JOB_SKIPPED, true);
65878a
+                else if (r == -ENOEXEC)
65878a
+                        r = job_finish_and_invalidate(j, JOB_INVALID, true);
65878a
                 else if (r == -EAGAIN) {
65878a
                         j->state = JOB_WAITING;
65878a
                         m->n_running_jobs--;
65878a
@@ -784,7 +786,7 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
65878a
                 goto finish;
65878a
         }
65878a
 
65878a
-        if (result == JOB_FAILED)
65878a
+        if (result == JOB_FAILED || result == JOB_INVALID)
65878a
                 j->manager->n_failed_jobs ++;
65878a
 
65878a
         job_uninstall(j);
65878a
@@ -1140,7 +1142,8 @@ static const char* const job_result_table[_JOB_RESULT_MAX] = {
65878a
         [JOB_TIMEOUT] = "timeout",
65878a
         [JOB_FAILED] = "failed",
65878a
         [JOB_DEPENDENCY] = "dependency",
65878a
-        [JOB_SKIPPED] = "skipped"
65878a
+        [JOB_SKIPPED] = "skipped",
65878a
+        [JOB_INVALID] = "invalid",
65878a
 };
65878a
 
65878a
 DEFINE_STRING_TABLE_LOOKUP(job_result, JobResult);
65878a
diff --git a/src/core/job.h b/src/core/job.h
65878a
index d90bc96..4237529 100644
65878a
--- a/src/core/job.h
65878a
+++ b/src/core/job.h
65878a
@@ -97,7 +97,8 @@ enum JobResult {
65878a
         JOB_TIMEOUT,             /* JobTimeout elapsed */
65878a
         JOB_FAILED,              /* Job failed */
65878a
         JOB_DEPENDENCY,          /* A required dependency job did not result in JOB_DONE */
65878a
-        JOB_SKIPPED,             /* JOB_RELOAD of inactive unit; negative result of JOB_VERIFY_ACTIVE */
65878a
+        JOB_SKIPPED,             /* Negative result of JOB_VERIFY_ACTIVE */
65878a
+        JOB_INVALID,             /* JOB_RELOAD of inactive unit */
65878a
         _JOB_RESULT_MAX,
65878a
         _JOB_RESULT_INVALID = -1
65878a
 };
65878a
diff --git a/src/core/unit.c b/src/core/unit.c
65878a
index 1db7d06..0f57b06 100644
65878a
--- a/src/core/unit.c
65878a
+++ b/src/core/unit.c
65878a
@@ -1239,8 +1239,11 @@ int unit_reload(Unit *u) {
65878a
         if (state == UNIT_RELOADING)
65878a
                 return -EALREADY;
65878a
 
65878a
-        if (state != UNIT_ACTIVE)
65878a
+        if (state != UNIT_ACTIVE) {
65878a
+                log_warning_unit(u->id, "Unit %s cannot be reloaded because it is inactive.",
65878a
+                                 u->id);
65878a
                 return -ENOEXEC;
65878a
+        }
65878a
 
65878a
         if ((following = unit_following(u))) {
65878a
                 log_debug_unit(u->id, "Redirecting reload request from %s to %s.",