Stricter checks for command-line options

(thanks to Sebastian Pipping)
This commit is contained in:
Hisham Muhammad 2011-08-26 21:04:26 +00:00
parent 7eeb52dfbb
commit 5dfb46e14f
2 changed files with 18 additions and 5 deletions

View File

@ -4,6 +4,8 @@ What's new in version 0.9.1
* Option for counting CPUs from zero
(thanks to Sean Noonan)
* Meters update in every screen (no longer halting while on Setup, etc.)
* Stricter checks for command-line options
(thanks to Sebastian Pipping)
* BUGFIX: Support larger numbers for process times.
(thanks to Tristan Nakagawa for the report.)
* BUGFIX: Segfault in BarMeterMode_draw() for small terminal widths

21
htop.c
View File

@ -228,12 +228,14 @@ static void addUserToVector(int key, void* userCast, void* panelCast) {
Panel_add(panel, (Object*) ListItem_new(user, key));
}
static void setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
static bool setUserOnly(const char* userName, bool* userOnly, uid_t* userId) {
struct passwd* user = getpwnam(userName);
if (user) {
*userOnly = true;
*userId = user->pw_uid;
return true;
}
return false;
}
static inline void setSortKey(ProcessList* pl, ProcessField sortKey, Panel* panel, Settings* settings) {
@ -295,16 +297,25 @@ int main(int argc, char** argv) {
}
break;
case 'd':
sscanf(optarg, "%d", &delay);
if (delay < 1) delay = 1;
if (delay > 100) delay = 100;
if (sscanf(optarg, "%d", &delay) == 1) {
if (delay < 1) delay = 1;
if (delay > 100) delay = 100;
} else {
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
exit(1);
}
break;
case 'u':
setUserOnly(optarg, &userOnly, &userId);
if (!setUserOnly(optarg, &userOnly, &userId)) {
fprintf(stderr, "Error: invalid user \"%s\".\n", optarg);
exit(1);
}
break;
case 'C':
usecolors=0;
break;
default:
exit(1);
}
}