From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: phil@nwl.cc, thaller@redhat.com, jami.maenpaa@wapice.com
Subject: [PATCH nft 1/2] parser_json: use stdin buffer if available
Date: Wed, 10 Jul 2024 17:20:03 +0200 [thread overview]
Message-ID: <20240710152004.11526-1-pablo@netfilter.org> (raw)
Since 5c2b2b0a2ba7 ("src: error reporting with -f and read from stdin")
stdin is stored in a buffer, update json support to use it instead of
reading from /dev/stdin.
Some systems do not provide /dev/stdin symlink to /proc/self/fd/0
according to reporter (that mentions Yocto Linux as example).
Fixes: 935f82e7dd49 ("Support 'nft -f -' to read from stdin")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: remove check for nft_output_json() in nft_run_cmd_from_filename()
as suggested by Phil Sutter, so JSON support does not really use
/dev/stdin.
src/libnftables.c | 3 +--
src/parser_json.c | 7 +++++++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/libnftables.c b/src/libnftables.c
index af4734c05004..89317f9f6049 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -807,8 +807,7 @@ int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
if (!strcmp(filename, "-"))
filename = "/dev/stdin";
- if (!strcmp(filename, "/dev/stdin") &&
- !nft_output_json(&nft->output))
+ if (!strcmp(filename, "/dev/stdin"))
nft->stdin_buf = stdin_to_buffer();
if (!nft->stdin_buf &&
diff --git a/src/parser_json.c b/src/parser_json.c
index ee4657ee8044..4912d3608b2b 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -4357,6 +4357,13 @@ int nft_parse_json_filename(struct nft_ctx *nft, const char *filename,
json_error_t err;
int ret;
+ if (nft->stdin_buf) {
+ json_indesc.type = INDESC_STDIN;
+ json_indesc.name = "/dev/stdin";
+
+ return nft_parse_json_buffer(nft, nft->stdin_buf, msgs, cmds);
+ }
+
json_indesc.type = INDESC_FILE;
json_indesc.name = filename;
--
2.30.2
next reply other threads:[~2024-07-10 15:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 15:20 Pablo Neira Ayuso [this message]
2024-07-10 15:20 ` [PATCH nft 2/2] libnftables: skip useable checks for /dev/stdin Pablo Neira Ayuso
2024-07-10 15:52 ` [PATCH nft 1/2] parser_json: use stdin buffer if available Phil Sutter
2024-07-10 15:54 ` Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2024-07-09 14:59 Pablo Neira Ayuso
2024-07-10 13:53 ` Phil Sutter
2024-07-10 14:01 ` Phil Sutter
2024-07-10 14:04 ` Pablo Neira Ayuso
2024-07-10 15:15 ` Phil Sutter
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=20240710152004.11526-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=jami.maenpaa@wapice.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
--cc=thaller@redhat.com \
/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