Feature request: Add support for linenoise as alternative to readline
Hello dear netfilter folks,
I'd like to make an feature request:
Please add support for the linenoise library (https://github.com/antirez/linenoise) as an alternative to libreadline. The linenoise library has a very small footprint and is often used in embedded environments.
This would enable the CLI on embedded devices.
Other projects that already have support for linenoise are e.g. SQLite.
Thank you very much for your attention.
Best regards
Sebastian Priebe
SII Technologies GmbH
Gesch?ftsf?hrer: Robert Bauer
Sitz der Gesellschaft: 86167 Augsburg
Registergericht: Amtsgericht Augsburg HRB 31802
cover Add Linenoise support to the CLI.
Sebastian Priebe [0] requested Linenoise support for the CLI as an alternative to Readline, so I thought I'd have a go at providing it. Linenoise is a minimal, zero-config, BSD licensed, Readline replacement used in Redis, MongoDB, and Android [1].
0 - https://lore.kernel.org/netfilter-devel/[email protected]/
1 - https://github.com/antirez/linenoise/
The upstream repo doesn't contain the infrastructure for building or installing libraries. I've taken a look at how Redis and MongoDB handle this, and they both include the upstream sources in their trees (MongoDB actually uses a C++ fork, Linenoise NG [2]), so I've done the same.
2 - https://github.com/arangodb/linenoise-ng
Initially, I added the Linenoise header to include/ and the source to src/, but the compiler warning flags used by upstream differ from those used by nftables, which meant that the compiler emitted warnings when compiling the Linenoise source and I had to edit it to fix them. Since they were benign and editing the source would make it more complicated to update from upstream in the future, I have, instead, chosen to put everything in a separate linenoise/ directory with its own Makefile.am and the same warning flags as upstream.
By default, the CLI continues to be build using Readline, but passing with-cli=linenoise instead causes Linenoise to be used instead.
The first two patches do a bit of tidying; the third patch adds the Linenoise sources; the last adds Linenoise support to the CLI.
Jeremy Sowden (4):
configure: remove unused AC_SUBST macros.
cli: remove unused declaration.
cli: add upstream linenoise source.
cli: add linenoise CLI implementation.
Makefile.am | 7 +- configure.ac | 20 +- include/cli.h | 3 +- linenoise/.gitignore | 6 + linenoise/LICENSE | 25 + linenoise/Makefile.am | 13 + linenoise/Makefile.upstream | 7 + linenoise/README.markdown | 229 +++++++ linenoise/example.c | 74 +++ linenoise/linenoise.c | 1201 +++++++++++++++++++++++++++++++++++ linenoise/linenoise.h | 73 +++ src/Makefile.am | 6 + src/cli.c | 64 +- 13 files changed, 1710 insertions(+), 18 deletions(-) create mode 100644 linenoise/.gitignore create mode 100644 linenoise/LICENSE create mode 100644 linenoise/Makefile.am create mode 100644 linenoise/Makefile.upstream create mode 100644 linenoise/README.markdown create mode 100644 linenoise/example.c create mode 100644 linenoise/linenoise.c create mode 100644 linenoise/linenoise.h
Signature · 1 line
2.23.0
RFC PATCH 1/4 configure: remove unused AC_SUBST macros.
configure.ac contains a couple of AC_SUBST macros which serve no purpose. Remove them.
--- configure.ac | 2 -- 1 file changed, 2 deletions(-)
configure.ac +0 -2
@@ -75,7 +75,6 @@ AC_CHECK_LIB([readline], [readline], , AC_MSG_ERROR([No suitable version of libreadline found])) AC_DEFINE([HAVE_LIBREADLINE], [1], []) ]) -AC_SUBST(with_cli) AM_CONDITIONAL([BUILD_CLI], [test "x$with_cli" != xno]) AC_ARG_WITH([xtables], [AS_HELP_STRING([--with-xtables],
@@ -95,7 +94,6 @@ AC_CHECK_LIB([jansson], [json_object], , AC_MSG_ERROR([No suitable version of libjansson found])) AC_DEFINE([HAVE_LIBJANSSON], [1], [Define if you have libjansson]) ]) -AC_SUBST(with_json) AM_CONDITIONAL([BUILD_JSON], [test "x$with_json" != xno]) AC_ARG_ENABLE(python,
Signature · 1 line
2.23.0
Re: [PATCH RFC nftables 1/4] configure: remove unused AC_SUBST macros.
Quoted 2 lines · Jeremy Sowden
configure.ac contains a couple of
AC_SUBSTmacros which serve no purpose. Remove them.
Applied this patch to reduce your next batch, thanks.
RFC PATCH 2/4 cli: remove unused declaration.
In reply to Jeremy Sowdencli.h includes a forward declaration of struct parser_state which is not needed. Remove it.
--- include/cli.h | 1 - 1 file changed, 1 deletion(-)
include/cli.h +0 -1
@@ -4,7 +4,6 @@#include <nftables/libnftables.h> #include <config.h> -struct parser_state ;#ifdef HAVE_LIBREADLINE extern int cli_init (struct nft_ctx *nft);#else
Signature · 1 line
2.23.0
Pablo Neira Ayuso
maintainerRe: [PATCH RFC nftables 2/4] cli: remove unused declaration.
Quoted 2 lines · Jeremy Sowden
cli.hincludes a forward declaration of structparser_statewhich is not needed. Remove it.
Also applied, thanks.
RFC PATCH 3/4 cli: add upstream linenoise source.
In reply to Jeremy SowdenLinenoise is a minimal, zero-config, BSD licensed, readline replacement used in Redis, MongoDB, and Android:
https://github.com/antirez/linenoise/
The upstream repo doesn't contain the infrastructure for building or installing libraries. There was a 1.0 release made in 2015, but there have been a number of bug-fixes committed since. Therefore, add the latest upstream source:
4a961c010872 ("Merge pull request #151 from hoelzro/master")
to the nftables tree.
--- linenoise/LICENSE | 25 + linenoise/Makefile | 7 + linenoise/README.markdown | 229 +++++++ linenoise/example.c | 74 +++ linenoise/linenoise.c | 1201 +++++++++++++++++++++++++++++++++++++ linenoise/linenoise.h | 73 +++ 6 files changed, 1609 insertions(+) create mode 100644 linenoise/LICENSE create mode 100644 linenoise/Makefile create mode 100644 linenoise/README.markdown create mode 100644 linenoise/example.c create mode 100644 linenoise/linenoise.c create mode 100644 linenoise/linenoise.h
linenoise/LICENSE new file +25 -0
@@ -0,0 +1,25 @@ +Copyright (c) 2010-2014, Salvatore Sanfilippo <antirez at gmail dot com> +Copyright (c) 2010-2013, Pieter Noordhuis <pcnoordhuis at gmail dot com> + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
linenoise/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +linenoise_example: linenoise.h linenoise.c + +linenoise_example: linenoise.c example.c + $(CC) -Wall -W -Os -g -o linenoise_example linenoise.c example.c + +clean: + rm -f linenoise_example
linenoise/README.markdown new file +229 -0
229 lines not on this page · raw message
linenoise/example.c new file +74 -0
74 lines not on this page · raw message
linenoise/linenoise.c new file +1201 -0
1,201 lines not on this page · raw message
linenoise/linenoise.h new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.23.0
RFC PATCH 4/4 cli: add linenoise CLI implementation.
In reply to Jeremy SowdenBy default, continue to use libreadline, but if --with-cli=linenoise is passed to configure, build the linenoise implementation instead.
---
Makefile.am | 7 ++-
configure.ac | 18 +++++--
include/cli.h | 2 +-
linenoise/.gitignore | 6 +++
linenoise/Makefile.am | 13 +++++
linenoise/{Makefile => Makefile.upstream} | 0
src/Makefile.am | 6 +++
src/cli.c | 64 +++++++++++++++++++----
8 files changed, 101 insertions(+), 15 deletions(-)
create mode 100644 linenoise/.gitignore
create mode 100644 linenoise/Makefile.am
rename linenoise/{Makefile => Makefile.upstream} (100%)Makefile.am +6 -1
@@ -1,6 +1,11 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src \ +if BUILD_CLI_LINENOISE +SUBDIRS = linenoise +else +SUBDIRS = +endif +SUBDIRS += src \ include \ files \ doc
configure.ac +14 -4
@@ -68,14 +68,23 @@ AC_CHECK_LIB([gmp],[__gmpz_init], , AC_MSG_ERROR([No suitable version of libgmp AM_CONDITIONAL([BUILD_MINIGMP], [test "x$with_mini_gmp" = xyes]) AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli], - [disable interactive CLI (libreadline support)])], - [], [with_cli=yes]) -AS_IF([test "x$with_cli" != xno], [ + [disable interactive CLI (libreadline or linenoise support)])], + [], [with_cli=readline]) + +AS_IF([test "x$with_cli" = xreadline], [ AC_CHECK_LIB([readline], [readline], , - AC_MSG_ERROR([No suitable version of libreadline found])) + AC_MSG_ERROR([No suitable version of libreadline found])) AC_DEFINE([HAVE_LIBREADLINE], [1], []) +], + [test "x$with_cli" = xlinenoise], [ +AH_TEMPLATE([HAVE_LINENOISE], []) +AC_DEFINE([HAVE_LINENOISE], [1], []) +], + [test "x$with_cli" != xno], [ +AC_MSG_ERROR([unexpected CLI value: $with_cli]) ]) AM_CONDITIONAL([BUILD_CLI], [test "x$with_cli" != xno]) +AM_CONDITIONAL([BUILD_CLI_LINENOISE], [test "x$with_cli" = xlinenoise]) AC_ARG_WITH([xtables], [AS_HELP_STRING([--with-xtables], [Use libxtables for iptables interaction])],
@@ -118,6 +127,7 @@ AM_CONDITIONAL([HAVE_PYTHON], [test "$enable_python" != "no"]) AC_CONFIG_FILES([ \ Makefile \ libnftables.pc \ + linenoise/Makefile \ src/Makefile \ include/Makefile \ include/nftables/Makefile \
include/cli.h +1 -1
@@ -4,7 +4,7 @@#include <nftables/libnftables.h> #include <config.h> -#ifdef HAVE_LIBREADLINE +#if defined(HAVE_LIBREADLINE ) || defined(HAVE_LINENOISE )extern int cli_init (struct nft_ctx *nft);#else static inline int cli_init (struct nft_ctx *nft)
linenoise/.gitignore new file +6 -0
@@ -0,0 +1,6 @@ +*.la +*.lo +*.o +.deps/ +.libs/ +linenoise_example
linenoise/Makefile.am new file +13 -0
@@ -0,0 +1,13 @@ +include $(top_srcdir)/Make_global.am + +AM_CFLAGS = -Wall -W + +noinst_LTLIBRARIES = liblinenoise.la + +liblinenoise_la_SOURCES = linenoise.c + +noinst_PROGRAMS = linenoise_example + +linenoise_example_SOURCES = example.c + +linenoise_example_LDADD = liblinenoise.la
linenoise/Makefile.upstream renamed from linenoise/Makefile +0 -0
src/Makefile.am +6 -0
@@ -13,6 +13,9 @@ endif if BUILD_XTABLES AM_CPPFLAGS += ${XTABLES_CFLAGS} endif +if BUILD_CLI_LINENOISE +AM_CPPFLAGS += -I$(top_srcdir)/linenoise +endif AM_CFLAGS = -Wall \ -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
@@ -106,3 +109,6 @@ libnftables_la_LIBADD += ${JANSSON_LIBS} endif nft_LDADD = libnftables.la +if BUILD_CLI_LINENOISE +nft_LDADD += $(top_srcdir)/linenoise/liblinenoise.la +endif
src/cli.c +55 -9
101 lines not on this page · raw message
Signature · 1 line
2.23.0
Pablo Neira Ayuso
maintainerRe: [PATCH RFC nftables 4/4] cli: add linenoise CLI implementation.
On Mon, Sep 16, 2019 at 01:42:03PM +0100, Jeremy Sowden wrote:
[...]
Quoted 33 lines
configure.ac +13
-4@@ -68,14 +68,23 @@ AC_CHECK_LIB([gmp],[__gmpz_init], , AC_MSG_ERROR([No suitable version of libgmp AM_CONDITIONAL([BUILD_MINIGMP], [test "x$with_mini_gmp" = xyes]) AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli], - [disable interactive CLI (libreadline support)])], - [], [with_cli=yes]) -AS_IF([test "x$with_cli" != xno], [ + [disable interactive CLI (libreadline or linenoise support)])], + [], [with_cli=readline]) + +AS_IF([test "x$with_cli" = xreadline], [ AC_CHECK_LIB([readline], [readline], , - AC_MSG_ERROR([No suitable version of libreadline found])) + AC_MSG_ERROR([No suitable version of libreadline found])) AC_DEFINE([HAVE_LIBREADLINE], [1], []) +], + [test "x$with_cli" = xlinenoise], [ +AH_TEMPLATE([HAVE_LINENOISE], []) +AC_DEFINE([HAVE_LINENOISE], [1], []) +], + [test "x$with_cli" != xno], [ +AC_MSG_ERROR([unexpected CLI value: $with_cli]) ]) AM_CONDITIONAL([BUILD_CLI], [test "x$with_cli" != xno]) +AM_CONDITIONAL([BUILD_CLI_LINENOISE], [test "x$with_cli" = xlinenoise]) AC_ARG_WITH([xtables], [AS_HELP_STRING([--with-xtables], [Use libxtables for iptables interaction])],
configure.ac AM_CONDITIONAL([HAVE_PYTHON], [test "$enable_python" != "no"]) · line 133
Quoted 7 lines
configure.ac +1
-0@@ -118,6 +127,7 @@ AM_CONDITIONAL([HAVE_PYTHON], [test "$enable_python" != "no"]) AC_CONFIG_FILES([ \ Makefile \ libnftables.pc \ + linenoise/Makefile \ src/Makefile \ include/Makefile \ include/nftables/Makefile \
You also have to update this code after AC_OUTPUT in configure.in to display libnoise, right?
echo "
nft configuration:
cli support: ${with_cli}
enable debugging symbols: ${enable_debug}
use mini-gmp: ${with_mini_gmp}
enable man page: ${enable_man_doc}
libxtables support: ${with_xtables}
json output support: ${with_json}"Re: [PATCH RFC nftables 4/4] cli: add linenoise CLI implementation.
Quoted 46 lines · Pablo Neira Ayuso
On Mon, Sep 16, 2019 at 01:42:03PM +0100, Jeremy Sowden wrote:
[...]Quoted 33 lines
configure.ac +13
-4@@ -68,14 +68,23 @@ AC_CHECK_LIB([gmp],[__gmpz_init], , AC_MSG_ERROR([No suitable version of libgmp AM_CONDITIONAL([BUILD_MINIGMP], [test "x$with_mini_gmp" = xyes]) AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli], - [disable interactive CLI (libreadline support)])], - [], [with_cli=yes]) -AS_IF([test "x$with_cli" != xno], [ + [disable interactive CLI (libreadline or linenoise support)])], + [], [with_cli=readline]) + +AS_IF([test "x$with_cli" = xreadline], [ AC_CHECK_LIB([readline], [readline], , - AC_MSG_ERROR([No suitable version of libreadline found])) + AC_MSG_ERROR([No suitable version of libreadline found])) AC_DEFINE([HAVE_LIBREADLINE], [1], []) +], + [test "x$with_cli" = xlinenoise], [ +AH_TEMPLATE([HAVE_LINENOISE], []) +AC_DEFINE([HAVE_LINENOISE], [1], []) +], + [test "x$with_cli" != xno], [ +AC_MSG_ERROR([unexpected CLI value: $with_cli]) ]) AM_CONDITIONAL([BUILD_CLI], [test "x$with_cli" != xno]) +AM_CONDITIONAL([BUILD_CLI_LINENOISE], [test "x$with_cli" = xlinenoise]) AC_ARG_WITH([xtables], [AS_HELP_STRING([--with-xtables], [Use libxtables for iptables interaction])],configure.ac AM_CONDITIONAL([HAVE_PYTHON], [test "$enable_python" != "no"]) · line 133
Quoted 7 lines
configure.ac +1
-0@@ -118,6 +127,7 @@ AM_CONDITIONAL([HAVE_PYTHON], [test "$enable_python" != "no"]) AC_CONFIG_FILES([ \ Makefile \ libnftables.pc \ + linenoise/Makefile \ src/Makefile \ include/Makefile \ include/nftables/Makefile \You also have to update this code after
AC_OUTPUTin configure.in to display libnoise, right?
Quoted 8 lines
echo "
nft configuration:cli support: ${with_cli} enable debugging symbols: ${enable_debug} use mini-gmp: ${with_mini_gmp} enable man page: ${enable_man_doc} libxtables support: ${with_xtables} json output support: ${with_json}"
${with_cli} will be "readline", "linenoise" or "no":
$ ./configure --with-cli=linenoise [...]
nft configuration:
cli support: linenoise
enable debugging symbols: yes
use mini-gmp: no
enable man page: yes
libxtables support: no
json output support: no
enable Python: yes (with /usr/bin/python)J.
Pablo Neira Ayuso
maintainerRe: [PATCH RFC nftables 0/4] Add Linenoise support to the CLI.
In reply to Jeremy SowdenQuoted 13 lines · Jeremy Sowden
Sebastian Priebe [0] requested Linenoise support for the CLI as an alternative to Readline, so I thought I'd have a go at providing it. Linenoise is a minimal, zero-config, BSD licensed, Readline replacement used in Redis, MongoDB, and Android [1].
0 - https://lore.kernel.org/netfilter-devel/[email protected]/
1 - https://github.com/antirez/linenoise/The upstream repo doesn't contain the infrastructure for building or installing libraries. I've taken a look at how Redis and MongoDB handle this, and they both include the upstream sources in their trees (MongoDB actually uses a C++ fork, Linenoise NG [2]), so I've done the same.
Quoted 6 lines
2 - https://github.com/arangodb/linenoise-ng
Initially, I added the Linenoise header to
include/and the source to src/, but the compiler warning flags used by upstream differ from those used by nftables, which meant that the compiler emitted warnings when compiling the Linenoise source and I had to edit it to fix them.
Could you silent these warnings via CFLAGS just like we do with mini-gmp.{c,h}? We already cache a copy of mini-gmp.c in the tree, this would follow the same approach, just the source under src/ and the header in include/.
Quoted 7 lines
Since they were benign and editing the source would make it more complicated to update from upstream in the future, I have, instead, chosen to put everything in a separate linenoise/ directory with its own Makefile.am and the same warning flags as upstream.
By default, the CLI continues to be build using Readline, but passing
with-cli=linenoiseinstead causes Linenoise to be used instead.
Probably good if you can also update 'nft -v' to display that nft is compiled with/without mini-gmp and also with either libreadline/linenoise.
Quoted 2 lines
The first two patches do a bit of tidying; the third patch adds the Linenoise sources; the last adds Linenoise support to the CLI.
No objections, please update tests/build/ to check for this new ./configure option.
Thanks.
Re: [PATCH RFC nftables 0/4] Add Linenoise support to the CLI.
Quoted 23 lines · Pablo Neira Ayuso
Quoted 14 lines · Jeremy Sowden
Sebastian Priebe [0] requested Linenoise support for the CLI as an alternative to Readline, so I thought I'd have a go at providing it. Linenoise is a minimal, zero-config, BSD licensed, Readline replacement used in Redis, MongoDB, and Android [1].
0 - https://lore.kernel.org/netfilter-devel/[email protected]/
1 - https://github.com/antirez/linenoise/The upstream repo doesn't contain the infrastructure for building or installing libraries. I've taken a look at how Redis and MongoDB handle this, and they both include the upstream sources in their trees (MongoDB actually uses a C++ fork, Linenoise NG [2]), so I've done the same.
Quoted 7 lines
2 - https://github.com/arangodb/linenoise-ng
Initially, I added the Linenoise header to
include/and the source to src/, but the compiler warning flags used by upstream differ from those used by nftables, which meant that the compiler emitted warnings when compiling the Linenoise source and I had to edit it to fix them.
Quoted 4 lines
Could you silent these warnings via CFLAGS just like we do with mini-gmp.{c,h}? We already cache a copy of
mini-gmp.cin the tree, this would follow the same approach, just the source under src/ and the header ininclude/.
Ah, yes, thanks for the pointer.
Quoted 5 lines
Quoted 5 lines
Since they were benign and editing the source would make it more complicated to update from upstream in the future, I have, instead, chosen to put everything in a separate linenoise/ directory with its own Makefile.am and the same warning flags as upstream.
Quoted 7 lines
Quoted 3 lines
By default, the CLI continues to be build using Readline, but passing
with-cli=linenoiseinstead causes Linenoise to be used instead.Probably good if you can also update 'nft -v' to display that nft is compiled with/without mini-gmp and also with either libreadline/linenoise.
Will do.
Quoted 5 lines
Quoted 2 lines
The first two patches do a bit of tidying; the third patch adds the Linenoise sources; the last adds Linenoise support to the CLI.
No objections, please update tests/build/ to check for this new ./configure option.
Will do.
J.