]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: make sure we generate a nicer error when a linked unit is attempted to be enabled
authorLennart Poettering <lennart@poettering.net>
Mon, 11 Apr 2016 15:57:05 +0000 (17:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2016 11:43:33 +0000 (13:43 +0200)
We don't allow using config symlinks to enable units, but the error message we
printed was awful. Fix that, and generate a more readable error.

Fixes #3010.

src/core/dbus-manager.c
src/libsystemd/sd-bus/bus-common-errors.c
src/libsystemd/sd-bus/bus-common-errors.h
src/systemctl/systemctl.c

index 41f27ec26bb1e6fe85dab1631278c586b3d3ade7..0939a5518216c8c2f2503466b1c324ecf46b93bb 100644 (file)
@@ -1607,6 +1607,19 @@ fail:
         return r;
 }
 
+static int install_error(sd_bus_error *error, int c) {
+        assert(c < 0);
+
+        if (c == -ESHUTDOWN)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
+        if (c == -EADDRNOTAVAIL)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is transient or generated.");
+        if (c == -ELOOP)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_LINKED, "Refusing to operate on linked unit file.");
+
+        return c;
+}
+
 static int method_enable_unit_files_generic(
                 sd_bus_message *message,
                 Manager *m,
@@ -1638,12 +1651,8 @@ static int method_enable_unit_files_generic(
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
         r = call(m->unit_file_scope, runtime, NULL, l, force, &changes, &n_changes);
-        if (r == -ESHUTDOWN)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
-        if (r == -EADDRNOTAVAIL)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is transient or generated.");
         if (r < 0)
-                return r;
+                return install_error(error, r);
 
         return reply_unit_file_changes_and_free(m, message, carries_install_info ? r : -1, changes, n_changes);
 }
@@ -1709,7 +1718,7 @@ static int method_preset_unit_files_with_mode(sd_bus_message *message, void *use
 
         r = unit_file_preset(m->unit_file_scope, runtime, NULL, l, mm, force, &changes, &n_changes);
         if (r < 0)
-                return r;
+                return install_error(error, r);
 
         return reply_unit_file_changes_and_free(m, message, r, changes, n_changes);
 }
@@ -1745,7 +1754,7 @@ static int method_disable_unit_files_generic(
 
         r = call(m->unit_file_scope, runtime, NULL, l, &changes, &n_changes);
         if (r < 0)
-                return r;
+                return install_error(error, r);
 
         return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes);
 }
@@ -1780,7 +1789,7 @@ static int method_revert_unit_files(sd_bus_message *message, void *userdata, sd_
 
         r = unit_file_revert(m->unit_file_scope, NULL, l, &changes, &n_changes);
         if (r < 0)
-                return r;
+                return install_error(error, r);
 
         return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes);
 }
@@ -1811,7 +1820,7 @@ static int method_set_default_target(sd_bus_message *message, void *userdata, sd
 
         r = unit_file_set_default(m->unit_file_scope, NULL, name, force, &changes, &n_changes);
         if (r < 0)
-                return r;
+                return install_error(error, r);
 
         return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes);
 }
@@ -1852,7 +1861,7 @@ static int method_preset_all_unit_files(sd_bus_message *message, void *userdata,
         r = unit_file_preset_all(m->unit_file_scope, runtime, NULL, mm, force, &changes, &n_changes);
         if (r < 0) {
                 unit_file_changes_free(changes, n_changes);
-                return r;
+                return install_error(error, r);
         }
 
         return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes);
@@ -1890,12 +1899,8 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
                 return -EINVAL;
 
         r = unit_file_add_dependency(m->unit_file_scope, runtime, NULL, l, target, dep, force, &changes, &n_changes);
-        if (r == -ESHUTDOWN)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked.");
-        if (r == -EADDRNOTAVAIL)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_GENERATED, "Unit file is transient or generated.");
         if (r < 0)
-                return r;
+                return install_error(error, r);
 
         return reply_unit_file_changes_and_free(m, message, -1, changes, n_changes);
 }
index f16878cd1a6c2fa0e69055588a6f975d33c236d8..02e3bf904c8623b1853990ac7761415eb29c4491 100644 (file)
@@ -39,6 +39,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = {
         SD_BUS_ERROR_MAP(BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE,   EDEADLK),
         SD_BUS_ERROR_MAP(BUS_ERROR_UNIT_MASKED,                  ESHUTDOWN),
         SD_BUS_ERROR_MAP(BUS_ERROR_UNIT_GENERATED,               EADDRNOTAVAIL),
+        SD_BUS_ERROR_MAP(BUS_ERROR_UNIT_LINKED,                  ELOOP),
         SD_BUS_ERROR_MAP(BUS_ERROR_JOB_TYPE_NOT_APPLICABLE,      EBADR),
         SD_BUS_ERROR_MAP(BUS_ERROR_NO_ISOLATION,                 EPERM),
         SD_BUS_ERROR_MAP(BUS_ERROR_SHUTTING_DOWN,                ECANCELED),
index c16605ba8722375ddf8a6bc0d6e951509a5c1473..c8f369cb78b6b73c8560e3bfc666dada47b6c91d 100644 (file)
@@ -35,6 +35,7 @@
 #define BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE "org.freedesktop.systemd1.TransactionIsDestructive"
 #define BUS_ERROR_UNIT_MASKED "org.freedesktop.systemd1.UnitMasked"
 #define BUS_ERROR_UNIT_GENERATED "org.freedesktop.systemd1.UnitGenerated"
+#define BUS_ERROR_UNIT_LINKED "org.freedesktop.systemd1.UnitLinked"
 #define BUS_ERROR_JOB_TYPE_NOT_APPLICABLE "org.freedesktop.systemd1.JobTypeNotApplicable"
 #define BUS_ERROR_NO_ISOLATION "org.freedesktop.systemd1.NoIsolation"
 #define BUS_ERROR_SHUTTING_DOWN "org.freedesktop.systemd1.ShuttingDown"
index b94af9cf084209092718d7a6b453a7d8221c68e9..9efdc63dde71f6f0818f70e56bd9af75d6231934 100644 (file)
@@ -5446,6 +5446,8 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
                         return log_error_errno(r, "Unit file is masked.");
                 if (r == -EADDRNOTAVAIL)
                         return log_error_errno(r, "Unit file is transient or generated.");
+                if (r == -ELOOP)
+                        return log_error_errno(r, "Refusing to operate on linked unit file.");
                 if (r < 0)
                         return log_error_errno(r, "Operation failed: %m");