reader->service_reader = NULL;
while ((option = getopt(argc, argv, "cdt:gsf:r:n:v:b:ku:")) != -1) {
+ int err_arg_nondigit = 0;
+
switch (option) {
break;
case 'd':
reader->dumpcount = -1;
break;
case 'f':
- if (!optarg) {
- retval = -EINVAL;
- goto cleanup;
- }
- reader->file.path = strdup(optarg);
- if (!reader->file.path) {
- retval = -ENOMEM;
+ retval = logfile_set_path(&reader->file, optarg);
+ if (retval < 0)
goto cleanup;
- }
break;
case 'b':
- if (!optarg) {
- retval = -EINVAL;
- goto cleanup;
- }
assert(g_backend.reader_init);
retval = g_backend.reader_init(reader, optarg);
if (retval != 0)
goto cleanup;
break;
case 'r':
- if (!optarg || !isdigit(optarg[0])) {
- retval = -EINVAL;
- goto cleanup;
- }
- reader->file.rotate_size_kbytes = atoi(optarg);
+ reader->file.rotate_size_kbytes = atoi_check_numeric(optarg, &err_arg_nondigit);
break;
case 'n':
- if (!optarg || !isdigit(optarg[0])) {
- retval = -EINVAL;
- goto cleanup;
- }
- reader->file.max_rotated = atoi(optarg);
+ reader->file.max_rotated = atoi_check_numeric(optarg, &err_arg_nondigit);
break;
case 'v':
- if (!optarg) {
- retval = -EINVAL;
- goto cleanup;
- }
log_set_print_format(reader->file.format, log_format_from_string(optarg));
break;
case 's':
silence = 1;
log_add_filter_string(reader->file.format, "*:s");
break;
+ case '?':
+ // invalid option or missing argument - pass to default and break
default:
// everything else gets handled in util directly
break;
}
+ if (err_arg_nondigit || option == '?') {
+ retval = -EINVAL;
+ goto cleanup;
+ }
}
if (wr && wr->buf_ptr) {