__attribute__ ((cleanup(fdi_array_free))) struct fd_info * fdi_ptrs[SIMULTANEOUS_BUFFERS + 1] = {0}; // null terminated
int fdi_cnt = 0;
int i;
- int option;
int tag_cnt = 0;
struct stat stat_buf;
__attribute__ ((cleanup(logfile_free))) struct log_file l_file = {
logs.timeout = log_config_get_int(&conf, "util_sorting_time_window", DEFAULT_SORT_TIMEOUT);
while (1) {
- static struct option long_options[] = {
+ static const struct option long_options[] = {
{"dumpfile", required_argument, 0, 0},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
- int long_option_id = -1;
- optarg = NULL;
- option = getopt_long(argc, argv, "cdt:gsf:r:n:v:b:u:h", long_options, &long_option_id);
+ int err_arg_nondigit = 0;
+ int option = getopt_long(argc, argv, "cdt:gsf:r:n:v:b:u:h", long_options, NULL);
if (option < 0)
break;
switch (option) {
case 0:
- switch (long_option_id) {
- case 0:
- if (!optarg)
- goto missing_optarg;
- file_input_names[files_cnt++] = optarg;
- break;
- case 1:
- show_help(argv[0]);
- return 1;
- }
+ file_input_names[files_cnt++] = optarg;
break;
- case 'h':
- show_help(argv[0]);
- return 1;
case 'd':
dump = -1;
break;
case 't':
- if (!optarg)
- goto missing_optarg;
- if (!isdigit(optarg[0]))
- goto numeric_optarg;
- dump = atoi(optarg);
+ dump = atoi_check_numeric(optarg, &err_arg_nondigit);
break;
case 'c':
should_clear = 1;
should_getsize = 1;
break;
case 'b':
- if (!optarg)
- goto missing_optarg;
buffer_names[buffer_cnt++] = optarg;
break;
case 'u':
- if (!optarg)
- goto missing_optarg;
- if (!isdigit(optarg[0]))
- goto numeric_optarg;
- logs.size = atoi(optarg);
+ logs.size = atoi_check_numeric(optarg, &err_arg_nondigit);
break;
case 'f':
- if (!optarg)
- goto missing_optarg;
l_file.path = optarg;
break;
case 'v':
- if (!optarg)
- goto missing_optarg;
log_set_print_format(l_file.format, log_format_from_string(optarg));
break;
case 's':
log_add_filter_string(l_file.format, "*:s");
break;
case 'r':
- if (!optarg)
- goto missing_optarg;
- if (!isdigit(optarg[0]))
- goto numeric_optarg;
- l_file.rotate_size_kbytes = atoi(optarg);
+ l_file.rotate_size_kbytes = atoi_check_numeric(optarg, &err_arg_nondigit);
break;
case 'n':
- if (!optarg)
- goto missing_optarg;
- if (!isdigit(optarg[0]))
- goto numeric_optarg;
- l_file.max_rotated = atoi(optarg);
+ l_file.max_rotated = atoi_check_numeric(optarg, &err_arg_nondigit);
break;
+
+ case 'h':
+ /* pass thru */
default:
- printf("Error: invalid argument\n");
+ show_help(argv[0]);
+ return 1;
+ }
+
+ if (err_arg_nondigit) {
+ printf("Error: -%c requires a numerical parameter\n", option);
return 1;
}
}
handle_pipe(fdi_ptrs, fdi_cnt, dump, &logs, &l_file);
return 0;
-
-missing_optarg:
- printf("Error: -%c requires a parameter\n", option);
- return 1;
-
-numeric_optarg:
- printf("Error: -%c requires a numerical parameter\n", option);
- return 1;
}
/**