Explorar o código

将全局变量修改成函数调用

linzhenxing %!s(int64=3) %!d(string=hai) anos
pai
achega
1efb2ddd4a

+ 5 - 2
components/drivers/tty/n_tty.c

@@ -10,6 +10,7 @@
 #include <stddef.h>
 #include <ctype.h>
 #include <tty.h>
+#include <lwp.h>
 #if defined(RT_USING_POSIX)
 #include <posix_termios.h>
 #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;  

+ 3 - 2
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;

+ 6 - 1
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;

+ 1 - 0
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);

+ 2 - 2
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)
         {