From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3F991A052A; Tue, 26 Jan 2021 08:13:23 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6476E14128B; Tue, 26 Jan 2021 08:13:22 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id C5813141285; Tue, 26 Jan 2021 08:13:19 +0100 (CET) IronPort-SDR: GvUvluHwxH3hLT3VERjlL4pgfENSIu39V9XtYktqxOnKRXr2btxaVc5XUV3AUCGOk1Gx2Pds1t i+jUHzppaLzw== X-IronPort-AV: E=McAfee;i="6000,8403,9875"; a="179940876" X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="179940876" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2021 23:13:18 -0800 IronPort-SDR: UI/ezUFn0X4d7as/0EMpM5VjzCRaMyjhHiWzKQIAYDeukuAcz/AdXBzDwayz/WnX2KBrF/ymi4 2kOMpNOuJLUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,375,1602572400"; d="scan'208";a="361881087" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by fmsmga008.fm.intel.com with ESMTP; 25 Jan 2021 23:13:17 -0800 Received: from shsmsx602.ccr.corp.intel.com (10.109.6.142) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 25 Jan 2021 23:13:16 -0800 Received: from shsmsx603.ccr.corp.intel.com (10.109.6.143) by SHSMSX602.ccr.corp.intel.com (10.109.6.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 26 Jan 2021 15:13:14 +0800 Received: from shsmsx603.ccr.corp.intel.com ([10.109.6.143]) by SHSMSX603.ccr.corp.intel.com ([10.109.6.143]) with mapi id 15.01.1713.004; Tue, 26 Jan 2021 15:13:14 +0800 From: "Yu, DapengX" To: "Li, Xiaoyun" , "Xing, Beilei" , "Lu, Wenzhuo" , "Iremonger, Bernard" , "stephen@networkplumber.org" CC: "dev@dpdk.org" , "stable@dpdk.org" Thread-Topic: [PATCH v2] app/testpmd: avoid exit without terminal restore Thread-Index: AQHW8spjT1qoMP4TKEm2t6asyoZtVKo47n8AgACNPWA= Date: Tue, 26 Jan 2021 07:13:14 +0000 Message-ID: <2028de798dcd43bda6a502518cf6e6c4@intel.com> References: <20201224035748.67012-1-dapengx.yu@intel.com> <20210125032953.430840-1-dapengx.yu@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.36] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2] app/testpmd: avoid exit without terminal restore X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Xiaoyun, For this situation: registering prompt_exit succeed, and user type "quit" = command to exit testpmd. If the second call to cmdline_stdin_exit is not excluded from the code cond= itionally, the cmdline_stdin_exit will be called twice; 1. the first time: in prompt() #0 cmdline_stdin_exit (cl=3D0x3638470) at ../lib/librte_cmdline/cmdlin= e_socket.c:56 #1 0x000000000051fb62 in prompt () at ../app/test-pmd/cmdline.c:17134 #2 0x00000000005a4d0f in main (argc=3D2, argv=3D0x7fffffffda70) at ../= app/test-pmd/testpmd.c:3849 2. the second time: in exit() . #0 cmdline_stdin_exit (cl=3D0x3638470) at ../lib/librte_cmdline/cmdlin= e_socket.c:56 #1 0x000000000051fb95 in prompt_exit () at ../app/test-pmd/cmdline.c:1= 7142 #2 0x00007ffff630fe9c in __run_exit_handlers () from /lib64/libc.so.6 #3 0x00007ffff630ffd0 in exit () from /lib64/libc.so.6 #4 0x00007ffff62f96aa in __libc_start_main () from /lib64/libc.so.6 #5 0x00000000004ead2e in _start ()=20 -----Original Message----- From: Li, Xiaoyun=20 Sent: Tuesday, January 26, 2021 2:33 PM To: Yu, DapengX ; Xing, Beilei ; Lu, Wenzhuo ; Iremonger, Bernard ; stephen@networkplumber.org Cc: dev@dpdk.org; Yu, DapengX ; stable@dpdk.org Subject: RE: [PATCH v2] app/testpmd: avoid exit without terminal restore Hi > -----Original Message----- > From: dapengx.yu@intel.com > Sent: Monday, January 25, 2021 11:30 > To: Xing, Beilei ; Li, Xiaoyun=20 > ; Lu, Wenzhuo ; Iremonger,=20 > Bernard ; stephen@networkplumber.org > Cc: dev@dpdk.org; Yu, DapengX ; stable@dpdk.org > Subject: [PATCH v2] app/testpmd: avoid exit without terminal restore >=20 > From: Dapeng Yu >=20 > In interactive mode, if testpmd exit by calling rte_exit without=20 > restore terminal attributes, terminal will not echo keyboard input. >=20 > register a function with atexit() in prompt(), when exit() in > rte_exit() is called, the registered function restores terminal attribute= s. >=20 > Fixes: 5a8fb55c48ab ("app/testpmd: support unidirectional=20 > configuration") > Cc: stable@dpdk.org >=20 > Signed-off-by: Dapeng Yu > --- > app/test-pmd/cmdline.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) >=20 > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index=20 > 89034c8b7..f7e18ba3d 100644 > --- a/app/test-pmd/cmdline.c > +++ b/app/test-pmd/cmdline.c > @@ -17116,6 +17116,7 @@ cmdline_read_from_file(const char *filename)=20 > void > prompt(void) > { > +int ret; > /* initialize non-constant commands */ cmd_set_fwd_mode_init(); =20 > cmd_set_fwd_retry_mode_init(); @@ -17123,15 +17124,23 @@ prompt(void) =20 > testpmd_cl =3D cmdline_stdin_new(main_ctx, "testpmd> "); if (testpmd_cl= =20 > =3D=3D NULL) return; > + > +ret =3D atexit(prompt_exit); > +if (ret !=3D 0) > +printf("Cannot set exit function for cmdline\n"); > + > cmdline_interact(testpmd_cl); > -cmdline_stdin_exit(testpmd_cl); > +if (ret !=3D 0) Why do you need to check ret here? Even if registers prompt_exit failed, when users type "quit" and then break= from cmdline_interact(), cmdline_stdin_exit() should be called to restore = terminal settings. > +cmdline_stdin_exit(testpmd_cl); > } >=20 > void > prompt_exit(void) > { > -if (testpmd_cl !=3D NULL) > +if (testpmd_cl !=3D NULL) { > cmdline_quit(testpmd_cl); > +cmdline_stdin_exit(testpmd_cl); > +} > } >=20 > static void > -- > 2.27.0