From 75725bb8d1d54176d798189f3390cfe294a01325 Mon Sep 17 00:00:00 2001 From: linzhenxing Date: Tue, 29 Mar 2022 20:15:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?tty=20SIGINT=E3=80=81SIGTSTP=20=E4=BF=A1?= =?UTF-8?q?=E5=8F=B7=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/tty/n_tty.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c index 38bfd90060..bbc21562c4 100644 --- a/components/drivers/tty/n_tty.c +++ b/components/drivers/tty/n_tty.c @@ -528,13 +528,32 @@ static void eraser(unsigned char c, struct tty_struct *tty) * * Locking: ctrl_lock */ - +extern struct termios old_stdin_termios; static void __isig(int sig, struct tty_struct *tty) { struct rt_lwp *lwp = tty->foreground; + struct tty_ldisc *ld = RT_NULL; + struct termios *new_termios = &old_stdin_termios; + if (lwp) { - lwp_kill(lwp_to_pid(lwp), sig); + if (sig == SIGTSTP) + { + tty->init_termios = *new_termios; + ld = tty->ldisc; + if (ld != RT_NULL) + { + if (ld->ops->set_termios) + { + ld->ops->set_termios(tty, &old_stdin_termios); + } + } + tty->foreground = RT_NULL; + } + else + { + lwp_kill(lwp_to_pid(lwp), sig); + } } } -- Gitee From 1efb2ddd4ad5444c7c32e97e6c1156b652a5af2c Mon Sep 17 00:00:00 2001 From: linzhenxing Date: Wed, 30 Mar 2022 14:53:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B0=86=E5=85=A8=E5=B1=80=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E4=BF=AE=E6=94=B9=E6=88=90=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/tty/n_tty.c | 7 +++++-- components/drivers/tty/tty_ioctl.c | 5 +++-- components/lwp/lwp.c | 7 ++++++- components/lwp/lwp.h | 1 + components/lwp/lwp_pid.c | 4 ++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c index bbc21562c4..fcbe036373 100644 --- a/components/drivers/tty/n_tty.c +++ b/components/drivers/tty/n_tty.c @@ -10,6 +10,7 @@ #include #include #include +#include #if defined(RT_USING_POSIX) #include #endif @@ -533,19 +534,21 @@ static void __isig(int sig, struct tty_struct *tty) { struct rt_lwp *lwp = tty->foreground; struct tty_ldisc *ld = RT_NULL; - struct termios *new_termios = &old_stdin_termios; + struct termios old_termios; + struct termios *new_termios = get_old_termios(); if (lwp) { if (sig == SIGTSTP) { + rt_memcpy(&old_termios, &(tty->init_termios), sizeof(struct termios)); tty->init_termios = *new_termios; ld = tty->ldisc; if (ld != RT_NULL) { if (ld->ops->set_termios) { - ld->ops->set_termios(tty, &old_stdin_termios); + ld->ops->set_termios(tty, &old_termios); } } tty->foreground = RT_NULL; diff --git a/components/drivers/tty/tty_ioctl.c b/components/drivers/tty/tty_ioctl.c index 894353ed84..fb178a65ac 100644 --- a/components/drivers/tty/tty_ioctl.c +++ b/components/drivers/tty/tty_ioctl.c @@ -36,7 +36,7 @@ static int set_termios(struct tty_struct *tty, void *arg, int opt) { - struct termios old_termios = tty->init_termios; + struct termios old_termios; struct tty_ldisc *ld = RT_NULL; struct termios *new_termios = (struct termios *)arg; int level = 0; @@ -47,6 +47,7 @@ static int set_termios(struct tty_struct *tty, void *arg, int opt) return retval; } + rt_memcpy(&old_termios, &(tty->init_termios), sizeof(struct termios)); level = rt_hw_interrupt_disable(); tty->init_termios = *new_termios; rt_hw_interrupt_enable(level); @@ -55,7 +56,7 @@ static int set_termios(struct tty_struct *tty, void *arg, int opt) { if (ld->ops->set_termios) { - ld->ops->set_termios(tty, &old_termios); + ld->ops->set_termios(tty, old_termios); } } return 0; diff --git a/components/lwp/lwp.c b/components/lwp/lwp.c index 02b08d4856..d586d33bac 100644 --- a/components/lwp/lwp.c +++ b/components/lwp/lwp.c @@ -38,11 +38,16 @@ static const char elf_magic[] = {0x7f, 'E', 'L', 'F'}; #ifdef DFS_USING_WORKDIR extern char working_directory[]; #endif -struct termios stdin_termios, old_stdin_termios; +static struct termios stdin_termios, old_stdin_termios; extern void lwp_user_entry(void *args, const void *text, void *ustack, void *k_stack); int load_ldso(struct rt_lwp *lwp, char *exec_name, char *const argv[], char *const envp[]); +struct termios *get_old_termios(void) +{ + return &old_stdin_termios; +} + void lwp_setcwd(char *buf) { struct rt_lwp *lwp = RT_NULL; diff --git a/components/lwp/lwp.h b/components/lwp/lwp.h index 823231240c..f65c2a94a5 100644 --- a/components/lwp/lwp.h +++ b/components/lwp/lwp.h @@ -125,6 +125,7 @@ enum lwp_exit_request_type LWP_EXIT_REQUEST_TRIGGERED, LWP_EXIT_REQUEST_IN_PROCESS, }; +struct termios *get_old_termios(void); void lwp_setcwd(char *buf); char *lwp_getcwd(void); void lwp_request_thread_exit(rt_thread_t thread_to_exit); diff --git a/components/lwp/lwp_pid.c b/components/lwp/lwp_pid.c index 3b926de236..1b4696d78e 100644 --- a/components/lwp/lwp_pid.c +++ b/components/lwp/lwp_pid.c @@ -431,11 +431,11 @@ void lwp_free(struct rt_lwp* lwp) /* for parent */ { - extern struct termios old_stdin_termios; + struct termios *old_stdin_termios = get_old_termios(); struct rt_lwp *self_lwp = (struct rt_lwp *)lwp_self(); if (lwp->session == -1) { - tcsetattr(1, 0, &old_stdin_termios); + tcsetattr(1, 0, old_stdin_termios); } if (lwp->tty != RT_NULL) { -- Gitee From 27fe6ef2e8f2a04907dfb30900c3c00e470f01d0 Mon Sep 17 00:00:00 2001 From: linzhenxing Date: Wed, 30 Mar 2022 14:55:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/tty/n_tty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c index fcbe036373..955f733098 100644 --- a/components/drivers/tty/n_tty.c +++ b/components/drivers/tty/n_tty.c @@ -529,7 +529,7 @@ static void eraser(unsigned char c, struct tty_struct *tty) * * Locking: ctrl_lock */ -extern struct termios old_stdin_termios; + static void __isig(int sig, struct tty_struct *tty) { struct rt_lwp *lwp = tty->foreground; -- Gitee