Allow -u UID

Defaults to username, of course, like all POSIX utilities do
This commit is contained in:
наб 2021-10-04 15:08:55 +02:00 committed by BenBE
parent 731b4003a2
commit dfa62506b7
2 changed files with 8 additions and 3 deletions

View File

@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "CommandLine.h" #include "CommandLine.h"
#include <assert.h> #include <assert.h>
#include <ctype.h>
#include <getopt.h> #include <getopt.h>
#include <locale.h> #include <locale.h>
#include <stdbool.h> #include <stdbool.h>
@ -178,8 +179,12 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
if (!username) { if (!username) {
flags.userId = geteuid(); flags.userId = geteuid();
} else if (!Action_setUserOnly(username, &(flags.userId))) { } else if (!Action_setUserOnly(username, &(flags.userId))) {
fprintf(stderr, "Error: invalid user \"%s\".\n", username); for (const char *itr = username; *itr; ++itr)
exit(1); if (!isdigit((unsigned char)*itr)) {
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
exit(1);
}
flags.userId = atol(username);
} }
break; break;
} }

View File

@ -62,7 +62,7 @@ Show only the given PIDs
Sort by this column (use \-\-sort\-key help for a column list). Sort by this column (use \-\-sort\-key help for a column list).
This will force a list view unless you specify -t at the same time. This will force a list view unless you specify -t at the same time.
.TP .TP
\fB\-u \-\-user=USERNAME\fR \fB\-u \-\-user=USERNAME|UID\fR
Show only the processes of a given user Show only the processes of a given user
.TP .TP
\fB\-U \-\-no-unicode\fR \fB\-U \-\-no-unicode\fR