浏览代码

修复后台运行进程的bug。打印使用log_e

linzhenxing 3 年之前
父节点
当前提交
deb998be65
共有 2 个文件被更改,包括 24 次插入9 次删除
  1. 21 7
      components/lwp/lwp.c
  2. 3 2
      components/lwp/lwp_syscall.c

+ 21 - 7
components/lwp/lwp.c

@@ -1008,7 +1008,7 @@ void lwp_cleanup(struct rt_thread *tid)
 {
     rt_base_t level;
     struct rt_lwp *lwp;
-    struct tty_node *tty_head;
+    struct tty_node *tty_head = RT_NULL;
 
     if (tid == NULL)
     {
@@ -1023,10 +1023,16 @@ void lwp_cleanup(struct rt_thread *tid)
     lwp_tid_put(tid->tid);
     rt_list_remove(&tid->sibling);
     rt_hw_interrupt_enable(level);
-    tty_head = lwp->tty->head;
+    if (lwp->tty != RT_NULL)
+    {
+        tty_head = lwp->tty->head;
+    }
     if (!lwp_ref_dec(lwp))
     {
-        tty_pop(&tty_head, lwp);
+        if (tty_head)
+        {
+            tty_pop(&tty_head, lwp);
+        }
     }
     
     return;
@@ -1212,11 +1218,15 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
                     old_lwp = tty->foreground;
                     rt_mutex_take(&tty->mutex, RT_WAITING_FOREVER);
                     ret = tty_push(&tty->head, old_lwp);
+                    rt_mutex_release(&tty->mutex);
                     if (ret < 0)
                     {
-                        rt_kprintf("malloc fail!\n");
+                        lwp_tid_put(tid);
+                        lwp_ref_dec(lwp);
+                        LOG_E("malloc fail!\n");
+                        return -ENOMEM;
                     }
-                    rt_mutex_release(&tty->mutex);
+                    
                     lwp->tty = tty;
                     lwp->tty->pgrp = lwp->__pgrp;
                     lwp->tty->session = lwp->session;
@@ -1232,11 +1242,15 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
                     {
                         rt_mutex_take(&self_lwp->tty->mutex, RT_WAITING_FOREVER);
                         ret = tty_push(&self_lwp->tty->head, self_lwp);
+                        rt_mutex_release(&self_lwp->tty->mutex);
                         if (ret < 0)
                         {
-                            rt_kprintf("malloc fail!\n");
+                            lwp_tid_put(tid);
+                            lwp_ref_dec(lwp);
+                            LOG_E("malloc fail!\n");
+                            return -ENOMEM;
                         }
-                        rt_mutex_release(&self_lwp->tty->mutex);
+                        
                         lwp->tty = self_lwp->tty;
                         lwp->tty->pgrp = lwp->__pgrp;
                         lwp->tty->session = lwp->session;

+ 3 - 2
components/lwp/lwp_syscall.c

@@ -1731,12 +1731,13 @@ int _sys_fork(void)
         old_lwp = lwp->tty->foreground;
         rt_mutex_take(&lwp->tty->mutex, RT_WAITING_FOREVER);
         ret = tty_push(&lwp->tty->head, old_lwp);
+        rt_mutex_release(&lwp->tty->mutex);
         if (ret < 0)
         {
-            rt_kprintf("malloc fail!\n");
+            LOG_E("malloc fail!\n");
             goto fail;
         }
-        rt_mutex_release(&lwp->tty->mutex);
+        
         lwp->tty->foreground = lwp;
     }
     rt_hw_interrupt_enable(level);