[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Exit code of id depending on user group

From: Felipe Kellermann
Subject: Exit code of id depending on user group
Date: Sat, 11 Sep 2004 19:53:43 -0300 (BRT)


While writing patches to an embedded (BusyBox) version of `id' I noticed 
an interesting question about the `return value' that coreutils is using 
when we have an invalid group (say, an inexistent primary group) for the 
specified or current user.  Reading the XCU I noticed it doesn't specify 
what we should consider a "success" operation and what we should not.

Say I have the user `fuu' (primary group 100, users), and that I changed 
it to `199' (an intentionally invalid group identification), so now I'll 
check the user `fuu' identification (as in ``is it a valid user?'') with 
the coreutils version:

$ id fuu
uid=1018(fuu) gid=199 groups=199
$ echo $?

That return code sounds strange to me given the question I did.  While 
verifying that same scenario on my BSD system I noticed that its return 
code was exactly what I expected:

$ id fuu
uid=1001(fuu) gid=1001 groups=1001
$ echo $?

This is what my version do.  Now, what about the case when we do need to 
verify if `fuu' as a "valid user group identification"?  Then we could do 
the following:  `-g' in conjunction with `-n'.  My BSD is returning this:

$ id -gn test
$ echo $?

Not what I expected, as I'm querying the test's group *name*.  So with my 
version I have the following return code:

$ id -gn fuu
id: unknown gid 199
$ echo $?

Which sounds more reasonably to me, given my [gn] query.  While reading 
the sources I didn't see any hints about the issue.  Any suggestions or 
recomendations on this topic?

Felipe Kellermann

reply via email to

[Prev in Thread] Current Thread [Next in Thread]