Skip to content

id: don't exit 1 when uid/gid name lookup fails in default output#12341

Open
c-tonneslan wants to merge 1 commit into
uutils:mainfrom
c-tonneslan:fix/id-exit-code-name-lookup
Open

id: don't exit 1 when uid/gid name lookup fails in default output#12341
c-tonneslan wants to merge 1 commit into
uutils:mainfrom
c-tonneslan:fix/id-exit-code-name-lookup

Conversation

@c-tonneslan
Copy link
Copy Markdown

Closes #12246.

In a docker container where the current gid doesn't have an entry in /etc/passwd//etc/group, uutils id was printing the fallback numeric value but then exiting 1:

$ id
id: cannot find name for group ID 1234
id: cannot find name for group ID 1234
uid=0(root) gid=1234(1234) groups=1234(1234)
$ echo $?
1

That breaks init scripts that probe identities with plain id. GNU id prints the numeric value and exits 0.

The bug was a set_exit_code(1) call in each of the five lookup sites in the default formatter (uid, gid, euid, egid, groups). Failing to resolve a name isn't an error in the no-flag case, only with -n/--name where the user explicitly asked for a name. The -n paths still set exit 1, matching GNU.

I left the id: cannot find name... warning in place since it's informational; happy to also drop that if you'd prefer the cleaner GNU output.

When running in a container (or anywhere /etc/passwd doesn't have an
entry for the current uid/gid), uutils id was printing the numeric
fallback and exiting 1:

    $ id
    id: cannot find name for group ID 1234
    id: cannot find name for group ID 1234
    uid=0(root) gid=1234(1234) groups=1234(1234)
    $ echo $?
    1

That breaks docker startup scripts that probe with `id`. GNU id
prints the numeric value and exits 0 in that case.

The set_exit_code(1) calls in the default printer are wrong: failing
to name-resolve a uid isn't an error in the no-flag invocation, only
when the user explicitly asked for a name with -n. The five lookup
sites in the default formatter now just fall back to the numeric
string and keep the exit code at 0.

The -n/--name paths still set exit 1 on lookup failure (that's the
documented GNU behavior).

Closes uutils#12246.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@oech3
Copy link
Copy Markdown
Contributor

oech3 commented May 17, 2026

already opened #12252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

id returns wrong exit code when user does not exist

2 participants