irqbalance: use endptr to check whether the input parameter is empty
Signed-off-by: Liu Chao <liuchao173@huawei.com>
This commit is contained in:
parent
167580790c
commit
d48eaf61c2
23
irqbalance.c
23
irqbalance.c
|
@ -124,6 +124,7 @@ static void parse_command_line(int argc, char **argv)
|
||||||
int opt;
|
int opt;
|
||||||
int longind;
|
int longind;
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
|
char *endptr;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv,
|
while ((opt = getopt_long(argc, argv,
|
||||||
"odfjVi:p:s:c:l:m:t:e:",
|
"odfjVi:p:s:c:l:m:t:e:",
|
||||||
|
@ -139,8 +140,8 @@ static void parse_command_line(int argc, char **argv)
|
||||||
exit(1);
|
exit(1);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
deepest_cache = strtoul(optarg, NULL, 10);
|
deepest_cache = strtoul(optarg, &endptr, 10);
|
||||||
if (deepest_cache == ULONG_MAX || deepest_cache < 1) {
|
if (optarg == endptr || deepest_cache == ULONG_MAX || deepest_cache < 1) {
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -153,8 +154,8 @@ static void parse_command_line(int argc, char **argv)
|
||||||
foreground_mode=1;
|
foreground_mode=1;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
val = strtoull(optarg, NULL, 10);
|
val = strtoull(optarg, &endptr, 10);
|
||||||
if (val == ULONG_MAX) {
|
if (optarg == endptr || val == ULONG_MAX) {
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -171,8 +172,8 @@ static void parse_command_line(int argc, char **argv)
|
||||||
if (!strncmp(optarg, "off", strlen(optarg)))
|
if (!strncmp(optarg, "off", strlen(optarg)))
|
||||||
power_thresh = ULONG_MAX;
|
power_thresh = ULONG_MAX;
|
||||||
else {
|
else {
|
||||||
power_thresh = strtoull(optarg, NULL, 10);
|
power_thresh = strtoull(optarg, &endptr, 10);
|
||||||
if (power_thresh == ULONG_MAX) {
|
if (optarg == endptr || power_thresh == ULONG_MAX) {
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -189,14 +190,18 @@ static void parse_command_line(int argc, char **argv)
|
||||||
foreground_mode=1;
|
foreground_mode=1;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
sleep_interval = strtol(optarg, NULL, 10);
|
sleep_interval = strtol(optarg, &endptr, 10);
|
||||||
if (sleep_interval < 1) {
|
if (optarg == endptr || sleep_interval < 1) {
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
migrate_ratio = strtoul(optarg, NULL, 10);
|
migrate_ratio = strtoul(optarg, &endptr, 10);
|
||||||
|
if (optarg == endptr) {
|
||||||
|
usage();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue