netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nftables PATCH] src: fix return code
@ 2013-10-10 21:11 Arturo Borrero Gonzalez
  0 siblings, 0 replies; 3+ messages in thread
From: Arturo Borrero Gonzalez @ 2013-10-10 21:11 UTC (permalink / raw)
  To: netfilter-devel

Exit with NFT_EXIT_FAILURE if something went wrong in the netlink zone.

Before this patch:

# nft list chain filter asd ; echo $?
internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

0

After this patch:

# nft list chain filter asd ; echo $?
internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

1

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 src/main.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/main.c b/src/main.c
index 3ddcb71..9aa5f1b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -222,7 +222,7 @@ int main(int argc, char * const *argv)
 	char *buf = NULL, *filename = NULL;
 	unsigned int len;
 	bool interactive = false;
-	int i, val;
+	int i, val, rc = NFT_EXIT_FAILURE;
 
 	while (1) {
 		val = getopt_long(argc, argv, OPTSTRING, options, NULL);
@@ -318,11 +318,12 @@ int main(int argc, char * const *argv)
 		exit(NFT_EXIT_FAILURE);
 	}
 
-	nft_run(scanner, &state, &msgs);
+	if (nft_run(scanner, &state, &msgs) == 0)
+		rc = NFT_EXIT_SUCCESS;
 out:
 	scanner_destroy(scanner);
 	erec_print_list(stdout, &msgs);
 
 	xfree(buf);
-	return 0;
+	exit(rc);
 }


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [nftables PATCH] src: fix return code
@ 2013-10-10 21:11 Arturo Borrero Gonzalez
  2013-10-11  8:25 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Arturo Borrero Gonzalez @ 2013-10-10 21:11 UTC (permalink / raw)
  To: netfilter-devel

Exit with NFT_EXIT_FAILURE if something went wrong in the netlink zone.

Before this patch:

# nft list chain filter asd ; echo $?
internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

0

After this patch:

# nft list chain filter asd ; echo $?
internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

1

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 src/main.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/main.c b/src/main.c
index 3ddcb71..9aa5f1b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -222,7 +222,7 @@ int main(int argc, char * const *argv)
 	char *buf = NULL, *filename = NULL;
 	unsigned int len;
 	bool interactive = false;
-	int i, val;
+	int i, val, rc = NFT_EXIT_FAILURE;
 
 	while (1) {
 		val = getopt_long(argc, argv, OPTSTRING, options, NULL);
@@ -318,11 +318,12 @@ int main(int argc, char * const *argv)
 		exit(NFT_EXIT_FAILURE);
 	}
 
-	nft_run(scanner, &state, &msgs);
+	if (nft_run(scanner, &state, &msgs) == 0)
+		rc = NFT_EXIT_SUCCESS;
 out:
 	scanner_destroy(scanner);
 	erec_print_list(stdout, &msgs);
 
 	xfree(buf);
-	return 0;
+	exit(rc);
 }


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [nftables PATCH] src: fix return code
  2013-10-10 21:11 [nftables PATCH] src: fix return code Arturo Borrero Gonzalez
@ 2013-10-11  8:25 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2013-10-11  8:25 UTC (permalink / raw)
  To: Arturo Borrero Gonzalez; +Cc: netfilter-devel

On Thu, Oct 10, 2013 at 11:11:56PM +0200, Arturo Borrero Gonzalez wrote:
> Exit with NFT_EXIT_FAILURE if something went wrong in the netlink zone.
> 
> Before this patch:
> 
> # nft list chain filter asd ; echo $?
> internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]
> 
> 0
> 
> After this patch:
> 
> # nft list chain filter asd ; echo $?
> internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]
> 
> 1
> 
> Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
> ---
>  src/main.c |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/src/main.c b/src/main.c
> index 3ddcb71..9aa5f1b 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -222,7 +222,7 @@ int main(int argc, char * const *argv)
>  	char *buf = NULL, *filename = NULL;
>  	unsigned int len;
>  	bool interactive = false;
> -	int i, val;
> +	int i, val, rc = NFT_EXIT_FAILURE;
>  
>  	while (1) {
>  		val = getopt_long(argc, argv, OPTSTRING, options, NULL);
> @@ -318,11 +318,12 @@ int main(int argc, char * const *argv)
>  		exit(NFT_EXIT_FAILURE);
>  	}
>  
> -	nft_run(scanner, &state, &msgs);
> +	if (nft_run(scanner, &state, &msgs) == 0)
> +		rc = NFT_EXIT_SUCCESS;

I prefer if you check for errors, the convention is to check for
errors, which should be the less frequent path. So assume
NFT_EXIT_SUCCESS by default.

>  out:
>  	scanner_destroy(scanner);
>  	erec_print_list(stdout, &msgs);
>  
>  	xfree(buf);
> -	return 0;
> +	exit(rc);

Please, replace this with 'return rc;'

>  }
> 
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-11  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-10 21:11 [nftables PATCH] src: fix return code Arturo Borrero Gonzalez
2013-10-11  8:25 ` Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2013-10-10 21:11 Arturo Borrero Gonzalez

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).