hardlink: use errx() when parse options
Don't waste time with some cleanup on --exclude and --include regex errors. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
c12b639443
commit
ec194114e1
|
@ -919,29 +919,23 @@ static void __attribute__((__noreturn__)) usage(void)
|
|||
* @pregs: Pointer to a linked list of regular expressions
|
||||
* @regex: String containing the regular expression to be compiled
|
||||
*/
|
||||
static int register_regex(struct regex_link **pregs, const char *regex)
|
||||
static void register_regex(struct regex_link **pregs, const char *regex)
|
||||
{
|
||||
struct regex_link *link;
|
||||
struct regex_link *link = xmalloc(sizeof(*link));
|
||||
int err;
|
||||
|
||||
link = xmalloc(sizeof(*link));
|
||||
|
||||
if ((err = regcomp(&link->preg, regex, REG_NOSUB | REG_EXTENDED)) != 0) {
|
||||
size_t size = regerror(err, &link->preg, NULL, 0);
|
||||
char *buf = xmalloc(size + 1);
|
||||
|
||||
regerror(err, &link->preg, buf, size);
|
||||
|
||||
jlog(JLOG_FATAL, "Could not compile regular expression %s: %s",
|
||||
errx(EXIT_FAILURE, _("could not compile regular expression %s: %s"),
|
||||
regex, buf);
|
||||
free(buf);
|
||||
free(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
link->next = *pregs;
|
||||
*pregs = link;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1013,12 +1007,10 @@ static int parse_options(int argc, char *argv[])
|
|||
opts.dry_run = 1;
|
||||
break;
|
||||
case 'x':
|
||||
if (register_regex(&opts.exclude, optarg) != 0)
|
||||
return 1;
|
||||
register_regex(&opts.exclude, optarg);
|
||||
break;
|
||||
case 'i':
|
||||
if (register_regex(&opts.include, optarg) != 0)
|
||||
return 1;
|
||||
register_regex(&opts.include, optarg);
|
||||
break;
|
||||
case 's':
|
||||
opts.min_size = strtosize_or_err(optarg, _("failed to parse size"));
|
||||
|
@ -1075,8 +1067,7 @@ int main(int argc, char *argv[])
|
|||
if (atexit(to_be_called_atexit) != 0)
|
||||
err(EXIT_FAILURE, _("cannot register exit handler"));
|
||||
|
||||
if (parse_options(argc, argv) != 0)
|
||||
return 1;
|
||||
parse_options(argc, argv);
|
||||
|
||||
if (optind == argc)
|
||||
errx(EXIT_FAILURE, _("no directory of dile specified"));
|
||||
|
|
Loading…
Reference in New Issue