specifier: return -EUNATCH for user and group specifiers in global scope

%u, %U, %g and %G have nothing to resolve to in the global scope, and
failed with -EINVAL. Install code already treats -EUNATCH as "cannot
resolve specifiers": it is listed in ERRNO_IS_NEG_UNIT_ISSUE() and
install_change_dump_error() turns it into a proper message. With
-EINVAL, "systemctl --global enable" of a unit using these specifiers
only reported "Invalid argument".

Return -EUNATCH instead, like the machine-id and os-release
specifiers already do when their source is missing. Only the install
code uses these specifiers in the global scope.

(cherry picked from commit 03ce9bcff23d07751dc6911c7963e3bde9e780c2)
This commit is contained in:
Daan De Meyer
2026-10-16 11:36:32 +01:00
committed by Luca Boccassi
parent cb8fffda7d
commit d14b9ace0c
+4 -4
View File
@@ -304,7 +304,7 @@ int specifier_group_name(char specifier, const void *data, const char *root, con
assert(ret);
if (scope == RUNTIME_SCOPE_GLOBAL)
return -EINVAL;
return -EUNATCH;
t = gid_to_name(scope == RUNTIME_SCOPE_USER ? getgid() : 0);
if (!t)
@@ -321,7 +321,7 @@ int specifier_group_id(char specifier, const void *data, const char *root, const
assert(ret);
if (scope == RUNTIME_SCOPE_GLOBAL)
return -EINVAL;
return -EUNATCH;
gid = scope == RUNTIME_SCOPE_USER ? getgid() : 0;
@@ -339,7 +339,7 @@ int specifier_user_name(char specifier, const void *data, const char *root, cons
assert(ret);
if (scope == RUNTIME_SCOPE_GLOBAL)
return -EINVAL;
return -EUNATCH;
uid = scope == RUNTIME_SCOPE_USER ? getuid() : 0;
@@ -365,7 +365,7 @@ int specifier_user_id(char specifier, const void *data, const char *root, const
assert(ret);
if (scope == RUNTIME_SCOPE_GLOBAL)
return -EINVAL;
return -EUNATCH;
uid = scope == RUNTIME_SCOPE_USER ? getuid() : 0;