From dfa62506b7b412eeaea8efe1a5cb68e34fbfa88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Mon, 4 Oct 2021 15:08:55 +0200 Subject: Allow -u UID Defaults to username, of course, like all POSIX utilities do --- CommandLine.c | 9 +++++++-- htop.1.in | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CommandLine.c b/CommandLine.c index a352e4e3..c48572c2 100644 --- a/CommandLine.c +++ b/CommandLine.c @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "CommandLine.h" #include +#include #include #include #include @@ -178,8 +179,12 @@ static CommandLineSettings parseArguments(const char* program, int argc, char** if (!username) { flags.userId = geteuid(); } else if (!Action_setUserOnly(username, &(flags.userId))) { - fprintf(stderr, "Error: invalid user \"%s\".\n", username); - exit(1); + for (const char *itr = username; *itr; ++itr) + if (!isdigit((unsigned char)*itr)) { + fprintf(stderr, "Error: invalid user \"%s\".\n", username); + exit(1); + } + flags.userId = atol(username); } break; } diff --git a/htop.1.in b/htop.1.in index 7371efa0..702f7c23 100644 --- a/htop.1.in +++ b/htop.1.in @@ -62,7 +62,7 @@ Show only the given PIDs 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. .TP -\fB\-u \-\-user=USERNAME\fR +\fB\-u \-\-user=USERNAME|UID\fR Show only the processes of a given user .TP \fB\-U \-\-no-unicode\fR -- cgit v1.2.3