2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-02 15:45:25 +00:00

Merge branch 'ondrej/update-readline-support' into 'main'

Update and cleanup the readline library support

See merge request isc-projects/bind9!3942
This commit is contained in:
Ondřej Surý
2020-08-18 09:05:51 +00:00
10 changed files with 128 additions and 137 deletions

View File

@@ -1,3 +1,6 @@
5490. [func] Refactor the readline support to use pkg-config and
add support for editline library. [GL !3942]
5489. [bug] Named failed to reject some invalid records resulting 5489. [bug] Named failed to reject some invalid records resulting
in records that, after being printed, could not be in records that, after being printed, could not be
loaded or would result in DNSSEC validation failures loaded or would result in DNSSEC validation failures

View File

@@ -33,6 +33,11 @@ LIBISC_CFLAGS += \
$(LIBXML2_CFLAGS) $(LIBXML2_CFLAGS)
endif HAVE_LIBXML2 endif HAVE_LIBXML2
if HAVE_READLINE
LIBISC_CFLAGS += \
$(READLINE_CFLAGS)
endif HAVE_READLINE
LIBISC_LIBS = $(top_builddir)/lib/isc/libisc.la LIBISC_LIBS = $(top_builddir)/lib/isc/libisc.la
LIBDNS_CFLAGS = \ LIBDNS_CFLAGS = \

View File

@@ -25,6 +25,10 @@ libdighost_la_SOURCES = \
bin_PROGRAMS = dig host nslookup bin_PROGRAMS = dig host nslookup
nslookup_LDADD = \ nslookup_LDADD = \
$(LDADD) \ $(LDADD)
$(READLINE_LIB)
if HAVE_READLINE
nslookup_LDADD += \
$(READLINE_LIBS)
endif HAVE_READLINE

View File

@@ -22,6 +22,7 @@
#include <isc/netaddr.h> #include <isc/netaddr.h>
#include <isc/parseint.h> #include <isc/parseint.h>
#include <isc/print.h> #include <isc/print.h>
#include <isc/readline.h>
#include <isc/string.h> #include <isc/string.h>
#include <isc/task.h> #include <isc/task.h>
#include <isc/util.h> #include <isc/util.h>
@@ -38,27 +39,6 @@
#include "dighost.h" #include "dighost.h"
#if defined(HAVE_READLINE)
#if defined(HAVE_EDIT_READLINE_READLINE_H)
#include <edit/readline/readline.h>
#if defined(HAVE_EDIT_READLINE_HISTORY_H)
#include <edit/readline/history.h>
#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
#elif defined(HAVE_EDITLINE_READLINE_H)
#include <editline/readline.h>
#elif defined(HAVE_READLINE_READLINE_H)
/* Prevent deprecated functions being declared. */
#define _FUNCTION_DEF 1
/* Ensure rl_message() gets prototype. */
#define USE_VARARGS 1
#define PREFER_STDARG 1
#include <readline/readline.h>
#if defined(HAVE_READLINE_HISTORY_H)
#include <readline/history.h>
#endif /* if defined(HAVE_READLINE_HISTORY_H) */
#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
#endif /* if defined(HAVE_READLINE) */
static bool short_form = true, tcpmode = false, tcpmode_set = false, static bool short_form = true, tcpmode = false, tcpmode_set = false,
identify = false, stats = true, comments = true, identify = false, stats = true, comments = true,
section_question = true, section_answer = true, section_question = true, section_answer = true,
@@ -853,38 +833,27 @@ do_next_command(char *input) {
static void static void
get_next_command(void) { get_next_command(void) {
char *buf; char cmdlinebuf[COMMSIZE];
char *ptr; char *cmdline, *ptr = NULL;
fflush(stdout);
buf = isc_mem_allocate(mctx, COMMSIZE);
isc_app_block(); isc_app_block();
if (interactive) { if (interactive) {
#ifdef HAVE_READLINE cmdline = ptr = readline("> ");
ptr = readline("> "); if (ptr != NULL && *ptr != 0) {
if (ptr != NULL) {
add_history(ptr); add_history(ptr);
} }
#else /* ifdef HAVE_READLINE */
fprintf(stderr, "> ");
fflush(stderr);
ptr = fgets(buf, COMMSIZE, stdin);
#endif /* ifdef HAVE_READLINE */
} else { } else {
ptr = fgets(buf, COMMSIZE, stdin); cmdline = fgets(cmdlinebuf, COMMSIZE, stdin);
} }
isc_app_unblock(); isc_app_unblock();
if (ptr == NULL) { if (cmdline == NULL) {
in_use = false; in_use = false;
} else { } else {
do_next_command(ptr); do_next_command(cmdline);
} }
#ifdef HAVE_READLINE if (ptr != NULL) {
if (interactive) {
free(ptr); free(ptr);
} }
#endif /* ifdef HAVE_READLINE */
isc_mem_free(mctx, buf);
} }
ISC_NORETURN static void ISC_NORETURN static void

View File

@@ -18,8 +18,12 @@ LDADD = \
$(LIBISCCFG_LIBS) \ $(LIBISCCFG_LIBS) \
$(LIBIRS_LIBS) \ $(LIBIRS_LIBS) \
$(LIBBIND9_LIBS) \ $(LIBBIND9_LIBS) \
$(READLINE_LIB) \
$(GSSAPI_LIBS) \ $(GSSAPI_LIBS) \
$(KRB5_LIBS) $(KRB5_LIBS)
if HAVE_READLINE
LDADD += \
$(READLINE_LIBS)
endif
bin_PROGRAMS = nsupdate bin_PROGRAMS = nsupdate

View File

@@ -36,6 +36,7 @@
#include <isc/portset.h> #include <isc/portset.h>
#include <isc/print.h> #include <isc/print.h>
#include <isc/random.h> #include <isc/random.h>
#include <isc/readline.h>
#include <isc/region.h> #include <isc/region.h>
#include <isc/sockaddr.h> #include <isc/sockaddr.h>
#include <isc/socket.h> #include <isc/socket.h>
@@ -94,25 +95,6 @@
#include <bind9/getaddresses.h> #include <bind9/getaddresses.h>
#if defined(HAVE_READLINE)
#if defined(HAVE_EDIT_READLINE_READLINE_H)
#include <edit/readline/readline.h>
#if defined(HAVE_EDIT_READLINE_HISTORY_H)
#include <edit/readline/history.h>
#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
#elif defined(HAVE_EDITLINE_READLINE_H)
#include <editline/readline.h>
#else /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
/* Prevent deprecated functions being declared. */
#define _FUNCTION_DEF 1
/* Ensure rl_message() gets prototype. */
#define USE_VARARGS 1
#define PREFER_STDARG 1
#include <readline/history.h>
#include <readline/readline.h>
#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
#endif /* if defined(HAVE_READLINE) */
#define MAXCMD (128 * 1024) #define MAXCMD (128 * 1024)
#define MAXWIRE (64 * 1024) #define MAXWIRE (64 * 1024)
#define PACKETSIZE ((64 * 1024) - 1) #define PACKETSIZE ((64 * 1024) - 1)
@@ -2295,20 +2277,14 @@ static uint16_t
get_next_command(void) { get_next_command(void) {
uint16_t result = STATUS_QUIT; uint16_t result = STATUS_QUIT;
char cmdlinebuf[MAXCMD]; char cmdlinebuf[MAXCMD];
char *cmdline; char *cmdline = NULL, *ptr = NULL;
isc_app_block(); isc_app_block();
if (interactive) { if (interactive) {
#ifdef HAVE_READLINE cmdline = ptr = readline("> ");
cmdline = readline("> "); if (ptr != NULL && *ptr != 0) {
if (cmdline != NULL) { add_history(ptr);
add_history(cmdline);
} }
#else /* ifdef HAVE_READLINE */
fprintf(stdout, "> ");
fflush(stdout);
cmdline = fgets(cmdlinebuf, MAXCMD, input);
#endif /* ifdef HAVE_READLINE */
} else { } else {
cmdline = fgets(cmdlinebuf, MAXCMD, input); cmdline = fgets(cmdlinebuf, MAXCMD, input);
} }
@@ -2324,11 +2300,10 @@ get_next_command(void) {
(void)nsu_strsep(&tmp, "\r\n"); (void)nsu_strsep(&tmp, "\r\n");
result = do_next_command(cmdline); result = do_next_command(cmdline);
} }
#ifdef HAVE_READLINE if (ptr != NULL) {
if (interactive) { free(ptr);
free(cmdline);
} }
#endif /* ifdef HAVE_READLINE */
return (result); return (result);
} }

View File

@@ -976,66 +976,39 @@ AS_IF([test "$enable_tcp_fastopen" = "yes"],
# #
AC_CHECK_FUNCS([strlcpy strlcat]) AC_CHECK_FUNCS([strlcpy strlcat])
AC_SUBST(READLINE_LIB) #
AC_ARG_WITH(readline, # Check for readline support
AS_HELP_STRING([--with-readline[=LIBSPEC]], #
[specify readline library [default auto]]),
use_readline="$withval", use_readline="auto") AC_ARG_WITH([readline],
case "$use_readline" in [AS_HELP_STRING([--with-readline=yes|no|libedit|readline],
no) ;; [specify readline library [default auto]])],
*) [], [with_readline="auto"])
saved_LIBS="$LIBS"
case "$use_readline" in AS_CASE([$with_readline],
yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;; [no],[],
*) try_readline="$use_readline" [auto],
esac [PKG_CHECK_MODULES([READLINE], [libedit],
for readline in "$try_readline" $or_readline [AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])],
do [PKG_CHECK_MODULES([READLINE], [editline],
LIBS="$readline" [AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support.])],
AC_MSG_NOTICE(checking for readline with $readline) [PKG_CHECK_MODULES([READLINE], [readline],
AC_CHECK_FUNCS(readline) [AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support.])],
if test "yes" = "$ac_cv_func_readline" [AS_IF([test "$with_readline" = "yes"],
then [AC_MSG_ERROR([readline support requested, but none of the libraries have been found.])])])])])],
READLINE_LIB="$readline" [libedit],
break [PKG_CHECK_MODULES([READLINE], [libedit],
fi [AC_DEFINE([HAVE_READLINE_LIBEDIT], [1], [Build with libedit support])])],
for lib in -lterminfo -ltermcap -lncurses -lcurses [editline],
do [PKG_CHECK_MODULES([READLINE], [editline],
AC_MSG_NOTICE(checking for readline with $readline $lib) [AC_DEFINE([HAVE_READLINE_EDITLINE], [1], [Build with editline support])])],
unset ac_cv_func_readline [readline],
LIBS="$readline $lib" [PKG_CHECK_MODULES([READLINE], [readline],
AC_CHECK_FUNCS(readline) [AC_DEFINE([HAVE_READLINE_READLINE], [1], [Build with readline support])])],
if test "yes" = "$ac_cv_func_readline" [AC_MSG_ERROR([Unknown readline '$with_readline' library requested.])])
then AM_CONDITIONAL([HAVE_READLINE], [test -n "$READLINE_LIBS"])
READLINE_LIB="$readline $lib" AC_SUBST([READLINE_CFLAGS])
break AC_SUBST([READLINE_LIBS])
fi
done
if test "yes" = "$ac_cv_func_readline"
then
break
fi
done
if test "auto" != "$use_readline" &&
test "X$READLINE_LIB" = "X"
then
AC_MSG_ERROR([The readline library was not found.])
fi
LIBS="$saved_LIBS"
;;
esac
if test "yes" = "$ac_cv_func_readline"
then
case "$READLINE_LIB" in
*edit*)
AC_CHECK_HEADERS(editline/readline.h)
AC_CHECK_HEADERS(edit/readline/readline.h)
AC_CHECK_HEADERS(edit/readline/history.h)
;;
esac
AC_CHECK_HEADERS(readline/readline.h)
AC_CHECK_HEADERS(readline/history.h)
fi
# #
# Security Stuff # Security Stuff

View File

@@ -66,6 +66,7 @@ libisc_la_HEADERS = \
include/isc/radix.h \ include/isc/radix.h \
include/isc/random.h \ include/isc/random.h \
include/isc/ratelimiter.h \ include/isc/ratelimiter.h \
include/isc/readline.h \
include/isc/refcount.h \ include/isc/refcount.h \
include/isc/regex.h \ include/isc/regex.h \
include/isc/region.h \ include/isc/region.h \

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
/*
* A little wrapper around readline(), add_history() and free() to make using
* the readline code simpler.
*/
#if defined(HAVE_READLINE_LIBEDIT)
#include <editline/readline.h>
#elif defined(HAVE_READLINE_EDITLINE)
#include <editline.h>
#elif defined(HAVE_READLINE_READLINE)
/* Prevent deprecated functions being declared. */
#define _FUNCTION_DEF 1
/* Ensure rl_message() gets prototype. */
#define USE_VARARGS 1
#define PREFER_STDARG 1
#include <readline/history.h>
#include <readline/readline.h>
#endif
#if !defined(HAVE_READLINE_LIBEDIT) && !defined(HAVE_READLINE_EDITLINE) && \
!defined(HAVE_READLINE_READLINE)
#include <stdio.h>
#include <stdlib.h>
#define RL_MAXCMD (128 * 1024)
static inline char *
readline(const char *prompt) {
char *line, *buf = malloc(RL_MAXCMD);
fprintf(stdout, "%s", prompt);
fflush(stdout);
line = fgets(buf, RL_MAXCMD, stdin);
if (line == NULL) {
free(buf);
return (NULL);
}
return (buf);
};
#define add_history(line)
#endif

View File

@@ -1832,6 +1832,7 @@
./lib/isc/include/isc/radix.h C 2007,2008,2013,2014,2016,2018,2019,2020 ./lib/isc/include/isc/radix.h C 2007,2008,2013,2014,2016,2018,2019,2020
./lib/isc/include/isc/random.h C 1999,2000,2001,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020 ./lib/isc/include/isc/random.h C 1999,2000,2001,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020
./lib/isc/include/isc/ratelimiter.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2018,2019,2020 ./lib/isc/include/isc/ratelimiter.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2018,2019,2020
./lib/isc/include/isc/readline.h C 2020
./lib/isc/include/isc/refcount.h C 2001,2003,2004,2005,2006,2007,2009,2016,2017,2018,2019,2020 ./lib/isc/include/isc/refcount.h C 2001,2003,2004,2005,2006,2007,2009,2016,2017,2018,2019,2020
./lib/isc/include/isc/regex.h C 2013,2016,2018,2019,2020 ./lib/isc/include/isc/regex.h C 2013,2016,2018,2019,2020
./lib/isc/include/isc/region.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2013,2016,2018,2019,2020 ./lib/isc/include/isc/region.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2013,2016,2018,2019,2020