[dpdk-dev] [PATCH v2] cmdline: rework as a wrapper to libedit

Olivier Matz olivier.matz at 6wind.com
Tue Jun 26 15:33:13 CEST 2018


> I noticed a bad behavior change (in addition to many good ones):
> ctrl-c now quits the application, and this was not the case before.
> I often use ctrl-c to delete the line I'm currently editing. Please
> see at the end a proposition to restore this feature.

And now, ladies and gentlemen, the proposition I was talking about :)

 diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c
 index f334d7123..860457dc6 100644
 --- a/examples/vhost_crypto/main.c
 +++ b/examples/vhost_crypto/main.c
 @@ -15,7 +15,6 @@
  #include <rte_cryptodev.h>
  #include <rte_vhost_crypto.h>
  
 -#include <cmdline_rdline.h>
  #include <cmdline_parse.h>
  #include <cmdline_parse_string.h>
  #include <cmdline.h>
 diff --git a/lib/librte_cmdline/Makefile b/lib/librte_cmdline/Makefile
 index feb1f1bca..052934b69 100644
 --- a/lib/librte_cmdline/Makefile
 +++ b/lib/librte_cmdline/Makefile
 @@ -23,6 +23,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
  SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
  
  LDLIBS += -lrte_eal
 +LDLIBS += $(shell pkg-config --libs libedit)
  
  # install includes
  INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h
 diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
 index 1c45cd9ff..af72f394f 100644
 --- a/lib/librte_cmdline/cmdline.c
 +++ b/lib/librte_cmdline/cmdline.c
 @@ -4,8 +4,9 @@
   * All rights reserved.
   */
  
 +#include <sys/types.h>
  #include <ctype.h>
 -#include <histedit.h>
 +#include <signal.h>
  #include <stdint.h>
  #include <stdio.h>
  #include <string.h>
 @@ -16,6 +17,8 @@
  #include <poll.h>
  #include <errno.h>
  
 +#include <histedit.h>
 +
  #include <rte_string_fns.h>
  
  #include "cmdline_parse.h"
 @@ -60,6 +63,32 @@ cmdline_el_prompt(EditLine *el)
  	return cl->prompt;
  }
  
 +static int
 +editline_break(EditLine *el, int c)
 +{
 +	struct cmdline *cl;
 +
 +	(void)c;
 +
 +	if (el_get(el, EL_CLIENTDATA, &cl))
 +		return CC_FATAL;
 +
 +	fprintf(cl->f_out, "\n");
 +
 +	return CC_NEWLINE;
 +}
 +
 +static int
 +editline_suspend(EditLine *editline, int c)
 +{
 +	(void)editline;
 +	(void)c;
 +
 +	kill(getpid(), SIGSTOP);
 +
 +	return CC_NORM;
 +}
 +
  static unsigned char
  cmdline_el_execute(EditLine *el, int c)
  {
 @@ -224,6 +253,20 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
  	if (el_set(cl->el, EL_ADDFN, "ed-execute", "Execute command",
  		   cmdline_el_execute))
  		goto error;
 +	if (el_set(cl->el, EL_SETTY, "-d", "-isig", NULL))
 +		goto error;
 +	if (el_set(cl->el, EL_ADDFN, "ed-break",
 +			"Break and flush the buffer",
 +			editline_break))
 +		goto error;
 +	if (el_set(cl->el, EL_BIND, "^C", "ed-break", NULL))
 +		goto error;
 +	if (el_set(cl->el, EL_ADDFN, "ed-suspend",
 +			"Suspend the terminal",
 +			editline_suspend))
 +		goto error;
 +	if (el_set(cl->el, EL_BIND, "^Z", "ed-suspend", NULL))
 +		goto error;
  	if (el_set(cl->el, EL_BIND, "^J", "ed-execute", NULL))
  		goto error;
  	if (el_set(cl->el, EL_BIND, "^M", "ed-execute", NULL))
 diff --git a/mk/rte.app.mk b/mk/rte.app.mk
 index e5caefb08..f7d9f6f2c 100644
 --- a/mk/rte.app.mk
 +++ b/mk/rte.app.mk
 @@ -81,8 +81,6 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_RING)           += -lrte_ring
  _LDLIBS-$(CONFIG_RTE_LIBRTE_PCI)            += -lrte_pci
  _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL)            += -lrte_eal
  _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE)        += -lrte_cmdline
 -
 -_LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE)        += $(shell pkg-config --libs libedit)
  _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER)        += -lrte_reorder
  _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
  
 @@ -267,6 +265,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y)
  _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST)          += -lnuma
  endif
  _LDLIBS-$(CONFIG_RTE_PORT_PCAP)             += -lpcap
 +_LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE)        += $(shell pkg-config --libs libedit)
  endif # !CONFIG_RTE_BUILD_SHARED_LIBS
  
  _LDLIBS-y += $(EXECENV_LDLIBS)


More information about the dev mailing list