netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: fasnacht@protonmail.ch
Subject: [PATCH nft 1/4] scanner: call scanner_push_file() after scanner_push_file()
Date: Tue, 11 Feb 2020 21:23:05 +0100	[thread overview]
Message-ID: <20200211202308.90575-2-pablo@netfilter.org> (raw)
In-Reply-To: <20200211202308.90575-1-pablo@netfilter.org>

Update include_file() to return FILE *.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/scanner.l | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/scanner.l b/src/scanner.l
index ecf2354e3c2f..fe70df5c18ec 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -714,8 +714,8 @@ static void scanner_push_file(struct nft_ctx *nft, void *scanner,
 	scanner_push_indesc(state, indesc);
 }
 
-static int include_file(struct nft_ctx *nft, void *scanner,
-			const char *filename, const struct location *loc)
+static FILE *include_file(struct nft_ctx *nft, void *scanner,
+			  const char *filename, const struct location *loc)
 {
 	struct parser_state *state = yyget_extra(scanner);
 	struct error_record *erec;
@@ -733,11 +733,11 @@ static int include_file(struct nft_ctx *nft, void *scanner,
 			     filename, strerror(errno));
 		goto err;
 	}
-	scanner_push_file(nft, scanner, f, filename, loc);
-	return 0;
+
+	return f;
 err:
 	erec_queue(erec, state->msgs);
-	return -1;
+	return NULL;
 }
 
 static int include_glob(struct nft_ctx *nft, void *scanner, const char *pattern,
@@ -749,6 +749,7 @@ static int include_glob(struct nft_ctx *nft, void *scanner, const char *pattern,
 	glob_t glob_data;
 	unsigned int i;
 	int flags = 0;
+	FILE *f;
 	int ret;
 	char *p;
 
@@ -804,9 +805,11 @@ static int include_glob(struct nft_ctx *nft, void *scanner, const char *pattern,
 			if (len == 0 || path[len - 1] == '/')
 				continue;
 
-			ret = include_file(nft, scanner, path, loc);
-			if (ret != 0)
+			f = include_file(nft, scanner, path, loc);
+			if (!f)
 				goto err;
+
+			scanner_push_file(nft, scanner, f, path, loc);
 		}
 
 		globfree(&glob_data);
@@ -841,7 +844,14 @@ err:
 int scanner_read_file(struct nft_ctx *nft, const char *filename,
 		      const struct location *loc)
 {
-	return include_file(nft, nft->scanner, filename, loc);
+	FILE *f;
+
+	f = include_file(nft, nft->scanner, filename, loc);
+	if (!f)
+		return -1;
+
+	scanner_push_file(nft, nft->scanner, f, filename, loc);
+	return 0;
 }
 
 static bool search_in_include_path(const char *filename)
-- 
2.11.0


  reply	other threads:[~2020-02-11 20:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 20:23 [PATCH nft 0/4] glob and maximum number of includes Pablo Neira Ayuso
2020-02-11 20:23 ` Pablo Neira Ayuso [this message]
2020-02-11 20:23 ` [PATCH nft 2/4] scanner: add indesc_file_alloc() helper function Pablo Neira Ayuso
2020-02-11 20:23 ` [PATCH nft 3/4] scanner: call scanner_push_indesc() after scanner_push_file() Pablo Neira Ayuso
2020-02-11 20:23 ` [PATCH nft 4/4] scanner: multi-level input file stack for glob Pablo Neira Ayuso
2020-02-12 20:44 ` [PATCH nft 0/4] glob and maximum number of includes Pablo Neira Ayuso

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=20200211202308.90575-2-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=fasnacht@protonmail.ch \
    --cc=netfilter-devel@vger.kernel.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).