From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH 1/2] erec: Make __stmt_binary_error a little more versatile
Date: Thu, 27 Apr 2017 15:24:38 +0200 [thread overview]
Message-ID: <20170427132439.9443-1-phil@nwl.cc> (raw)
In order to allow for printing (at least) also warnings, rename
__stmt_binary_error to __stmt_binary_msg and pass the severity as first
parameter. Then create __stmt_binary_error macro to reestablish the old
signature.
Finally, add similar macros for printing warnings. And since these are
supposed to be non-fatal, make __stmt_binary_msg return 0 if a severity
below EREC_ERROR was given. This allows to still use it in return
statements.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/erec.h | 16 ++++++++++++----
src/erec.c | 13 +++++++------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/erec.h b/include/erec.h
index 36e0efa4fc1d9..0babfc0ff488c 100644
--- a/include/erec.h
+++ b/include/erec.h
@@ -63,11 +63,19 @@ extern void erec_print_list(FILE *f, struct list_head *list);
struct eval_ctx;
-extern int __fmtstring(4, 5) __stmt_binary_error(struct eval_ctx *ctx,
- const struct location *l1,
- const struct location *l2,
- const char *fmt, ...);
+extern int __fmtstring(5, 6) __stmt_binary_msg(enum error_record_types type,
+ struct eval_ctx *ctx,
+ const struct location *l1,
+ const struct location *l2,
+ const char *fmt, ...);
+#define __stmt_binary_warning(ctx, l1, l2, fmt, args...) \
+ __stmt_binary_msg(EREC_WARNING, ctx, l1, l2, fmt, ## args)
+#define stmt_warning(ctx, s1, fmt, args...) \
+ __stmt_binary_warning(ctx, &(s1)->location, NULL, fmt, ## args)
+
+#define __stmt_binary_error(ctx, l1, l2, fmt, args...) \
+ __stmt_binary_msg(EREC_ERROR, ctx, l1, l2, fmt, ## args)
#define stmt_error(ctx, s1, fmt, args...) \
__stmt_binary_error(ctx, &(s1)->location, NULL, fmt, ## args)
#define stmt_binary_error(ctx, s1, s2, fmt, args...) \
diff --git a/src/erec.c b/src/erec.c
index eacdd97a21cbc..7b9c2420d416c 100644
--- a/src/erec.c
+++ b/src/erec.c
@@ -208,19 +208,20 @@ void erec_print_list(FILE *f, struct list_head *list)
}
}
-int __fmtstring(4, 5) __stmt_binary_error(struct eval_ctx *ctx,
- const struct location *l1,
- const struct location *l2,
- const char *fmt, ...)
+int __fmtstring(5, 6) __stmt_binary_msg(enum error_record_types type,
+ struct eval_ctx *ctx,
+ const struct location *l1,
+ const struct location *l2,
+ const char *fmt, ...)
{
struct error_record *erec;
va_list ap;
va_start(ap, fmt);
- erec = erec_vcreate(EREC_ERROR, l1, fmt, ap);
+ erec = erec_vcreate(type, l1, fmt, ap);
if (l2 != NULL)
erec_add_location(erec, l2);
va_end(ap);
erec_queue(erec, ctx->msgs);
- return -1;
+ return type >= EREC_ERROR ? -1 : 0;
}
--
2.11.0
next reply other threads:[~2017-04-27 13:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-27 13:24 Phil Sutter [this message]
2017-04-27 13:24 ` [nft PATCH 2/2] masquerade: Complain if no prerouting chain exists Phil Sutter
2017-04-28 7:01 ` Arturo Borrero Gonzalez
2017-04-28 8:05 ` Phil Sutter
2017-04-28 8:11 ` Arturo Borrero Gonzalez
2017-04-28 8:28 ` Phil Sutter
2017-04-28 9:02 ` Arturo Borrero Gonzalez
2017-04-28 14:58 ` Pablo Neira Ayuso
2017-04-28 15:59 ` 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=20170427132439.9443-1-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).