Commit 5dfb46e1 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Stricter checks for command-line options

(thanks to Sebastian Pipping)
parent 7eeb52df
......@@ -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
......
......@@ -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 (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);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment