]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hardlink: use errx() when parse options
authorKarel Zak <kzak@redhat.com>
Thu, 4 Feb 2021 12:23:32 +0000 (13:23 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Feb 2021 10:50:21 +0000 (11:50 +0100)
Don't waste time with some cleanup on --exclude and --include regex
errors.

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/hardlink.c

index bf3e1a16f8de19f3c5477cbd1422cf8e03c86459..b9e38aa25fc2f58604bc7c37c5cd2a6694070aca 100644 (file)
@@ -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"));