diff --git a/components/drivers/tty/n_tty.c b/components/drivers/tty/n_tty.c index 38bfd9006062e31ccf5bbd73775ee3ee2d1eebe3..955f733098a285de2e9ce25b3a7c89101f17ed5f 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 @@ -532,9 +533,30 @@ static void eraser(unsigned char c, struct tty_struct *tty) static void __isig(int sig, struct tty_struct *tty) { struct rt_lwp *lwp = tty->foreground; + struct tty_ldisc *ld = RT_NULL; + struct termios old_termios; + struct termios *new_termios = get_old_termios(); + if (lwp) { - lwp_kill(lwp_to_pid(lwp), sig); + 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_termios); + } + } + tty->foreground = RT_NULL; + } + else + { + lwp_kill(lwp_to_pid(lwp), sig); + } } } diff --git a/components/drivers/tty/tty_ioctl.c b/components/drivers/tty/tty_ioctl.c index 894353ed845f52d4e0c4c36e10bf5c1dd22c92ad..fb178a65aca9392b90820405059533c66930ff10 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 02b08d48561b464b8fbd38c8e2c0e1ace3492932..d586d33bac2f6f3652300665bf2beab3aff2ad79 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 823231240cf3c1d53aed331af61f70d4624c8ff5..f65c2a94a59e3dedd2710738af1ff3b8acc02e5c 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 3b926de23677e63870775d62c8e20a31c1ec64b0..1b4696d78e6ec3ef32a6ea4f99fd123b24a2971f 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) {