Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
5077b179
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
460
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5077b179
编写于
11月 05, 2021
作者:
O
openharmony_ci
提交者:
Gitee
11月 05, 2021
浏览文件
操作
浏览文件
下载
差异文件
!693 fix: 修复Ctrl+C会终止所有进程的问题
Merge pull request !693 from huangshan/fix-pgrp
上级
e99aba9d
cdc0877f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
53 addition
and
35 deletion
+53
-35
apps/shell/include/shmsg.h
apps/shell/include/shmsg.h
+5
-2
apps/shell/src/main.c
apps/shell/src/main.c
+4
-1
apps/shell/src/shmsg.c
apps/shell/src/shmsg.c
+33
-20
kernel/common/console.c
kernel/common/console.c
+7
-8
kernel/common/console.h
kernel/common/console.h
+1
-1
kernel/common/los_magickey.c
kernel/common/los_magickey.c
+2
-2
kernel/common/los_magickey.h
kernel/common/los_magickey.h
+1
-1
未找到文件。
apps/shell/include/shmsg.h
浏览文件 @
5077b179
...
...
@@ -43,8 +43,10 @@ extern "C" {
#define SHELL_ENTRY_STACKSIZE 0x1000
#define SHELL_TASK_STACKSIZE 0x3000
#define SHELL_EXEC_COMMAND "exec "
#define SHELL_EXEC_COMMAND_BYTES 5
#define SHELL_EXEC_COMMAND "exec"
#define SHELL_EXEC_COMMAND_BYTES 4
#define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" "
#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES+1)
#define CONSOLE_IOC_MAGIC 'c'
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
...
...
@@ -57,6 +59,7 @@ extern "C" {
typedef
void
(
*
OutputFunc
)(
const
char
*
fmt
,
...);
extern
int
ShellTaskInit
(
ShellCB
*
shellCB
);
extern
int
ShellEntryInit
(
ShellCB
*
shellCB
);
extern
void
ChildExec
(
const
char
*
cmdName
,
char
*
const
paramArray
[]);
extern
void
ShellCmdLineParse
(
char
c
,
OutputFunc
outputFunc
,
ShellCB
*
shellCB
);
extern
int
ShellNotify
(
ShellCB
*
shellCB
);
...
...
apps/shell/src/main.c
浏览文件 @
5077b179
...
...
@@ -97,6 +97,9 @@ static int DoShellExec(char **argv)
int
ret
=
SH_NOK
;
char
*
cmdLine
=
NULL
;
if
(
strncmp
(
argv
[
0
],
SHELL_EXEC_COMMAND
,
SHELL_EXEC_COMMAND_BYTES
)
==
0
)
{
ChildExec
(
argv
[
1
],
argv
+
1
);
}
for
(
i
=
0
;
argv
[
i
];
i
++
)
{
len
+=
strlen
(
argv
[
i
]);
}
...
...
@@ -123,7 +126,7 @@ int main(int argc, char **argv)
int
ret
=
SH_NOK
;
ShellCB
*
shellCB
=
NULL
;
if
(
!
strcmp
(
argv
[
0
],
"shell"
)
&&
argv
[
1
]
)
{
if
(
argc
>
1
)
{
ret
=
DoShellExec
(
argv
+
1
);
return
ret
;
}
...
...
apps/shell/src/shmsg.c
浏览文件 @
5077b179
...
...
@@ -331,38 +331,51 @@ char *GetCmdName(const char *cmdline, unsigned int len)
return
cmdName
;
}
void
ChildExec
(
const
char
*
cmdName
,
char
*
const
paramArray
[])
{
int
ret
;
pid_t
gid
;
ret
=
setpgrp
();
if
(
ret
==
-
1
)
{
exit
(
1
);
}
gid
=
getpgrp
();
if
(
gid
<
0
)
{
printf
(
"get group id failed, pgrpid %d, errno %d
\n
"
,
gid
,
errno
);
}
ret
=
tcsetpgrp
(
STDIN_FILENO
,
gid
);
if
(
ret
!=
0
)
{
printf
(
"tcsetpgrp failed, errno %d
\n
"
,
errno
);
}
ret
=
execve
(
cmdName
,
paramArray
,
NULL
);
if
(
ret
==
-
1
)
{
perror
(
"execve"
);
exit
(
-
1
);
}
}
static
void
DoCmdExec
(
const
char
*
cmdName
,
const
char
*
cmdline
,
unsigned
int
len
,
const
CmdParsed
*
cmdParsed
)
{
int
ret
;
pid_t
forkPid
;
pid_t
gid
;
if
(
strncmp
(
cmdline
,
SHELL_EXEC_COMMAND
,
SHELL
_EXEC_COMMAND_BYTES
)
==
0
)
{
if
(
strncmp
(
cmdline
,
CMD_EXEC_COMMAND
,
CMD
_EXEC_COMMAND_BYTES
)
==
0
)
{
forkPid
=
fork
();
if
(
forkPid
<
0
)
{
printf
(
"Faild to fork from shell
\n
"
);
return
;
}
else
if
(
forkPid
==
0
)
{
ret
=
setpgrp
();
if
(
ret
==
-
1
)
{
exit
(
1
);
}
gid
=
getpgrp
();
if
(
gid
<
0
)
{
printf
(
"get group id failed, pgrpid %d, errno %d
\n
"
,
gid
,
errno
);
}
ret
=
tcsetpgrp
(
STDIN_FILENO
,
gid
);
ChildExec
(
cmdParsed
->
paramArray
[
0
],
cmdParsed
->
paramArray
);
}
else
{
waitpid
(
forkPid
,
0
,
0
);
ret
=
tcsetpgrp
(
STDIN_FILENO
,
getpid
());
if
(
ret
!=
0
)
{
printf
(
"tcsetpgrp failed, errno %d
\n
"
,
errno
);
}
ret
=
execve
((
const
char
*
)
cmdParsed
->
paramArray
[
0
],
(
char
*
const
*
)
cmdParsed
->
paramArray
,
NULL
);
if
(
ret
==
-
1
)
{
perror
(
"execve"
);
exit
(
-
1
);
}
}
}
else
{
(
void
)
syscall
(
__NR_shellexec
,
cmdName
,
cmdline
);
...
...
@@ -419,7 +432,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
unsigned
int
removeLen
=
strlen
(
"./"
);
/* "./" needs to be removed if it exists */
unsigned
int
ret
;
char
*
newCmd
=
NULL
;
char
*
execCmd
=
SHELL
_EXEC_COMMAND
;
char
*
execCmd
=
CMD
_EXEC_COMMAND
;
const
char
*
cmdBuf
=
input
;
unsigned
int
cmdBufLen
=
strlen
(
cmdBuf
);
char
*
shiftStr
=
(
char
*
)
malloc
(
cmdBufLen
+
1
);
...
...
kernel/common/console.c
浏览文件 @
5077b179
...
...
@@ -436,17 +436,16 @@ STATIC VOID StoreReadChar(CONSOLE_CB *consoleCB, char ch, INT32 readcount)
}
}
VOID
KillPgrp
()
VOID
KillPgrp
(
UINT16
consoleId
)
{
INT32
consoleId
;
LosProcessCB
*
process
=
OsCurrProcessGet
();
if
((
process
->
consoleID
>
CONSOLE_NUM
-
1
)
||
(
process
->
consoleID
<
0
))
{
if
((
consoleId
>
CONSOLE_NUM
)
||
(
consoleId
<=
0
))
{
return
;
}
CONSOLE_CB
*
consoleCB
=
g_console
[
consoleId
-
1
];
/* the default of consoleCB->pgrpId is -1, may not be set yet, avoid killing all processes */
if
(
consoleCB
->
pgrpId
<
0
)
{
return
;
}
consoleId
=
process
->
consoleID
;
CONSOLE_CB
*
consoleCB
=
g_console
[
consoleId
];
(
VOID
)
OsKillLock
(
consoleCB
->
pgrpId
,
SIGINT
);
}
...
...
kernel/common/console.h
浏览文件 @
5077b179
...
...
@@ -124,7 +124,7 @@ extern INT32 GetFilepOps(const struct file *filep, struct file **privFilep, cons
extern
VOID
OsWaitConsoleSendTaskPend
(
UINT32
taskID
);
extern
VOID
OsWakeConsoleSendTask
(
VOID
);
#endif
extern
VOID
KillPgrp
(
VOID
);
extern
VOID
KillPgrp
(
UINT16
consoleId
);
/* console ioctl */
#define CONSOLE_IOC_MAGIC 'c'
...
...
kernel/common/los_magickey.c
浏览文件 @
5077b179
...
...
@@ -118,14 +118,14 @@ STATIC VOID OsMagicMemCheck(VOID)
}
#endif
INT32
CheckMagicKey
(
CHAR
key
)
INT32
CheckMagicKey
(
CHAR
key
,
UINT16
consoleId
)
{
#ifdef LOSCFG_ENABLE_MAGICKEY
INT32
i
;
STATIC
UINT32
magicKeySwitch
=
0
;
if
(
key
==
0x03
)
{
/* ctrl + c */
KillPgrp
();
KillPgrp
(
consoleId
);
return
0
;
}
else
if
(
key
==
0x12
)
{
/* ctrl + r */
magicKeySwitch
=
~
magicKeySwitch
;
...
...
kernel/common/los_magickey.h
浏览文件 @
5077b179
...
...
@@ -46,7 +46,7 @@ typedef struct {
CHAR
magicKey
;
}
MagicKeyOp
;
extern
INT32
CheckMagicKey
(
CHAR
key
);
extern
INT32
CheckMagicKey
(
CHAR
key
,
UINT16
consoleId
);
#ifdef __cplusplus
#if __cplusplus
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录