提交 7bc68f45 编写于 作者: Yansira's avatar Yansira

feat: 自研shell命令回补

【背景】liteos_a需要支持toybox缺失的自研shell命令

【修改方案】
新增自研shell命令的入口判断场景,使得mksh可以执行自研shell的命令

re #I44U0H
Signed-off-by: Yansira's avataryansira <yansira@hotmail.com>
Change-Id: Idf08cb6df456bd6c89fe8fe505317f1c0ca61eda
上级 2b9c55fd
......@@ -35,7 +35,7 @@
#include "semaphore.h"
#include "securec.h"
#include "unistd.h"
#include <sys/syscall.h>
ShellCB *g_shellCB = NULL;
......@@ -88,11 +88,44 @@ OUT:
return ret;
}
int main()
static int DoShellExec(char **argv)
{
int i, j;
int len = 0;
int ret = SH_NOK;
char *cmdLine = NULL;
for (i = 0; argv[i]; i++) {
len += strlen(argv[i]);
}
len += i + 1;
cmdLine = (char *)malloc(len);
if (!cmdLine) {
return ret;
}
memset_s(cmdLine, len, 0, len);
for(j = 0; j < i; j++) {
strcat_s(cmdLine, len, argv[j]);
strcat_s(cmdLine, len, " ");
}
cmdLine[len - 2] = '\0';
ret = syscall(__NR_shellexec, argv[0], cmdLine);
free(cmdLine);
return ret;
}
int main(int argc, char **argv)
{
int ret = SH_NOK;
ShellCB *shellCB = NULL;
if (!strcmp(argv[0], "shell") && argv[1]) {
ret = DoShellExec(argv + 1);
return ret;
}
setbuf(stdout, NULL);
shellCB = (ShellCB *)malloc(sizeof(ShellCB));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册