Skip to content

Commit dfa6250

Browse files
nabijaczleweliBenBE
authored andcommitted
Allow -u UID
Defaults to username, of course, like all POSIX utilities do
1 parent 731b400 commit dfa6250

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

CommandLine.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ in the source distribution for its full text.
1111
#include "CommandLine.h"
1212

1313
#include <assert.h>
14+
#include <ctype.h>
1415
#include <getopt.h>
1516
#include <locale.h>
1617
#include <stdbool.h>
@@ -178,8 +179,12 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
178179
if (!username) {
179180
flags.userId = geteuid();
180181
} else if (!Action_setUserOnly(username, &(flags.userId))) {
181-
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
182-
exit(1);
182+
for (const char *itr = username; *itr; ++itr)
183+
if (!isdigit((unsigned char)*itr)) {
184+
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
185+
exit(1);
186+
}
187+
flags.userId = atol(username);
183188
}
184189
break;
185190
}

htop.1.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Show only the given PIDs
6262
Sort by this column (use \-\-sort\-key help for a column list).
6363
This will force a list view unless you specify -t at the same time.
6464
.TP
65-
\fB\-u \-\-user=USERNAME\fR
65+
\fB\-u \-\-user=USERNAME|UID\fR
6666
Show only the processes of a given user
6767
.TP
6868
\fB\-U \-\-no-unicode\fR

0 commit comments

Comments
 (0)