mirror of
https://github.com/systemd/systemd.git
synced 2025-03-09 12:58:26 +03:00
shared/install: provide proper error messages when invalid specifiers are used
$ build/systemctl --root=/tmp/systemctl-test.KXY8fu enable some-some-link6@.socket Failed to enable unit, invalid specifier in "target@C:%C.socket".
This commit is contained in:
parent
6ec4c852c9
commit
19b9d5d0d1
@ -374,12 +374,16 @@ void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *chang
|
||||
verb, changes[i].path);
|
||||
logged = true;
|
||||
break;
|
||||
|
||||
case -EADDRNOTAVAIL:
|
||||
log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is transient or generated.",
|
||||
verb, changes[i].path);
|
||||
logged = true;
|
||||
break;
|
||||
case -EBADSLT:
|
||||
log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid specifier in \"%s\".",
|
||||
verb, changes[i].path);
|
||||
logged = true;
|
||||
break;
|
||||
case -EIDRM:
|
||||
log_error_errno(changes[i].type_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.",
|
||||
verb, changes[i].source, changes[i].path);
|
||||
@ -396,18 +400,15 @@ void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *chang
|
||||
verb, changes[i].path);
|
||||
logged = true;
|
||||
break;
|
||||
|
||||
case -ENOENT:
|
||||
log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s does not exist.", verb, changes[i].path);
|
||||
logged = true;
|
||||
break;
|
||||
|
||||
case -EUNATCH:
|
||||
log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
|
||||
verb, changes[i].path);
|
||||
logged = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(changes[i].type_or_errno < 0);
|
||||
log_error_errno(changes[i].type_or_errno, "Failed to %s unit, file \"%s\": %m",
|
||||
@ -3318,7 +3319,7 @@ int unit_file_preset_all(
|
||||
|
||||
r = preset_prepare_one(scope, &plus, &minus, &lp, de->d_name, &presets, changes, n_changes);
|
||||
if (r < 0 &&
|
||||
!IN_SET(r, -EEXIST, -ERFKILL, -EADDRNOTAVAIL, -EIDRM, -EUCLEAN, -ELOOP, -ENOENT, -EUNATCH))
|
||||
!IN_SET(r, -EEXIST, -ERFKILL, -EADDRNOTAVAIL, -EBADSLT, -EIDRM, -EUCLEAN, -ELOOP, -ENOENT, -EUNATCH))
|
||||
/* Ignore generated/transient/missing/invalid units when applying preset, propagate other errors.
|
||||
* Coordinate with unit_file_dump_changes() above. */
|
||||
return r;
|
||||
|
@ -485,33 +485,31 @@ check_alias W 'right'
|
||||
|
||||
check_alias b "$(systemd-id128 boot-id)"
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%C.socket
|
||||
# Alias=target@%E.socket
|
||||
# Alias=target@%f.socket
|
||||
# Specifiers not available for [Install]
|
||||
check_alias C '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias E '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias f '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias h '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias I '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias J '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias L '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias P '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias s '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias S '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias t '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias T '' && { echo "Expected failure" >&2; exit 1; }
|
||||
check_alias V '' && { echo "Expected failure" >&2; exit 1; }
|
||||
|
||||
# FIXME: we use the calling user instead of root :(
|
||||
check_alias g root || :
|
||||
check_alias G 0 || :
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%h.socket
|
||||
|
||||
check_alias i ""
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%I.socket
|
||||
|
||||
check_alias j 'link6'
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%J.socket
|
||||
|
||||
check_alias l "$(uname -n | sed 's/\..*//')"
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%L.socket
|
||||
|
||||
test ! -e "$root/etc/machine-id"
|
||||
check_alias m '' && { echo "Expected failure" >&2; exit 1; }
|
||||
|
||||
@ -523,22 +521,12 @@ check_alias N 'some-some-link6@'
|
||||
|
||||
check_alias p 'some-some-link6'
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%P.socket
|
||||
# Alias=target@%s.socket
|
||||
# Alias=target@%S.socket
|
||||
# Alias=target@%t.socket
|
||||
# Alias=target@%T.socket
|
||||
|
||||
# FIXME: we use the calling user instead of root :(
|
||||
check_alias u root || :
|
||||
check_alias U 0 || :
|
||||
|
||||
check_alias v "$(uname -r)"
|
||||
|
||||
# FIXME: Failed to enable: Invalid slot.
|
||||
# Alias=target@%V.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; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user