shared/install: provide a nicer error message for invalid WantedBy=/Required= values
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 13 Dec 2019 17:36:29 +0000 (18:36 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 Feb 2020 16:19:06 +0000 (17:19 +0100)
$ build/systemctl --user cat badinstall
 # /home/zbyszek/.config/systemd/user/badinstall.service
[Service]
ExecStart=true

[Install]
WantedBy=asdf

$ build/systemctl --user enable badinstall
Failed to enable unit: "asdf" is not a valid unit name.

Fixes #4209.

(cherry picked from commit d7ceaf72618aa2466fc4465ce8fcebf0cba68cc1)
(cherry picked from commit d2471109d99912de5cf50fd060295d4ddf681027)

src/core/dbus-manager.c
src/shared/install.c

index 98d2e828a3fd54f9e85c903d86aaea3e85cdcf5b..d8cb5180afb4b3475a782fbf60c1d8df9d6923c3 100644 (file)
@@ -1901,6 +1901,12 @@ static int install_error(
                                               "Unit %s is transient or generated.", changes[i].path);
                         goto found;
 
+                case -EUCLEAN:
+                        r = sd_bus_error_setf(error, BUS_ERROR_BAD_UNIT_SETTING,
+                                              "\"%s\" is not a valid unit name.",
+                                              changes[i].path);
+                        goto found;
+
                 case -ELOOP:
                         r = sd_bus_error_setf(error, BUS_ERROR_UNIT_LINKED,
                                               "Refusing to operate on alias name or linked unit file: %s",
index 17f6f99f29542b0eafbfb99b911e57484be2f47b..c43c9823634170db04247828a2ee6ec9b000eac9 100644 (file)
@@ -365,6 +365,12 @@ void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *chang
                                         verb, changes[i].path);
                         logged = true;
                         break;
+                case -EUCLEAN:
+                        log_error_errno(changes[i].type,
+                                        "Failed to %s unit, \"%s\" is not a valid unit name.",
+                                        verb, changes[i].path);
+                        logged = true;
+                        break;
                 case -ELOOP:
                         log_error_errno(changes[i].type, "Failed to %s unit, refusing to operate on linked unit file %s",
                                         verb, changes[i].path);
@@ -1788,7 +1794,8 @@ static int install_info_symlink_wants(
                         return q;
 
                 if (!unit_name_is_valid(dst, UNIT_NAME_ANY)) {
-                        r = -EINVAL;
+                        unit_file_changes_add(changes, n_changes, -EUCLEAN, dst, NULL);
+                        r = -EUCLEAN;
                         continue;
                 }