shared/specifier: provide proper error messages when specifiers fail to read files

ENOENT is easily confused with the file that we're working on not being
present, e.g. when the file contains %o or something else that requires
os-release to be present. Let's use -EUNATCH instead to reduce that chances of
confusion if the context of the error is lost.

And once we have pinpointed the reason, let's provide a proper error message:

+ build/systemctl --root=/tmp/systemctl-test.TO7Mcb enable some-some-link6@.socket
/tmp/systemctl-test.TO7Mcb/etc/systemd/system/some-some-link6@.socket: Failed to resolve alias "target@A:%A.socket": Protocol driver not attached
Failed to enable unit, cannot resolve specifiers in "target@A:%A.socket".
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-03-29 16:17:56 +02:00
parent 7962116fc8
commit 6ec4c852c9
4 changed files with 82 additions and 39 deletions
+41 -14
View File
@@ -445,13 +445,46 @@ EOF
check_alias a "$(uname -m | tr '_' '-')"
# FIXME: when os-release is not found, we fail we a cryptic error
# Alias=target@%A.socket
test ! -e "$root/etc/os-release"
test ! -e "$root/usr/lib/os-release"
check_alias A '' && { echo "Expected failure" >&2; exit 1; }
check_alias B '' && { echo "Expected failure" >&2; exit 1; }
check_alias M '' && { echo "Expected failure" >&2; exit 1; }
check_alias o '' && { echo "Expected failure" >&2; exit 1; }
check_alias w '' && { echo "Expected failure" >&2; exit 1; }
check_alias W '' && { echo "Expected failure" >&2; exit 1; }
cat >"$root/etc/os-release" <<EOF
# empty
EOF
check_alias A ''
check_alias B ''
check_alias M ''
check_alias o ''
check_alias w ''
check_alias W ''
cat >"$root/etc/os-release" <<EOF
ID='the-id'
VERSION_ID=39a
BUILD_ID=build-id
VARIANT_ID=wrong
VARIANT_ID=right
IMAGE_ID="foobar"
IMAGE_VERSION='1-2-3'
EOF
check_alias A '1-2-3'
check_alias B 'build-id'
check_alias M 'foobar'
check_alias o 'the-id'
check_alias w '39a'
check_alias W 'right'
check_alias b "$(systemd-id128 boot-id)"
# Alias=target@%B.socket
# FIXME: Failed to enable: Invalid slot.
# Alias=target@%C.socket
# Alias=target@%E.socket
@@ -479,18 +512,15 @@ check_alias l "$(uname -n | sed 's/\..*//')"
# FIXME: Failed to enable: Invalid slot.
# Alias=target@%L.socket
# FIXME: Failed to enable: No such file or directory.
# Alias=target@%m.socket
test ! -e "$root/etc/machine-id"
check_alias m '' && { echo "Expected failure" >&2; exit 1; }
# FIXME: Failed to enable: No such file or directory.
# Alias=target@%M.socket
systemd-id128 new >"$root/etc/machine-id"
check_alias m "$(cat "$root/etc/machine-id")"
check_alias n 'some-some-link6@.socket'
check_alias N 'some-some-link6@'
# FIXME: Failed to enable: No such file or directory.
# Alias=target@%o.socket
check_alias p 'some-some-link6'
# FIXME: Failed to enable: Invalid slot.
@@ -509,9 +539,6 @@ check_alias v "$(uname -r)"
# FIXME: Failed to enable: Invalid slot.
# Alias=target@%V.socket
# Alias=target@%w.socket
# Alias=target@%W.socket
check_alias % '%' && { echo "Expected failure because % is not legal in unit name" >&2; exit 1; }
check_alias z 'z' && { echo "Expected failure because %z is not known" >&2; exit 1; }