* [nft PATCH] build: allow disabling libreadline-support
@ 2014-10-01 21:59 Steven Barth
2014-10-09 12:26 ` Pablo Neira Ayuso
0 siblings, 1 reply; 6+ messages in thread
From: Steven Barth @ 2014-10-01 21:59 UTC (permalink / raw)
To: netfilter-devel; +Cc: Steven Barth
This makes nftables a bit more embedded-friendly.
Signed-off-by: Steven Barth <cyrus@openwrt.org>
---
configure.ac | 11 +++++++++--
src/Makefile.in | 2 ++
src/main.c | 6 ++++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3a7647f..a19da5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,8 +71,15 @@ AC_CHECK_LIB([nftnl], [nft_rule_alloc], ,
AC_CHECK_LIB([gmp], [__gmpz_init], ,
AC_MSG_ERROR([No suitable version of libgmp found]))
-AC_CHECK_LIB([readline], [readline], ,
- AC_MSG_ERROR([No suitable version of libreadline found]))
+
+AC_ARG_WITH([libreadline], [AS_HELP_STRING([--without-libreadline],
+ [Disable libreadline support (no interactive CLI)])], [],
+ [with_libreadline=yes])
+AS_IF([test "x$with_libreadline" != xno], [
+AC_CHECK_LIB([readline],[readline], , AC_MSG_ERROR([No suitable version of libreadline found]))
+])
+AC_SUBST(with_libreadline)
+
# Checks for header files.
AC_HEADER_STDC
diff --git a/src/Makefile.in b/src/Makefile.in
index 8ac2b46..04107a8 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -3,7 +3,9 @@ PROGRAMS += nft
nft-destdir := @sbindir@
nft-obj += main.o
+ifeq (@with_libreadline@,yes)
nft-obj += cli.o
+endif
nft-obj += rule.o
nft-obj += statement.o
nft-obj += datatype.o
diff --git a/src/main.c b/src/main.c
index 2685b0d..de2efe6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -335,8 +335,14 @@ int main(int argc, char * const *argv)
if (scanner_read_file(scanner, filename, &internal_location) < 0)
goto out;
} else if (interactive) {
+#ifdef HAVE_LIBREADLINE
cli_init(&state);
return 0;
+#else
+ fprintf(stderr, "%s: interactive CLI not supported in this build\n",
+ argv[0]);
+ exit(NFT_EXIT_FAILURE);
+#endif
} else {
fprintf(stderr, "%s: no command specified\n", argv[0]);
exit(NFT_EXIT_FAILURE);
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [nft PATCH] build: allow disabling libreadline-support
2014-10-01 21:59 [nft PATCH] build: allow disabling libreadline-support Steven Barth
@ 2014-10-09 12:26 ` Pablo Neira Ayuso
2014-10-09 15:02 ` Steven Barth
0 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2014-10-09 12:26 UTC (permalink / raw)
To: Steven Barth; +Cc: netfilter-devel
Hi Steven,
Thanks for your patch. No major objections to this. Some comments
below:
On Wed, Oct 01, 2014 at 11:59:02PM +0200, Steven Barth wrote:
> This makes nftables a bit more embedded-friendly.
>
> Signed-off-by: Steven Barth <cyrus@openwrt.org>
> ---
> configure.ac | 11 +++++++++--
> src/Makefile.in | 2 ++
> src/main.c | 6 ++++++
> 3 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 3a7647f..a19da5d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -71,8 +71,15 @@ AC_CHECK_LIB([nftnl], [nft_rule_alloc], ,
> AC_CHECK_LIB([gmp], [__gmpz_init], ,
> AC_MSG_ERROR([No suitable version of libgmp found]))
>
> -AC_CHECK_LIB([readline], [readline], ,
> - AC_MSG_ERROR([No suitable version of libreadline found]))
> +
> +AC_ARG_WITH([libreadline], [AS_HELP_STRING([--without-libreadline],
> + [Disable libreadline support (no interactive CLI)])], [],
> + [with_libreadline=yes])
I think, better call this option "without-cli" ?
> +AS_IF([test "x$with_libreadline" != xno], [
> +AC_CHECK_LIB([readline],[readline], , AC_MSG_ERROR([No suitable version of libreadline found]))
> +])
> +AC_SUBST(with_libreadline)
> +
>
> # Checks for header files.
> AC_HEADER_STDC
> diff --git a/src/Makefile.in b/src/Makefile.in
> index 8ac2b46..04107a8 100644
> --- a/src/Makefile.in
> +++ b/src/Makefile.in
> @@ -3,7 +3,9 @@ PROGRAMS += nft
> nft-destdir := @sbindir@
>
> nft-obj += main.o
> +ifeq (@with_libreadline@,yes)
> nft-obj += cli.o
> +endif
> nft-obj += rule.o
> nft-obj += statement.o
> nft-obj += datatype.o
> diff --git a/src/main.c b/src/main.c
> index 2685b0d..de2efe6 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -335,8 +335,14 @@ int main(int argc, char * const *argv)
> if (scanner_read_file(scanner, filename, &internal_location) < 0)
> goto out;
> } else if (interactive) {
> +#ifdef HAVE_LIBREADLINE
Please, add the:
#ifdef HAVE_LIBREADLINE
in cli_init() and cli_exit() in cli.c. It would be good if the cli_init()
returns a negative value, so you spot the error message below.
> cli_init(&state);
> return 0;
> +#else
> + fprintf(stderr, "%s: interactive CLI not supported in this build\n",
> + argv[0]);
> + exit(NFT_EXIT_FAILURE);
> +#endif
> } else {
> fprintf(stderr, "%s: no command specified\n", argv[0]);
> exit(NFT_EXIT_FAILURE);
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [nft PATCH] build: allow disabling libreadline-support
2014-10-09 12:26 ` Pablo Neira Ayuso
@ 2014-10-09 15:02 ` Steven Barth
2014-10-09 16:33 ` Pablo Neira Ayuso
0 siblings, 1 reply; 6+ messages in thread
From: Steven Barth @ 2014-10-09 15:02 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel
Hi Pablo,
> >
> > -AC_CHECK_LIB([readline], [readline], ,
> > - AC_MSG_ERROR([No suitable version of libreadline found]))
> > +
> > +AC_ARG_WITH([libreadline], [AS_HELP_STRING([--without-libreadline],
> > + [Disable libreadline support (no interactive CLI)])], [],
> > + [with_libreadline=yes])
>
> I think, better call this option "without-cli" ?
OK, guess that's fine as well.
>
> Please, add the:
>
> #ifdef HAVE_LIBREADLINE
>
> in cli_init() and cli_exit() in cli.c. It would be good if the cli_init()
> returns a negative value, so you spot the error message below.
The problem I see here that this would basically mean enclosing most of
cli.c in #ifdef HAVE_LIBREADLINE to avoid depending on readline-headers
and having a rather awkward stub of cli_init in the no-readline case.
My main point of excluding cli.c in the Makefile from the start is to
avoid this madness.
Cheers,
Steven
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [nft PATCH] build: allow disabling libreadline-support
2014-10-09 15:02 ` Steven Barth
@ 2014-10-09 16:33 ` Pablo Neira Ayuso
2014-10-09 20:48 ` [nft PATCHv2] " Steven Barth
0 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2014-10-09 16:33 UTC (permalink / raw)
To: Steven Barth; +Cc: netfilter-devel
[-- Attachment #1: Type: text/plain, Size: 762 bytes --]
On Thu, Oct 09, 2014 at 05:02:41PM +0200, Steven Barth wrote:
> > Please, add the:
> >
> > #ifdef HAVE_LIBREADLINE
> >
> > in cli_init() and cli_exit() in cli.c. It would be good if the cli_init()
> > returns a negative value, so you spot the error message below.
>
> The problem I see here that this would basically mean enclosing most of
> cli.c in #ifdef HAVE_LIBREADLINE to avoid depending on readline-headers
> and having a rather awkward stub of cli_init in the no-readline case.
>
> My main point of excluding cli.c in the Makefile from the start is to
> avoid this madness.
I see, then I'd suggest something like the change (applies on top of
your patch).
Would you merge this to your patch, including the --without-cli option
and resend? Thanks.
[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 1229 bytes --]
diff --git a/include/nftables.h b/include/nftables.h
index 3394e32..c3d3dbf 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -31,7 +31,14 @@ extern unsigned int debug_level;
extern const char *include_paths[INCLUDE_PATHS_MAX];
struct parser_state;
+#ifdef HAVE_LIBREADLINE
extern int cli_init(struct parser_state *state);
+#else
+static inline int cli_init(struct parser_state *state)
+{
+ return -1;
+}
+#endif
extern void cli_exit(void);
extern void cli_display(const char *fmt, va_list ap) __fmtstring(1, 0);
diff --git a/src/main.c b/src/main.c
index de2efe6..8dc0768 100644
--- a/src/main.c
+++ b/src/main.c
@@ -335,14 +335,12 @@ int main(int argc, char * const *argv)
if (scanner_read_file(scanner, filename, &internal_location) < 0)
goto out;
} else if (interactive) {
-#ifdef HAVE_LIBREADLINE
- cli_init(&state);
+ if (cli_init(&state) < 0) {
+ fprintf(stderr, "%s: CLI not supported in this build\n",
+ argv[0]);
+ exit(NFT_EXIT_FAILURE);
+ }
return 0;
-#else
- fprintf(stderr, "%s: interactive CLI not supported in this build\n",
- argv[0]);
- exit(NFT_EXIT_FAILURE);
-#endif
} else {
fprintf(stderr, "%s: no command specified\n", argv[0]);
exit(NFT_EXIT_FAILURE);
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [nft PATCHv2] build: allow disabling libreadline-support
2014-10-09 16:33 ` Pablo Neira Ayuso
@ 2014-10-09 20:48 ` Steven Barth
2014-10-10 10:23 ` Pablo Neira Ayuso
0 siblings, 1 reply; 6+ messages in thread
From: Steven Barth @ 2014-10-09 20:48 UTC (permalink / raw)
To: netfilter-devel; +Cc: Pablo Neira Ayuso, Steven Barth
This makes nftables a bit more embedded-friendly.
Signed-off-by: Steven Barth <cyrus@openwrt.org>
---
configure.ac | 9 +++++++--
include/nftables.h | 7 +++++++
src/Makefile.in | 2 ++
src/main.c | 6 +++++-
4 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3a7647f..a2dd415 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,8 +71,13 @@ AC_CHECK_LIB([nftnl], [nft_rule_alloc], ,
AC_CHECK_LIB([gmp], [__gmpz_init], ,
AC_MSG_ERROR([No suitable version of libgmp found]))
-AC_CHECK_LIB([readline], [readline], ,
- AC_MSG_ERROR([No suitable version of libreadline found]))
+AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli],
+ [disable interactive CLI (libreadline support)])],
+ [], [with_cli=yes])
+AS_IF([test "x$with_cli" != xno], [
+AC_CHECK_LIB([readline],[readline], , AC_MSG_ERROR([No suitable version of libreadline found]))
+])
+AC_SUBST(with_cli)
# Checks for header files.
AC_HEADER_STDC
diff --git a/include/nftables.h b/include/nftables.h
index 3394e32..c3d3dbf 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -31,7 +31,14 @@ extern unsigned int debug_level;
extern const char *include_paths[INCLUDE_PATHS_MAX];
struct parser_state;
+#ifdef HAVE_LIBREADLINE
extern int cli_init(struct parser_state *state);
+#else
+static inline int cli_init(struct parser_state *state)
+{
+ return -1;
+}
+#endif
extern void cli_exit(void);
extern void cli_display(const char *fmt, va_list ap) __fmtstring(1, 0);
diff --git a/src/Makefile.in b/src/Makefile.in
index 8ac2b46..7ecc5f2 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -3,7 +3,9 @@ PROGRAMS += nft
nft-destdir := @sbindir@
nft-obj += main.o
+ifeq (@with_cli@,yes)
nft-obj += cli.o
+endif
nft-obj += rule.o
nft-obj += statement.o
nft-obj += datatype.o
diff --git a/src/main.c b/src/main.c
index 2685b0d..ee684ce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -335,7 +335,11 @@ int main(int argc, char * const *argv)
if (scanner_read_file(scanner, filename, &internal_location) < 0)
goto out;
} else if (interactive) {
- cli_init(&state);
+ if (cli_init(&state) < 0) {
+ fprintf(stderr, "%s: interactive CLI not supported in this build\n",
+ argv[0]);
+ exit(NFT_EXIT_FAILURE);
+ }
return 0;
} else {
fprintf(stderr, "%s: no command specified\n", argv[0]);
--
2.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [nft PATCHv2] build: allow disabling libreadline-support
2014-10-09 20:48 ` [nft PATCHv2] " Steven Barth
@ 2014-10-10 10:23 ` Pablo Neira Ayuso
0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2014-10-10 10:23 UTC (permalink / raw)
To: Steven Barth; +Cc: netfilter-devel
On Thu, Oct 09, 2014 at 10:48:27PM +0200, Steven Barth wrote:
> This makes nftables a bit more embedded-friendly.
Applied, thanks Steven.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-10-10 10:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-01 21:59 [nft PATCH] build: allow disabling libreadline-support Steven Barth
2014-10-09 12:26 ` Pablo Neira Ayuso
2014-10-09 15:02 ` Steven Barth
2014-10-09 16:33 ` Pablo Neira Ayuso
2014-10-09 20:48 ` [nft PATCHv2] " Steven Barth
2014-10-10 10:23 ` Pablo Neira Ayuso
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).