!541 feat: 自研shell命令回补
Merge pull request !541 from Kiita/shell_cmd_0812
This commit is contained in:
commit
fb5df47b6c
|
@ -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));
|
||||||
|
|
Loading…
Reference in New Issue