1abbee
From a47b58110f92415fcb69441031e4d04fec48b852 Mon Sep 17 00:00:00 2001
1abbee
From: Franck Bui <fbui@suse.com>
1abbee
Date: Wed, 2 Dec 2015 17:03:28 +0100
1abbee
Subject: [PATCH] core: use bus_unit_check_load_state() in
1abbee
 transaction_add_job_and_dependencies()
1abbee
1abbee
(cherry picked from commit ee87525c5eeacf3ce8fb730bcd3658e8da085046)
1abbee
Related: #1256858
1abbee
---
1abbee
 src/core/transaction.c    | 27 +++++----------------------
1abbee
 src/systemctl/systemctl.c |  5 +++++
1abbee
 2 files changed, 10 insertions(+), 22 deletions(-)
1abbee
1abbee
diff --git a/src/core/transaction.c b/src/core/transaction.c
181b3f
index aed64fa41..57e9cb3f8 100644
1abbee
--- a/src/core/transaction.c
1abbee
+++ b/src/core/transaction.c
1abbee
@@ -26,6 +26,7 @@
1abbee
 #include "bus-util.h"
1abbee
 #include "bus-error.h"
1abbee
 #include "transaction.h"
1abbee
+#include "dbus-unit.h"
1abbee
 
1abbee
 static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
1abbee
 
1abbee
@@ -857,30 +858,12 @@ int transaction_add_job_and_dependencies(
1abbee
                 return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
1abbee
                                          "Unit %s is not loaded properly.", unit->id);
1abbee
 
1abbee
-        if (type != JOB_STOP && unit->load_state == UNIT_ERROR) {
1abbee
-                if (unit->load_error == -ENOENT || unit->manager->test_run)
1abbee
-                        return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
1abbee
-                                                 "Unit %s failed to load: %s.",
1abbee
-                                                 unit->id,
1abbee
-                                                 strerror(-unit->load_error));
1abbee
-                else
1abbee
-                        return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
1abbee
-                                                 "Unit %s failed to load: %s. "
1abbee
-                                                 "See system logs and 'systemctl status %s' for details.",
1abbee
-                                                 unit->id,
1abbee
-                                                 strerror(-unit->load_error),
1abbee
-                                                 unit->id);
1abbee
+        if (type != JOB_STOP) {
1abbee
+                r = bus_unit_check_load_state(unit, e);
1abbee
+                if (r < 0)
1abbee
+                        return r;
1abbee
         }
1abbee
 
1abbee
-        if (type != JOB_STOP && unit->load_state == UNIT_NOT_FOUND)
1abbee
-                return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
1abbee
-                                         "Unit %s failed to load: %s.",
1abbee
-                                         unit->id, strerror(-unit->load_error));
1abbee
-
1abbee
-        if (type != JOB_STOP && unit->load_state == UNIT_MASKED)
1abbee
-                return sd_bus_error_setf(e, BUS_ERROR_UNIT_MASKED,
1abbee
-                                         "Unit %s is masked.", unit->id);
1abbee
-
1abbee
         if (!unit_job_is_applicable(unit, type))
1abbee
                 return sd_bus_error_setf(e, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE,
1abbee
                                          "Job type %s is not applicable for unit %s.",
1abbee
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
181b3f
index 58998185c..e4b404abc 100644
1abbee
--- a/src/systemctl/systemctl.c
1abbee
+++ b/src/systemctl/systemctl.c
1abbee
@@ -2617,6 +2617,11 @@ static int start_unit_one(
1abbee
                 verb = method_to_verb(method);
1abbee
 
1abbee
                 log_error("Failed to %s %s: %s", verb, name, bus_error_message(error, r));
1abbee
+
1abbee
+                if (!sd_bus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT) &&
1abbee
+                    !sd_bus_error_has_name(error, BUS_ERROR_UNIT_MASKED))
1abbee
+                        log_error("See system logs and 'systemctl status %s' for details.", name);
1abbee
+
1abbee
                 return r;
1abbee
         }
1abbee