Skip to contentSkip to conversation

src: fix return code

PATCH Superseded Arturo Borrero Gonzalez 2 participants 2 messages Oct 10, 2013 – Oct 11, 2013 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: fix return code

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

---
 src/main.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
src/main.c +4 -3
index 3ddcb71..9aa5f1b 100644
@@ -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);
 }
#1 lore raw
Quoted 35 lines · Arturo Borrero Gonzalez

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

---
 src/main.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
src/main.c +1 -1
index 3ddcb71..9aa5f1b 100644
@@ -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);

src/main.c int main(int argc, char * const *argv) · line 322

Quoted 6 lines
src/main.c +2 -1
@@ -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.

src/main.c int main(int argc, char * const *argv) · line 328

Quoted 7 lines
src/main.c +1 -1
 out:
 	scanner_destroy(scanner);
 	erec_print_list(stdout, &msgs);
 
 	xfree(buf);
-	return 0;
+	exit(rc);

Please, replace this with 'return rc;'

Quoted 6 lines
src/main.c +0 -1
 }
 
--

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