ps(1): '-U' to select processes by real user IDs

This is what POSIX mandates for option '-U' and arguably the behavior
that most users actually need in most cases.  Before, '-U' would select
processes by their effective user IDs (which is the behavior mandated by
POSIX for option '-u').

Matching by real user IDs allows to list all processes belonging to the
passed users, including those temporarily having a different effective
user ID, which can happen if launched by a setuid executable or if using
some credentials-changing facility (such as seteuid() for root processes
or mac_do(4)/setcred(2)).  Conversely, processes temporarily assuming
the identity of some of the passed users will not be listed anymore
(they do not "belong" to these users).

This change also makes '-U' consistent with '-G', the latter already
matching on real group IDs.

While here, remove the (non-compiled) code for tentative option '-R' as
its proposed behavior was the one established here for '-U'.  Also, move
the compiled-out old code for '-U' under '-u' for reference, as this is
what the latter should do according to POSIX, even if it seems unlikely
we will want to change the behavior of '-u'.

Reviewed by:    manpages (ziaee)
MFC after:      3 days
Relnotes:       yes
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D49622 (code)
Differential Revision:  https://reviews.freebsd.org/D49623 (manual page)
This commit is contained in:
Olivier Certner 2025-04-01 15:07:24 +02:00
parent 2d7f70975b
commit 995b690d13
No known key found for this signature in database
GPG key ID: 8CA13040971E2627
2 changed files with 23 additions and 28 deletions

View file

@ -371,8 +371,8 @@ Implies
.Fl x
by default.
.It Fl U
Display information about processes whose effective user ID matches the
specified user IDs or names.
Display information about processes whose real user ID matches the specified
user IDs or names.
Implies
.Fl x
by default.
@ -953,20 +953,16 @@ equivalently to
.Pc ,
and option
.Fl u
to select processes by effective user ID
.Po
which is the current behavior of option
.Fl U
.Pc .
to select processes by effective user ID.
.Pp
However, options
.Fl A , a , G , l , o , p ,
.Fl A , a , G , l , o , p , U ,
and
.Fl t
behave as prescribed by
.St -p1003.1-2024 .
Options
.Fl f , U ,
.Fl f
and
.Fl w
currently do not, but may be changed to in the future.

View file

@ -356,20 +356,6 @@ main(int argc, char *argv[])
*/
nselectors++;
break;
#if 0
case 'R':
/*
* XXX - This un-standard option is still under
* debate. This is what SUSv3 defines as
* the `-U' option, and while it would be
* nice to have, it could cause even more
* confusion to implement it as `-R'.
*/
add_list(&ruidlist, optarg);
xkeep_implied = 1;
nselectors++;
break;
#endif
case 'r':
sortby = SORTCPU;
break;
@ -401,21 +387,34 @@ main(int argc, char *argv[])
nselectors++;
break;
case 'U':
add_list(&ruidlist, optarg);
xkeep_implied = 1;
nselectors++;
break;
case 'u':
#if 0
/*
* POSIX says that '-U' should match on real user IDs,
* not effective ones as we are doing here, which is
* normally the behavior of option '-u' according to the
* standard.
* POSIX's '-u' behavior.
*
* This has not been activated because:
* 1. Option '-U' is a substitute for most users, and
* those that care seem more likely to want to match
* on the real user ID to display all processes
* launched by some users.
* 2. '-u' has been a canned display on the BSDs for
* a very long time (POLA).
*/
add_list(&uidlist, optarg);
xkeep_implied = 1;
nselectors++;
break;
case 'u':
#else
/* Historical BSD's '-u'. */
parsefmt(ufmt, &varlist, 0);
sortby = SORTCPU;
_fmt = 1;
break;
#endif
case 'v':
parsefmt(vfmt, &varlist, 0);
sortby = SORTMEM;