summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-11 17:57:05 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:33 +0200
commit8e20adcaa0cf06a85d36e2fda35fa1d70d5d63c8 (patch)
tree6abaead08125a91d851548b06f21bb2b95b18988 /src/core
parentd94c2b06f9800d635f3cb05b4a6c67145aa1ba09 (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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/dbus-manager.c35
1 files changed, 20 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);
}