From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Dmitry Malloy <dmitrym@microsoft.com>,
Narcisa Ana Maria Vasile <Narcisa.Vasile@microsoft.com>,
Fady Bader <fady@mellanox.com>,
Tal Shnaiderman <talshn@mellanox.com>,
"Kadam, Pallavi" <pallavi.kadam@intel.com>,
Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
Olivier Matz <olivier.matz@6wind.com>
Subject: [dpdk-dev] [PATCH v2 2/7] cmdline: add internal wrappers for terminal handling
Date: Fri, 31 Jul 2020 00:06:46 +0300 [thread overview]
Message-ID: <20200730210652.14568-3-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20200730210652.14568-1-dmitry.kozliuk@gmail.com>
Extract struct terminal and associated functions that set up, save, and
restore terminal parameters. Use existing code as Unix implementation.
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
lib/librte_cmdline/Makefile | 4 ++++
lib/librte_cmdline/cmdline_os_unix.c | 27 +++++++++++++++++++++++++++
lib/librte_cmdline/cmdline_private.h | 12 +++++++++++-
lib/librte_cmdline/cmdline_socket.c | 15 ++++-----------
lib/librte_cmdline/cmdline_vt100.c | 1 -
lib/librte_cmdline/meson.build | 4 ++++
6 files changed, 50 insertions(+), 13 deletions(-)
create mode 100644 lib/librte_cmdline/cmdline_os_unix.c
diff --git a/lib/librte_cmdline/Makefile b/lib/librte_cmdline/Makefile
index 619d9a242..3d8e84c07 100644
--- a/lib/librte_cmdline/Makefile
+++ b/lib/librte_cmdline/Makefile
@@ -23,6 +23,10 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_vt100.c
SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c
SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c
+ifneq ($(CONFIG_RTE_EXEC_ENV_WINDOWS),y)
+SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_os_unix.c
+endif
+
LDLIBS += -lrte_net -lrte_eal
# install includes
diff --git a/lib/librte_cmdline/cmdline_os_unix.c b/lib/librte_cmdline/cmdline_os_unix.c
new file mode 100644
index 000000000..ca47bd19f
--- /dev/null
+++ b/lib/librte_cmdline/cmdline_os_unix.c
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Dmitry Kozlyuk
+ */
+
+#include <string.h>
+
+#include "cmdline_private.h"
+
+void
+terminal_adjust(struct terminal *oldterm)
+{
+ struct termios term;
+
+ tcgetattr(0, &oldterm->termios);
+
+ memcpy(&term, &oldterm->termios, sizeof(term));
+ term.c_lflag &= ~(ICANON | ECHO | ISIG);
+ tcsetattr(0, TCSANOW, &term);
+
+ setbuf(stdin, NULL);
+}
+
+void
+terminal_restore(const struct terminal *oldterm)
+{
+ tcsetattr(fileno(stdin), TCSANOW, &oldterm->termios);
+}
diff --git a/lib/librte_cmdline/cmdline_private.h b/lib/librte_cmdline/cmdline_private.h
index 3b1c70e9f..adc552845 100644
--- a/lib/librte_cmdline/cmdline_private.h
+++ b/lib/librte_cmdline/cmdline_private.h
@@ -10,13 +10,23 @@
#include <cmdline_rdline.h>
#include <cmdline_parse.h>
+struct terminal {
+ struct termios termios;
+};
+
+/* Disable buffering and echoing, save previous settings to oldterm. */
+void terminal_adjust(struct terminal *oldterm);
+
+/* Restore terminal settings form oldterm. */
+void terminal_restore(const struct terminal *oldterm);
+
struct cmdline {
int s_in;
int s_out;
cmdline_parse_ctx_t *ctx;
struct rdline rdl;
char prompt[RDLINE_PROMPT_SIZE];
- struct termios oldterm;
+ struct terminal oldterm;
};
#endif
diff --git a/lib/librte_cmdline/cmdline_socket.c b/lib/librte_cmdline/cmdline_socket.c
index 5e4b734d6..e73666f15 100644
--- a/lib/librte_cmdline/cmdline_socket.c
+++ b/lib/librte_cmdline/cmdline_socket.c
@@ -37,18 +37,11 @@ struct cmdline *
cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
{
struct cmdline *cl;
- struct termios oldterm, term;
-
- tcgetattr(0, &oldterm);
- memcpy(&term, &oldterm, sizeof(term));
- term.c_lflag &= ~(ICANON | ECHO | ISIG);
- tcsetattr(0, TCSANOW, &term);
- setbuf(stdin, NULL);
cl = cmdline_new(ctx, prompt, 0, 1);
- if (cl)
- memcpy(&cl->oldterm, &oldterm, sizeof(term));
+ if (cl != NULL)
+ terminal_adjust(&cl->oldterm);
return cl;
}
@@ -56,8 +49,8 @@ cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
void
cmdline_stdin_exit(struct cmdline *cl)
{
- if (!cl)
+ if (cl == NULL)
return;
- tcsetattr(fileno(stdin), TCSANOW, &cl->oldterm);
+ terminal_restore(&cl->oldterm);
}
diff --git a/lib/librte_cmdline/cmdline_vt100.c b/lib/librte_cmdline/cmdline_vt100.c
index 662fc7345..bb968dd5f 100644
--- a/lib/librte_cmdline/cmdline_vt100.c
+++ b/lib/librte_cmdline/cmdline_vt100.c
@@ -10,7 +10,6 @@
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
-#include <termios.h>
#include "cmdline_vt100.h"
diff --git a/lib/librte_cmdline/meson.build b/lib/librte_cmdline/meson.build
index 7fc54ff1a..5c9e8886d 100644
--- a/lib/librte_cmdline/meson.build
+++ b/lib/librte_cmdline/meson.build
@@ -25,4 +25,8 @@ headers = files('cmdline.h',
'cmdline_cirbuf.h',
'cmdline_parse_portlist.h')
+if not is_windows
+ sources += files('cmdline_os_unix.c')
+endif
+
deps += ['net']
--
2.25.4
next prev parent reply other threads:[~2020-07-30 21:07 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-20 21:05 [dpdk-dev] [PATCH 0/7] cmdline: support Windows Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 1/7] cmdline: make implementation opaque Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 2/7] cmdline: add internal wrappers for terminal handling Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 3/7] cmdline: add internal wrappers for character input Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 4/7] cmdline: add internal wrapper for vdprintf Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 5/7] eal/windows: improve compatibility networking headers Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 6/7] cmdline: support Windows Dmitry Kozlyuk
2020-06-28 14:20 ` Fady Bader
2020-06-29 6:23 ` Ranjit Menon
2020-06-29 7:42 ` Dmitry Kozlyuk
2020-06-29 8:12 ` Tal Shnaiderman
2020-06-29 23:56 ` Dmitry Kozlyuk
2020-07-08 1:09 ` Dmitry Kozlyuk
2020-06-20 21:05 ` [dpdk-dev] [PATCH 7/7] examples/cmdline: build on Windows Dmitry Kozlyuk
2020-07-17 22:16 ` [dpdk-dev] [PATCH 0/7] cmdline: support Windows Narcisa Ana Maria Vasile
2020-07-30 18:08 ` Kadam, Pallavi
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 " Dmitry Kozlyuk
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 1/7] cmdline: make implementation opaque Dmitry Kozlyuk
2020-08-05 9:31 ` Kinsella, Ray
2020-08-05 11:17 ` Dmitry Kozlyuk
2020-09-30 8:11 ` Kinsella, Ray
2020-09-30 15:26 ` Dmitry Kozlyuk
2020-09-17 13:34 ` Olivier Matz
2020-09-17 17:05 ` Stephen Hemminger
2020-09-18 8:33 ` Bruce Richardson
2020-09-18 12:13 ` Ferruh Yigit
2020-09-18 13:23 ` Kinsella, Ray
2020-09-17 23:13 ` Dmitry Kozlyuk
2020-09-18 13:31 ` Kinsella, Ray
2020-07-30 21:06 ` Dmitry Kozlyuk [this message]
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 3/7] cmdline: add internal wrappers for character input Dmitry Kozlyuk
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 4/7] cmdline: add internal wrapper for vdprintf Dmitry Kozlyuk
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 5/7] eal/windows: improve compatibility networking headers Dmitry Kozlyuk
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 6/7] cmdline: support Windows Dmitry Kozlyuk
2020-07-30 21:06 ` [dpdk-dev] [PATCH v2 7/7] examples/cmdline: build on Windows Dmitry Kozlyuk
2020-09-26 1:33 ` [dpdk-dev] [EXTERNAL] " Narcisa Ana Maria Vasile
2020-09-26 6:03 ` Khoa To
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 0/7] cmdline: support Windows Dmitry Kozlyuk
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 1/7] cmdline: make implementation logically opaque Dmitry Kozlyuk
2020-09-30 8:12 ` Kinsella, Ray
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 2/7] cmdline: add internal wrappers for terminal handling Dmitry Kozlyuk
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 3/7] cmdline: add internal wrappers for character input Dmitry Kozlyuk
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 4/7] cmdline: add internal wrapper for vdprintf Dmitry Kozlyuk
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 5/7] eal/windows: improve compatibility networking headers Dmitry Kozlyuk
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 6/7] cmdline: support Windows Dmitry Kozlyuk
2020-10-14 22:31 ` Thomas Monjalon
2020-09-28 21:50 ` [dpdk-dev] [PATCH v3 7/7] examples/cmdline: build on Windows Dmitry Kozlyuk
2020-10-14 22:33 ` Thomas Monjalon
2020-10-05 15:33 ` [dpdk-dev] [PATCH v3 0/7] cmdline: support Windows Olivier Matz
2020-10-14 22:41 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200730210652.14568-3-dmitry.kozliuk@gmail.com \
--to=dmitry.kozliuk@gmail.com \
--cc=Narcisa.Vasile@microsoft.com \
--cc=dev@dpdk.org \
--cc=dmitrym@microsoft.com \
--cc=fady@mellanox.com \
--cc=olivier.matz@6wind.com \
--cc=pallavi.kadam@intel.com \
--cc=talshn@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).