began to reimplement the new execution
This commit is contained in:
parent
0d425aa44c
commit
28b2e82078
1 changed files with 41 additions and 5 deletions
|
|
@ -72,7 +72,9 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
|||
waitpid(pid, &status, 0);
|
||||
free(argv);
|
||||
if (WIFEXITED(status))
|
||||
{
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +123,7 @@ static int get_fd_target(const struct ast_redir *redir)
|
|||
if (redir->io_number != -1)
|
||||
return redir->io_number;
|
||||
if (redir->type == AST_REDIR_TYPE_LESS
|
||||
|| redir->type == AST_REDIR_TYPE_LESSGREAT
|
||||
|| redir->type == AST_REDIR_TYPE_DLESS
|
||||
|| redir->type == AST_REDIR_TYPE_LESSAND)
|
||||
return 0;
|
||||
return 1;
|
||||
|
|
@ -163,6 +165,43 @@ static int handle_and_restore_fd(int saved_fd, int fd_target)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
static open_all_redir(const struct ast_list redir_list)
|
||||
{
|
||||
while (redir_list){
|
||||
struct ast_redir *redir = (struct ast_redir*)redir_list->data;
|
||||
int target_fd;
|
||||
if (redir->io_number != -1)
|
||||
{
|
||||
target_fd = redir->io_number;
|
||||
}
|
||||
else
|
||||
{
|
||||
// assign target_fd depending on redir type
|
||||
}
|
||||
|
||||
int saved_fd = dup(target_fd);
|
||||
|
||||
// if redir type is not with '&'
|
||||
// then we open("filename")
|
||||
// else, no need to open, just new_fd = atoi(filename)
|
||||
|
||||
open();
|
||||
|
||||
dup2(target_fd, new_fd);
|
||||
|
||||
close(new_fd);
|
||||
|
||||
// append target_fd and saved_fd to a list
|
||||
// in order to be able to restore all the fds
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
/*
|
||||
int exec_ast_redir(struct ast_redir *redir, struct hash_map *vars)
|
||||
{
|
||||
int fd_target = get_fd_target(redir);
|
||||
|
|
@ -206,7 +245,7 @@ int exec_ast_redir(struct ast_redir *redir, struct hash_map *vars)
|
|||
int ret = execution(redir->child, vars);
|
||||
handle_and_restore_fd(saved_fd, fd_target);
|
||||
return ret;
|
||||
}
|
||||
} */
|
||||
|
||||
// --- Builtins ---
|
||||
|
||||
|
|
@ -234,7 +273,6 @@ static int builtin_echo(char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int builtin_true(char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
|
|
@ -256,7 +294,6 @@ static int builtin_exit(char **argv)
|
|||
return exit_val;
|
||||
}
|
||||
|
||||
|
||||
static int builtin_cd(char **argv)
|
||||
{
|
||||
const char *path = argv[1];
|
||||
|
|
@ -277,7 +314,6 @@ static int builtin_cd(char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tries to execute a builtin command if the command matches a builtin
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue