diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-04-11 17:57:05 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-04-12 13:43:33 +0200 |
commit | 8e20adcaa0cf06a85d36e2fda35fa1d70d5d63c8 (patch) | |
tree | 6abaead08125a91d851548b06f21bb2b95b18988 | |
parent | d94c2b06f9800d635f3cb05b4a6c67145aa1ba09 (diff) |
core: make sure we generate a nicer error when a linked unit is attempted to be enabled
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.
-rw-r--r-- | src/core/dbus-manager.c | 35 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-common-errors.c | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-common-errors.h | 1 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 2 |
4 files changed, 24 insertions, 15 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 41f27ec26b..0939a55182 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -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); } diff --git a/src/libsystemd/sd-bus/bus-common-errors.c b/src/libsystemd/sd-bus/bus-common-errors.c index f16878cd1a..02e3bf904c 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.c +++ b/src/libsystemd/sd-bus/bus-common-errors.c @@ -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), diff --git a/src/libsystemd/sd-bus/bus-common-errors.h b/src/libsystemd/sd-bus/bus-common-errors.h index c16605ba87..c8f369cb78 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.h +++ b/src/libsystemd/sd-bus/bus-common-errors.h @@ -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" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index b94af9cf08..9efdc63dde 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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"); |