]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Don't exit early after printing help texts
authorPhil Sutter <phil@nwl.cc>
Wed, 6 May 2020 12:39:52 +0000 (14:39 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 11 May 2020 12:28:29 +0000 (14:28 +0200)
Follow regular code path after handling --help option to gracefully
deinit and free stuff.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/xtables-arp.c
iptables/xtables-eb.c
iptables/xtables.c

index e64938fbf5d36fd241aef36f71c50107075cb733..8632774dfb705e945a1ce4e48aa44cedf855fae8 100644 (file)
@@ -235,7 +235,7 @@ exit_tryhelp(int status)
 }
 
 static void
-exit_printhelp(void)
+printhelp(void)
 {
        struct xtables_target *t = NULL;
        int i;
@@ -325,7 +325,6 @@ exit_printhelp(void)
                printf("\n");
                t->help();
        }
-       exit(0);
 }
 
 static char
@@ -666,7 +665,8 @@ int do_commandarp(struct nft_handle *h, int argc, char *argv[], char **table,
                        if (!optarg)
                                optarg = argv[optind];
 
-                       exit_printhelp();
+                       printhelp();
+                       command = CMD_NONE;
                        break;
                case 's':
                        check_inverse(optarg, &invert, &optind, argc);
@@ -881,8 +881,6 @@ int do_commandarp(struct nft_handle *h, int argc, char *argv[], char **table,
        if (optind < argc)
                xtables_error(PARAMETER_PROBLEM,
                              "unknown arguments found on commandline");
-       if (!command)
-               xtables_error(PARAMETER_PROBLEM, "no command specified");
        if (invert)
                xtables_error(PARAMETER_PROBLEM,
                              "nothing appropriate following !");
@@ -1009,6 +1007,8 @@ int do_commandarp(struct nft_handle *h, int argc, char *argv[], char **table,
                        xtables_error(PARAMETER_PROBLEM, "Wrong policy `%s'\n",
                                      policy);
                break;
+       case CMD_NONE:
+               break;
        default:
                /* We should never reach this... */
                exit_tryhelp(2);
index 5764d1803cba7dab7459dd9ae5978a6bcc2c8419..375a95d1d5c750ec386cbbb24b0e450325fe579d 100644 (file)
@@ -1218,7 +1218,7 @@ print_zero:
 
        if (command == 'h' && !(flags & OPT_ZERO)) {
                print_help(cs.target, cs.matches, *table);
-               exit(0);
+               ret = 1;
        }
 
        /* Do the final checks */
index 63a37ae86706914ac7dc3a685469d8bf3888ad15..9d2e441e0b773313d307cc22a4095eb7df388570 100644 (file)
@@ -161,7 +161,7 @@ exit_tryhelp(int status)
 }
 
 static void
-exit_printhelp(const struct xtables_rule_match *matches)
+printhelp(const struct xtables_rule_match *matches)
 {
        printf("%s v%s\n\n"
 "Usage: %s -[ACD] chain rule-specification [options]\n"
@@ -240,7 +240,6 @@ exit_printhelp(const struct xtables_rule_match *matches)
 "[!] --version -V              print package version.\n");
 
        print_extension_helps(xtables_targets, matches);
-       exit(0);
 }
 
 void
@@ -724,7 +723,9 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
                                xtables_find_match(cs->protocol,
                                        XTF_TRY_LOAD, &cs->matches);
 
-                       exit_printhelp(cs->matches);
+                       printhelp(cs->matches);
+                       p->command = CMD_NONE;
+                       return;
 
                        /*
                         * Option selection