[Aggregator] Test numbers from the command line
Check the return value of most calls to strtol(). Force base 10 when reading integers from the command line.
This commit is contained in:
parent
ed690ad196
commit
89f0b583e3
|
@ -363,6 +363,8 @@ int parse_config_file(int argc, char **argv)
|
|||
int parse_command_line(int argc, char **argv)
|
||||
{
|
||||
int opt ;
|
||||
long arg_long ; // Integer value of optarg
|
||||
char *endptr ; // Return value of strtol()
|
||||
|
||||
optind = 1 ; // Rewind argument parsing
|
||||
|
||||
|
@ -374,10 +376,20 @@ int parse_command_line(int argc, char **argv)
|
|||
cfg_setbool(cfg, "autocalibration", cfg_true) ;
|
||||
break ;
|
||||
case 'c' :
|
||||
cfg_setint(cfg, "check_interval", strtol(optarg, NULL, 0)) ;
|
||||
arg_long = strtol(optarg, &endptr, 10) ;
|
||||
if (endptr != optarg)
|
||||
cfg_setint(cfg, "check_interval", arg_long) ;
|
||||
else
|
||||
fprintf(stderr, "Warning! Bad check_interval:"
|
||||
" failing to the default value.\n") ;
|
||||
break ;
|
||||
case 'C' :
|
||||
cfg_setint(cfg, "ac_order_interval", strtol(optarg, NULL, 0)) ;
|
||||
arg_long = strtol(optarg, &endptr, 10) ;
|
||||
if (endptr != optarg)
|
||||
cfg_setint(cfg, "ac_order_interval", arg_long) ;
|
||||
else
|
||||
fprintf(stderr, "Warning! Bad ac_order_interval:"
|
||||
" failing back to the default value.\n") ;
|
||||
break ;
|
||||
case 'D' :
|
||||
cfg_setbool(cfg, "daemon", cfg_true) ;
|
||||
|
@ -394,36 +406,51 @@ int parse_command_line(int argc, char **argv)
|
|||
break ;
|
||||
case 'H' :
|
||||
cfg_setint(cfg, "autocalibration_hello_port",
|
||||
strtol(optarg, NULL, 0)) ;
|
||||
strtol(optarg, NULL, 10)) ;
|
||||
break ;
|
||||
case 'i' :
|
||||
cfg_setstr(cfg, "positioner_host", optarg) ;
|
||||
break ;
|
||||
case 'k' :
|
||||
cfg_setint(cfg, "keep_timeout", strtol(optarg, NULL, 0)) ;
|
||||
arg_long = strtol(optarg, &endptr, 10) ;
|
||||
if (endptr != optarg)
|
||||
cfg_setint(cfg, "keep_timeout", arg_long) ;
|
||||
else
|
||||
fprintf(stderr, "Warning! Bad keep_timeout:"
|
||||
" failing back to the default value.\n") ;
|
||||
break ;
|
||||
case 'K' :
|
||||
cfg_setint(cfg, "cp_keep_timeout", strtol(optarg, NULL, 0)) ;
|
||||
arg_long = strtol(optarg, &endptr, 10) ;
|
||||
if (endptr != optarg)
|
||||
cfg_setint(cfg, "cp_keep_timeout", arg_long) ;
|
||||
else
|
||||
fprintf(stderr, "Warning! Bad cp_keep_timeout:"
|
||||
" failing back to the default value.\n") ;
|
||||
break ;
|
||||
case 'l' :
|
||||
cfg_setint(cfg, "listening_port", strtol(optarg, NULL, 0)) ;
|
||||
cfg_setint(cfg, "listening_port", strtol(optarg, NULL, 10)) ;
|
||||
break ;
|
||||
case 'o' :
|
||||
cfg_setstr(cfg, "output_file", optarg) ;
|
||||
break ;
|
||||
case 'O' :
|
||||
cfg_setint(cfg, "autocalibration_order_port",
|
||||
strtol(optarg, NULL, 0)) ;
|
||||
strtol(optarg, NULL, 10)) ;
|
||||
break ;
|
||||
case 'p' :
|
||||
cfg_setint(cfg, "positioner_port", strtol(optarg, NULL, 0)) ;
|
||||
cfg_setint(cfg, "positioner_port", strtol(optarg, NULL, 10)) ;
|
||||
break ;
|
||||
case 'q' :
|
||||
// Quiet mode: reset the verbose level
|
||||
cfg_setint(cfg, "verbose", 0) ;
|
||||
break ;
|
||||
case 't' :
|
||||
cfg_setint(cfg, "aggregate_timeout", strtol(optarg, NULL, 0)) ;
|
||||
arg_long = strtol(optarg, &endptr, 10) ;
|
||||
if (endptr != optarg)
|
||||
cfg_setint(cfg, "aggregate_timeout", arg_long) ;
|
||||
else
|
||||
fprintf(stderr, "Warning! Bad aggregate_timeout:"
|
||||
" failing back to the default value.\n") ;
|
||||
break ;
|
||||
case 'v' :
|
||||
// Increment the verbose level
|
||||
|
|
Loading…
Reference in New Issue