[systemd-devel] [PATCH] core: collapse JOB_RELOAD on an inactive unit into JOB_NOP

Jon Severinsson jon at severinsson.net
Tue Jul 15 19:15:30 PDT 2014


Before this commit systemctl reload on an inactive unit with a queued
start job would block until the unit had started if the unit supported
reload, but return failure immediately if the unit didn't.

Additionally systemctl reload-or-try-restart (and systemctl force-reload)
would block until the unit had started if the unit supported reload, but
return *success* immediately if the unit didn't.

Finaly reload on an inactive unit without a queued start job would
reurn failure, but try-restart on the same job would return success.

This behaviour is unintuitive and inconsistent, so make reload of inactive
units behave just like try-restart.

Also fixes deadlocks on boot if a unit calls systemctl reload,
reload-or-try-restart or force-reload on a unit ordered later
in the boot sequence during startup.
---
 src/core/job.c  | 5 +++++
 src/core/unit.c | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/core/job.c b/src/core/job.c
index dc4f441..ff94f73 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -362,6 +362,11 @@ void job_type_collapse(JobType *t, Unit *u) {
 
         switch (*t) {
 
+        case JOB_RELOAD:
+                s = unit_active_state(u);
+                if (UNIT_IS_INACTIVE_OR_FAILED(s))
+                        *t = JOB_NOP;
+
         case JOB_TRY_RESTART:
                 s = unit_active_state(u);
                 if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s))
diff --git a/src/core/unit.c b/src/core/unit.c
index 0e4ebfd..59ffd49 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1389,12 +1389,15 @@ int unit_reload(Unit *u) {
         if (state == UNIT_RELOADING)
                 return -EALREADY;
 
-        if (state != UNIT_ACTIVE) {
+        if (UNIT_IS_INACTIVE_OR_FAILED(state)) {
                 log_warning_unit(u->id, "Unit %s cannot be reloaded because it is inactive.",
                                  u->id);
                 return -ENOEXEC;
         }
 
+        if (state != UNIT_ACTIVE)
+                return -EAGAIN;
+
         following = unit_following(u);
         if (following) {
                 log_debug_unit(u->id, "Redirecting reload request from %s to %s.",
-- 
2.0.1



More information about the systemd-devel mailing list