From 838746e009fcc3928ac76b4c7a07f5615d7d503a Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Mon, 7 May 2018 13:37:45 +0200 Subject: xtables-compat: xtables-save: don't return 1 noticed that iptables-compat-save exits with 1 on success, whereas iptables-compat-save -t filter returns 0 (as expected). Caused by double-invert of return value, so ge rid of those. do_output now returns a value suitable to pass to exit() or return from main. Signed-off-by: Florian Westphal --- iptables/nft.c | 14 ++++---------- iptables/xtables-save.c | 11 +++++------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/iptables/nft.c b/iptables/nft.c index 165fb9cf..fcceb09c 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -1630,20 +1630,17 @@ int nft_for_each_table(struct nft_handle *h, int (*func)(struct nft_handle *h, const char *tablename, bool counters), bool counters) { - int ret = 1; struct nftnl_table_list *list; struct nftnl_table_list_iter *iter; struct nftnl_table *t; list = nftnl_table_list_get(h); - if (list == NULL) { - ret = 0; - goto err; - } + if (list == NULL) + return -1; iter = nftnl_table_list_iter_create(list); if (iter == NULL) - return 0; + return -1; t = nftnl_table_list_iter_next(iter); while (t != NULL) { @@ -1656,10 +1653,7 @@ int nft_for_each_table(struct nft_handle *h, } nftnl_table_list_free(list); - -err: - /* the core expects 1 for success and 0 for error */ - return ret == 0 ? 1 : 0; + return 0; } static int __nft_rule_del(struct nft_handle *h, struct nftnl_rule_list *list, diff --git a/iptables/xtables-save.c b/iptables/xtables-save.c index 893b2b93..e5401daf 100644 --- a/iptables/xtables-save.c +++ b/iptables/xtables-save.c @@ -45,16 +45,16 @@ do_output(struct nft_handle *h, const char *tablename, bool counters) struct nftnl_chain_list *chain_list; if (!tablename) - return nft_for_each_table(h, do_output, counters); + return nft_for_each_table(h, do_output, counters) ? 1 : 0; if (!nft_table_find(h, tablename)) { printf("Table `%s' does not exist\n", tablename); - return 0; + return 1; } if (!nft_is_table_compatible(h, tablename)) { printf("# Table `%s' is incompatible, use 'nft' tool.\n", tablename); - return 1; + return 0; } chain_list = nft_chain_dump(h); @@ -73,8 +73,7 @@ do_output(struct nft_handle *h, const char *tablename, bool counters) now = time(NULL); printf("COMMIT\n"); printf("# Completed on %s", ctime(&now)); - - return 1; + return 0; } /* Format: @@ -176,7 +175,7 @@ xtables_save_main(int family, const char *progname, int argc, char *argv[]) exit(0); } - return !do_output(&h, tablename, show_counters); + return do_output(&h, tablename, show_counters); } int xtables_ip4_save_main(int argc, char *argv[]) -- cgit v1.2.3