summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-24 16:02:48 +0100
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:29 +0200
commit7bfe3d44d008f46d65ebdf5adc0c847b45fd4ab2 (patch)
treeeb9cc09f0cf1c6bddc4b33fe3272a4145d5c1012 /src
parentf413930863ab3b98cb7bf9e761081b4e88a5d7d9 (diff)
core: when enabling a generated unit file, return a clean error
Let's be precise when the user tries to invoke an "enable" operation on a generated unit file.
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus-manager.c8
-rw-r--r--src/libsystemd/sd-bus/bus-common-errors.c1
-rw-r--r--src/libsystemd/sd-bus/bus-common-errors.h1
-rw-r--r--src/shared/install.c10
-rw-r--r--src/systemctl/systemctl.c4
5 files changed, 22 insertions, 2 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 739bd14b9e..e187e19d03 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1648,7 +1648,9 @@ static int method_enable_unit_files_generic(
r = call(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");
+ 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 generated.");
if (r < 0)
return r;
@@ -1886,7 +1888,9 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
r = unit_file_add_dependency(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");
+ 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 generated.");
if (r < 0)
return r;
diff --git a/src/libsystemd/sd-bus/bus-common-errors.c b/src/libsystemd/sd-bus/bus-common-errors.c
index 6370061daf..f16878cd1a 100644
--- a/src/libsystemd/sd-bus/bus-common-errors.c
+++ b/src/libsystemd/sd-bus/bus-common-errors.c
@@ -38,6 +38,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = {
SD_BUS_ERROR_MAP(BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, EDEADLK),
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_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 464834979a..c16605ba87 100644
--- a/src/libsystemd/sd-bus/bus-common-errors.h
+++ b/src/libsystemd/sd-bus/bus-common-errors.h
@@ -34,6 +34,7 @@
#define BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC "org.freedesktop.systemd1.TransactionOrderIsCyclic"
#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_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/shared/install.c b/src/shared/install.c
index 202d16e129..1e497d1492 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1761,6 +1761,8 @@ int unit_file_add_dependency(
return r;
if (target_info->type == UNIT_FILE_TYPE_MASKED)
return -ESHUTDOWN;
+ if (unit_file_is_generated(&paths, target_info->path))
+ return -EADDRNOTAVAIL;
assert(target_info->type == UNIT_FILE_TYPE_REGULAR);
@@ -1772,6 +1774,8 @@ int unit_file_add_dependency(
return r;
if (i->type == UNIT_FILE_TYPE_MASKED)
return -ESHUTDOWN;
+ if (unit_file_is_generated(&paths, i->path))
+ return -EADDRNOTAVAIL;
assert(i->type == UNIT_FILE_TYPE_REGULAR);
@@ -1830,6 +1834,8 @@ int unit_file_enable(
return r;
if (i->type == UNIT_FILE_TYPE_MASKED)
return -ESHUTDOWN;
+ if (unit_file_is_generated(&paths, i->path))
+ return -EADDRNOTAVAIL;
assert(i->type == UNIT_FILE_TYPE_REGULAR);
}
@@ -1957,6 +1963,8 @@ int unit_file_set_default(
return r;
if (i->type == UNIT_FILE_TYPE_MASKED)
return -ESHUTDOWN;
+ if (unit_file_is_generated(&paths, i->path))
+ return -EADDRNOTAVAIL;
path = strjoina(config_path, "/" SPECIAL_DEFAULT_TARGET);
@@ -2254,6 +2262,8 @@ static int preset_prepare_one(
if (i->type == UNIT_FILE_TYPE_MASKED)
return -ESHUTDOWN;
+ if (unit_file_is_generated(paths, i->path))
+ return -EADDRNOTAVAIL;
} else
r = install_info_discover(scope, minus, root_dir, paths, name, SEARCH_FOLLOW_CONFIG_SYMLINKS, &i);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 6394b4749e..4103a5da6d 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5473,6 +5473,8 @@ static int enable_unit(int argc, char *argv[], void *userdata) {
if (r == -ESHUTDOWN)
return log_error_errno(r, "Unit file is masked.");
+ if (r == -EADDRNOTAVAIL)
+ return log_error_errno(r, "Unit file is generated.");
if (r < 0)
return log_error_errno(r, "Operation failed: %m");
@@ -5639,6 +5641,8 @@ static int add_dependency(int argc, char *argv[], void *userdata) {
r = unit_file_add_dependency(arg_scope, arg_runtime, arg_root, names, target, dep, arg_force, &changes, &n_changes);
if (r == -ESHUTDOWN)
return log_error_errno(r, "Unit file is masked.");
+ if (r == -EADDRNOTAVAIL)
+ return log_error_errno(r, "Unit file is generated.");
if (r < 0)
return log_error_errno(r, "Can't add dependency: %m");