Replaces system/exec to use execve/waitpid
git-svn-id: file:///home/svn/framework3/trunk@5166 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
a3e365c2b5
commit
39ed1257d1
|
@ -12,9 +12,8 @@
|
|||
/* XXX: Re-do help to specify a category and print the commands in that category? */
|
||||
void cmd_help(int, char * []);
|
||||
void cmd_fork(int, char * []);
|
||||
void cmd_exec(char *);
|
||||
/* XXX: system sucks, it may block, we need a better solution that backgrounds it */
|
||||
void cmd_system(char *);
|
||||
void cmd_exec(int, char * []);
|
||||
void cmd_system(int, char * []);
|
||||
void cmd_quit(int, char * []);
|
||||
|
||||
/* File descriptor handling */
|
||||
|
|
|
@ -94,15 +94,39 @@ void cmd_fork(int argc, char * argv[])
|
|||
signal(SIGCHLD, &sig_chld_waitpid);
|
||||
}
|
||||
|
||||
void cmd_exec(char * string)
|
||||
void cmd_exec(int argc, char * argv[])
|
||||
{
|
||||
execl("/bin/sh", "sh", "-c", string, NULL);
|
||||
perror("execl");
|
||||
int i;
|
||||
char *prog;
|
||||
|
||||
argv++;
|
||||
|
||||
prog = argv[0];
|
||||
|
||||
printf("Executing");
|
||||
for(i=0; argv[i]; i++) {
|
||||
printf(" %s", argv[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
execve(prog, argv, NULL);
|
||||
perror("execve");
|
||||
}
|
||||
|
||||
void cmd_system(char * string)
|
||||
void cmd_system(int argc, char * argv[])
|
||||
{
|
||||
system(string);
|
||||
pid_t fork_pid;
|
||||
|
||||
signal(SIGCHLD, &sig_chld_ignore);
|
||||
if((fork_pid = fork()) != 0)
|
||||
{
|
||||
while(waitpid(fork_pid, NULL, WNOHANG) <= 0)
|
||||
usleep(300);
|
||||
} else {
|
||||
cmd_exec(argc, argv);
|
||||
exit(0);
|
||||
}
|
||||
signal(SIGCHLD, &sig_chld_waitpid);
|
||||
}
|
||||
|
||||
void cmd_quit(int argc, char * argv[])
|
||||
|
|
|
@ -33,8 +33,8 @@ struct __cmdhandler handlerlist[] =
|
|||
{
|
||||
{ "help", &cmd_help, 1, 0, 0 },
|
||||
{ "fork", &cmd_fork, 1, 0, 0 },
|
||||
{ "exec", &cmd_exec, 0, 0, 0 },
|
||||
{ "system", &cmd_system, 0, 0, 0 },
|
||||
{ "exec", &cmd_exec, 1, 1, 14 },
|
||||
{ "system", &cmd_system, 1, 1, 14 },
|
||||
{ "quit", &cmd_quit, 1, 0, 0 },
|
||||
{ "exit", &cmd_quit, 1, 0, 0 },
|
||||
|
||||
|
@ -167,7 +167,8 @@ int main(void)
|
|||
void parse(char * str, int * const argc, char * argv[])
|
||||
{
|
||||
*argc = 0;
|
||||
|
||||
argv[0] = '\0';
|
||||
|
||||
if(strlen(str) == 0)
|
||||
return;
|
||||
|
||||
|
@ -177,6 +178,7 @@ void parse(char * str, int * const argc, char * argv[])
|
|||
{
|
||||
*str = '\0';
|
||||
argv[(*argc)++] = str+1;
|
||||
argv[(*argc)] = '\0';
|
||||
}
|
||||
if(*str == '\\')
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue