From 1ef40f182ea2e92908a8567fc584997da10cfa3f Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sat, 16 May 2026 19:59:49 -0400 Subject: [PATCH] id: don't exit 1 when uid/gid name lookup fails in default 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 #12246. Signed-off-by: Charlie Tonneslan --- src/uu/id/src/id.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 24b80e8eb41..671cc1f57bb 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -638,6 +638,10 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { let mut lock = io::stdout().lock(); + // Name lookup failures in the default output are non-fatal: GNU `id` + // happily prints just the numeric id and exits 0. Docker containers + // routinely run as uids that don't have a /etc/passwd entry, and exit + // 1 here breaks init scripts that probe with `id`. write!( lock, "uid={uid}({})", @@ -646,7 +650,6 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { "{}", translate!("id-error-cannot-find-user-name", "uid" => uid) ); - set_exit_code(1); uid.to_string() }) )?; @@ -658,7 +661,6 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { "{}", translate!("id-error-cannot-find-group-name", "gid" => gid) ); - set_exit_code(1); gid.to_string() }) )?; @@ -671,7 +673,6 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { "{}", translate!("id-error-cannot-find-user-name", "uid" => euid) ); - set_exit_code(1); euid.to_string() }) )?; @@ -686,7 +687,6 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { "{}", translate!("id-error-cannot-find-group-name", "gid" => egid) ); - set_exit_code(1); egid.to_string() }) )?; @@ -703,7 +703,6 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { "{}", translate!("id-error-cannot-find-group-name", "gid" => gr) ); - set_exit_code(1); gr.to_string() }) ))