From 174c5c5f0686e85204083548805fbbb78a6ede82 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 1 Sep 2024 21:37:33 +0900 Subject: [PATCH] firewall-util: several cleanups for config_parse_nft_set() - use log_syntax_parse_error(), - return 1 on success, - drop unnecessary or redundant assertions, - add missing log_oom(). --- src/shared/firewall-util-nft.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/shared/firewall-util-nft.c b/src/shared/firewall-util-nft.c index e9bd286786..daf73c5b7b 100644 --- a/src/shared/firewall-util-nft.c +++ b/src/shared/firewall-util-nft.c @@ -1284,16 +1284,11 @@ int config_parse_nft_set( NFTSetContext *nft_set_context = ASSERT_PTR(data); int r; - assert(filename); - assert(lvalue); - assert(rvalue); - assert(nft_set_context); assert(IN_SET(ltype, NFT_SET_PARSE_NETWORK, NFT_SET_PARSE_CGROUP)); if (isempty(rvalue)) { nft_set_context_clear(nft_set_context); - - return 0; + return 1; } for (const char *p = rvalue;;) { @@ -1303,17 +1298,10 @@ int config_parse_nft_set( NFTSetSource source; r = extract_first_word(&p, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - _cleanup_free_ char *esc = NULL; - - esc = cescape(rvalue); - log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax %s=%s, ignoring: %m", lvalue, strna(esc)); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); if (r == 0) - return 0; + return 1; q = tuple; r = extract_many_words(&q, ":", EXTRACT_CUNESCAPE, &source_str, &family_str, &table, &set); @@ -1365,7 +1353,7 @@ int config_parse_nft_set( r = nft_set_add(nft_set_context, source, nfproto, table, set); if (r < 0) - return r; + return log_oom(); } assert_not_reached();