diff --git a/src/shared/install.c b/src/shared/install.c index 332c146710..554c530cc4 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1794,20 +1794,22 @@ static int install_info_symlink_alias( q = install_name_printf(scope, info, *s, info->root, &dst); if (q < 0) { unit_file_changes_add(changes, n_changes, q, *s, NULL); - return q; + r = r < 0 ? r : q; + continue; } q = unit_file_verify_alias(info, dst, &dst_updated, changes, n_changes); - if (q < 0) + if (q < 0) { + r = r < 0 ? r : q; continue; + } alias_path = path_make_absolute(dst_updated ?: dst, config_path); if (!alias_path) return -ENOMEM; q = create_symlink(lp, info->path, alias_path, force, changes, n_changes); - if (r == 0) - r = q; + r = r < 0 ? r : q; } return r; diff --git a/test/test-systemctl-enable.sh b/test/test-systemctl-enable.sh index 8ac1342b91..32bc6e5ef7 100644 --- a/test/test-systemctl-enable.sh +++ b/test/test-systemctl-enable.sh @@ -56,19 +56,27 @@ test ! -e "$root/etc/systemd/system/default.target.wants/test1.service" test ! -e "$root/etc/systemd/system/special.target.requires/test1.service" : -------aliases---------------------------------------------- -"$systemctl" --root="$root" enable test1 -test -h "$root/etc/systemd/system/default.target.wants/test1.service" -test -h "$root/etc/systemd/system/special.target.requires/test1.service" - cat >>"$root/etc/systemd/system/test1.service" <&2; exit 1; } +test -h "$root/etc/systemd/system/default.target.wants/test1.service" +test -h "$root/etc/systemd/system/special.target.requires/test1.service" +test ! -e "$root/etc/systemd/system/test1-goodalias.service" +test -h "$root/etc/systemd/system/test1-goodalias.service" +test ! -e "$root/etc/systemd/system/test1@badalias.service" +test ! -e "$root/etc/systemd/system/test1-badalias.target" +test ! -e "$root/etc/systemd/system/test1-badalias.socket" +test -h "$root/etc/systemd/system/test1-goodalias2.service" + : -------aliases in reeanble---------------------------------- -"$systemctl" --root="$root" reenable test1 +"$systemctl" --root="$root" reenable test1 && { echo "Expected failure" >&2; exit 1; } test -h "$root/etc/systemd/system/default.target.wants/test1.service" test ! -e "$root/etc/systemd/system/test1-goodalias.service" test -h "$root/etc/systemd/system/test1-goodalias.service" @@ -328,7 +336,7 @@ Alias=link4alias.service Alias=link4alias2.service EOF -"$systemctl" --root="$root" enable 'link4.service' +"$systemctl" --root="$root" enable 'link4.service' && { echo "Expected failure" >&2; exit 1; } test ! -h "$root/etc/systemd/system/link4.service" # this is our file test ! -h "$root/etc/systemd/system/link4@.service" test ! -h "$root/etc/systemd/system/link4@inst.service" @@ -343,18 +351,20 @@ test ! -h "$root/etc/systemd/system/link4alias.service" test ! -h "$root/etc/systemd/system/link4alias2.service" : -------systemctl enable on path to unit file---------------- +cat >"$root/etc/systemd/system/link4.service" <"$root/etc/systemd/system/link5.service" <&2; exit 1; } -# FIXME: if there's an invalid Alias=, we shouldn't preach about empty [Install] - # TODO: repeat the tests above for presets : -------SYSTEMD_OS_RELEASE relative to root------------------