aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Certner <olce@FreeBSD.org>2025-04-01 13:07:24 +0000
committerOlivier Certner <olce@FreeBSD.org>2025-04-28 12:18:26 +0000
commit995b690d1398044dc9d85a6d86ec550cda30b2ac (patch)
tree76fbdcfba218ec9154952a37bf26f75ce5f32f29
parent2d7f70975bd8146f36b35477a8a1be490a0afc95 (diff)
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)
-rw-r--r--bin/ps/ps.114
-rw-r--r--bin/ps/ps.c37
2 files changed, 23 insertions, 28 deletions
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 174f18a2f2d9..ff9a847ffd86 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -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.
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 6c007e8fc1a1..a75ea512ad54 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -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;