feat: 自研shell命令回补

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

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

re #I44U0H

Signed-off-by: yansira <yansira@hotmail.com>
Change-Id: Idf08cb6df456bd6c89fe8fe505317f1c0ca61eda
This commit is contained in:
Kiita 2021-08-12 11:28:40 +08:00
parent 2b9c55fd90
commit 7bc68f454f
1 changed files with 35 additions and 2 deletions

View File

@ -35,7 +35,7 @@
#include "semaphore.h" #include "semaphore.h"
#include "securec.h" #include "securec.h"
#include "unistd.h" #include "unistd.h"
#include <sys/syscall.h>
ShellCB *g_shellCB = NULL; ShellCB *g_shellCB = NULL;
@ -88,11 +88,44 @@ OUT:
return ret; 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; int ret = SH_NOK;
ShellCB *shellCB = NULL; ShellCB *shellCB = NULL;
if (!strcmp(argv[0], "shell") && argv[1]) {
ret = DoShellExec(argv + 1);
return ret;
}
setbuf(stdout, NULL); setbuf(stdout, NULL);
shellCB = (ShellCB *)malloc(sizeof(ShellCB)); shellCB = (ShellCB *)malloc(sizeof(ShellCB));