mirror of https://github.com/xzeldon/htop.git
Avoid modifying optarg
It might be working, but lets rather not modify getopt's global variable `optarg`. Also there is no need to call `getenv("USER")`, just use `geteuid()`.
This commit is contained in:
parent
5d4061732f
commit
1f5bd5c4c8
16
htop.c
16
htop.c
|
@ -131,21 +131,21 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
if (!optarg && optind < argc && argv[optind] != NULL &&
|
{
|
||||||
|
const char *username = optarg;
|
||||||
|
if (!username && optind < argc && argv[optind] != NULL &&
|
||||||
(argv[optind][0] != '\0' && argv[optind][0] != '-')) {
|
(argv[optind][0] != '\0' && argv[optind][0] != '-')) {
|
||||||
optarg = argv[optind++];
|
username = argv[optind++];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!optarg) {
|
if (!username) {
|
||||||
optarg = getenv("USER");
|
|
||||||
flags.userId = geteuid();
|
flags.userId = geteuid();
|
||||||
}
|
} else if (!Action_setUserOnly(username, &(flags.userId))) {
|
||||||
|
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
|
||||||
if (!Action_setUserOnly(optarg, &(flags.userId))) {
|
|
||||||
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'C':
|
case 'C':
|
||||||
flags.useColors = false;
|
flags.useColors = false;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue