netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 15/15] nft: Don't exit early after printing help texts
Date: Wed,  6 May 2020 19:33:31 +0200	[thread overview]
Message-ID: <20200506173331.9347-16-phil@nwl.cc> (raw)
In-Reply-To: <20200506173331.9347-1-phil@nwl.cc>

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 | 10 +++++-----
 iptables/xtables-eb.c  |  2 +-
 iptables/xtables.c     |  7 ++++---
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/iptables/xtables-arp.c b/iptables/xtables-arp.c
index e64938fbf5d36..8632774dfb705 100644
--- a/iptables/xtables-arp.c
+++ b/iptables/xtables-arp.c
@@ -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);
diff --git a/iptables/xtables-eb.c b/iptables/xtables-eb.c
index 5764d1803cba7..375a95d1d5c75 100644
--- a/iptables/xtables-eb.c
+++ b/iptables/xtables-eb.c
@@ -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 */
diff --git a/iptables/xtables.c b/iptables/xtables.c
index 63a37ae867069..9d2e441e0b773 100644
--- a/iptables/xtables.c
+++ b/iptables/xtables.c
@@ -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
-- 
2.25.1


      parent reply	other threads:[~2020-05-06 17:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 17:33 [iptables PATCH 00/15] cache evaluation phase bonus material Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 01/15] nft: Free rule pointer in nft_cmd_free() Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 02/15] nft: Add missing clear_cs() calls Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 03/15] nft: Avoid use-after-free when rebuilding cache Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 04/15] nft: Call nft_release_cache() in nft_fini() Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 05/15] tests: shell: Implement --valgrind mode Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 06/15] nft: cache: Re-establish cache consistency check Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 07/15] nft: Clear all lists in nft_fini() Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 08/15] nft: Fix leaks in ebt_add_policy_rule() Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 09/15] nft: Fix leak when deleting rules Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 10/15] ebtables: Free statically loaded extensions again Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 11/15] libxtables: Introduce xtables_fini() Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 12/15] nft: Use clear_cs() instead of open coding Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 13/15] arptables: Fix leak in nft_arp_print_rule() Phil Sutter
2020-05-06 17:33 ` [iptables PATCH 14/15] nft: Fix leak when replacing a rule Phil Sutter
2020-05-06 17:33 ` Phil Sutter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200506173331.9347-16-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).