summaryrefslogtreecommitdiffstats
path: root/htop.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2020-08-20 13:57:09 +1000
committerNathan Scott <nathans@redhat.com>2020-08-20 13:57:09 +1000
commitfb679dfb183eb72ee020f63c9779018b92ff84be (patch)
treeb3ce702b011c79ca196ea3e315689eea5cb3c140 /htop.c
parenta7a5e356c2990e7288cb70ebe0b9991b8e4136ba (diff)
parent7c62db73fc8e544692a903e5f391751a3561a71b (diff)
Merge branch 'hishamhm-pull-884'
Diffstat (limited to 'htop.c')
-rw-r--r--htop.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/htop.c b/htop.c
index 8c88c782..93b788fb 100644
--- a/htop.c
+++ b/htop.c
@@ -43,7 +43,7 @@ static void printHelpFlag() {
"-h --help Print this help screen\n"
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
"-t --tree Show the tree view by default\n"
- "-u --user=USERNAME Show only processes of a given user\n"
+ "-u --user[=USERNAME] Show only processes for a given user (or $USER)\n"
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
"-v --version Print version info\n"
"\n"
@@ -82,7 +82,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
{"version", no_argument, 0, 'v'},
{"delay", required_argument, 0, 'd'},
{"sort-key", required_argument, 0, 's'},
- {"user", required_argument, 0, 'u'},
+ {"user", optional_argument, 0, 'u'},
{"no-color", no_argument, 0, 'C'},
{"no-colour",no_argument, 0, 'C'},
{"tree", no_argument, 0, 't'},
@@ -92,7 +92,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
int opt, opti=0;
/* Parse arguments */
- while ((opt = getopt_long(argc, argv, "hvCs:td:u:p:", long_opts, &opti))) {
+ while ((opt = getopt_long(argc, argv, "hvCs:td:u::p:", long_opts, &opti))) {
if (opt == EOF) break;
switch (opt) {
case 'h':
@@ -123,6 +123,16 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
}
break;
case 'u':
+ if (!optarg && optind < argc && argv[optind] != NULL &&
+ (argv[optind][0] != '\0' && argv[optind][0] != '-')) {
+ optarg = argv[optind++];
+ }
+
+ if (!optarg) {
+ optarg = getenv("USER");
+ flags.userId = geteuid();
+ }
+
if (!Action_setUserOnly(optarg, &(flags.userId))) {
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy