From 6a9600aa61292a9f4f2634a1fa227b84e9ce1645 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Tue, 21 Jan 2014 14:34:35 +0100 Subject: [PATCH] When libreadline isn't available try editline. --- configure.ac | 27 ++++++++++++++++++++------- src/Makefile.am | 4 ++-- src/occtl.c | 19 +++++++++++++++++-- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 9a875b4b..387d013c 100644 --- a/configure.ac +++ b/configure.ac @@ -79,25 +79,38 @@ PKG_CHECK_MODULES([LIBPROTOBUF_C], [libprotobuf-c],, AM_CONDITIONAL(LOCAL_PROTOBUF_C, test "x$with_local_protobuf_c" != xno) PKG_CHECK_MODULES(LIBNL3, libnl-route-3.0 >= 3.1, [have_libnl3=yes], [have_libnl3=no]) -if (test "${have_libnl3}" = "yes"); then +if test "${have_libnl3}" = "yes"; then AC_DEFINE(HAVE_LIBNL, 1, [have libnl]) fi if test "$dbus_enabled" = yes;then occtl_enabled=yes - AC_LIB_HAVE_LINKFLAGS(readline,, [#include ], [readline(0);]) + + have_readline=no + AC_LIB_HAVE_LINKFLAGS(readline,, [ +#include +#include ], [readline(0);]) if test x$ac_cv_libreadline = xyes; then - AC_SUBST(LIBREADLINE_LIBS, [$LIBREADLINE]), + AC_SUBST(LIBREADLINE_LIBS, [$LIBREADLINE]) + AC_DEFINE(HAVE_ORIG_READLINE, 1, [have original readline]) + have_readline=yes else - occtl_enabled=no - AC_MSG_WARN([[*** -*** libreadline was not found. occtl will not be built. + PKG_CHECK_MODULES(LIBREADLINE, libedit, [have_libedit=yes], [have_libedit=no]) + if test "${have_libedit}" = "no"; then + occtl_enabled=no + AC_MSG_WARN([[*** +*** libreadline or editline was not found. occtl will not be built. ***]]) + else + have_readline=editline + fi fi else occtl_enabled=no fi +AM_CONDITIONAL(ENABLE_OCCTL, test "x$occtl_enabled" = xyes) + pam_enabled=no LIBS="$oldlibs -lpam" AC_MSG_CHECKING([for pam library]) @@ -272,7 +285,7 @@ Summary of build options: systemd: ${systemd_enabled} (socket activation) dbus: ${dbus_enabled} - readline: ${ac_cv_libreadline} + readline: ${have_readline} libnl3: ${have_libnl3} local protobuf-c: ${with_local_protobuf_c} local PCL library: ${with_local_pcl} diff --git a/src/Makefile.am b/src/Makefile.am index 2e87433e..bf7edcbc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = AM_CPPFLAGS = -I$(srcdir)/../gl/ -I$(builddir)/../gl/ \ -I$(srcdir)/ -I$(builddir)/../ $(LIBOPTS_CFLAGS) \ $(LIBPROTOBUF_C_CFLAGS) $(LIBDBUS_CFLAGS) \ - $(LIBNL3_CFLAGS) + $(LIBNL3_CFLAGS) $(LIBREADLINE_CFLAGS) BUILT_SOURCES = ocpasswd-args.c ocpasswd-args.h \ ocserv-args.c ocserv-args.h ipc.pb-c.c ipc.pb-c.h @@ -27,7 +27,7 @@ EXTRA_DIST = ccan/licenses/BSD-MIT version.inc.in \ occtl-args.def ipc.proto bin_PROGRAMS = ocpasswd -if HAVE_DBUS +if ENABLE_OCCTL bin_PROGRAMS += occtl endif diff --git a/src/occtl.c b/src/occtl.c index 221eabf3..5a0b95d4 100644 --- a/src/occtl.c +++ b/src/occtl.c @@ -25,8 +25,13 @@ #include #include #include -#include -#include +#include +#ifdef HAVE_ORIG_READLINE +# include +# include +#else +# include +#endif #include #include #include @@ -114,6 +119,10 @@ static void print_commands(unsigned interactive) } } +#ifndef HAVE_ORIG_READLINE +# define whitespace(x) c_isspace(x) +#endif + static unsigned need_help(const char *arg) { while (whitespace(*arg)) @@ -1029,7 +1038,9 @@ static int handle_help_cmd(DBusConnection * conn, const char *arg) static int handle_reset_cmd(DBusConnection * conn, const char *arg) { rl_reset_terminal(NULL); +#ifdef HAVE_ORIG_READLINE rl_reset_screen_size(); +#endif return 0; } @@ -1268,9 +1279,11 @@ static char *occtl_completion(char *text, int start, int end) void handle_sigint(int signo) { +#ifdef HAVE_ORIG_READLINE rl_reset_line_state(); rl_replace_line("", 0); rl_crlf(); +#endif rl_redisplay(); return; } @@ -1281,7 +1294,9 @@ void initialize_readline(void) rl_attempted_completion_function = (CPPFunction *) occtl_completion; rl_completion_entry_function = command_generator; rl_completion_query_items = 20; +#ifdef HAVE_ORIG_READLINE rl_clear_signals(); +#endif signal(SIGINT, handle_sigint); }