feat(compiling en fait): Execution
This commit is contained in:
parent
08803bd591
commit
6ca10b673a
4 changed files with 15 additions and 20 deletions
|
|
@ -42,16 +42,15 @@ static int set_all_redir(struct list *redir_list)
|
|||
{
|
||||
while (redir_list)
|
||||
{
|
||||
struct ast_redir *redir = (struct ast_redir *)redir_list->data;
|
||||
struct ast *redir_node = (struct ast *)redir_list->data;
|
||||
struct ast_redir *redir = ast_get_redir(redir_node);
|
||||
int target_fd;
|
||||
|
||||
if (redir->io_number != -1)
|
||||
{
|
||||
target_fd = redir->io_number;
|
||||
}
|
||||
else
|
||||
{
|
||||
// assign target_fd depending on redir type
|
||||
if (redir->type == AST_REDIR_TYPE_LESS
|
||||
|| redir->type == AST_REDIR_TYPE_LESSGREAT
|
||||
|| redir->type == AST_REDIR_TYPE_LESSAND)
|
||||
|
|
@ -63,7 +62,6 @@ static int set_all_redir(struct list *redir_list)
|
|||
target_fd = 1;
|
||||
}
|
||||
}
|
||||
|
||||
redir->saved_fd = dup(target_fd);
|
||||
int new_fd = -1;
|
||||
int flags = 0;
|
||||
|
|
@ -130,8 +128,7 @@ static int try_builtin(char **argv, struct hash_map *vars);
|
|||
int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
||||
{
|
||||
(void)vars;
|
||||
set_all_redir(command->redirections ? command->redirections->children
|
||||
: NULL);
|
||||
set_all_redir(command->redirections);
|
||||
|
||||
if (!command || !(command->command))
|
||||
{
|
||||
|
|
@ -142,8 +139,7 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
|||
if (!argv || !(argv[0]))
|
||||
{
|
||||
free(argv);
|
||||
unset_all_redir(command->redirections ? command->redirections->children
|
||||
: NULL);
|
||||
unset_all_redir(command->redirections);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -151,8 +147,7 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
|||
if (builtin_ret != -1)
|
||||
{
|
||||
free(argv);
|
||||
unset_all_redir(command->redirections ? command->redirections->children
|
||||
: NULL);
|
||||
unset_all_redir(command->redirections);
|
||||
return builtin_ret;
|
||||
}
|
||||
|
||||
|
|
@ -161,8 +156,7 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
|||
{
|
||||
perror("fork");
|
||||
free(argv);
|
||||
unset_all_redir(command->redirections ? command->redirections->children
|
||||
: NULL);
|
||||
unset_all_redir(command->redirections);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -170,16 +164,14 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars)
|
|||
{
|
||||
execvp(argv[0], argv);
|
||||
perror("execvp");
|
||||
unset_all_redir(command->redirections ? command->redirections->children
|
||||
: NULL);
|
||||
unset_all_redir(command->redirections);
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
int status = 0;
|
||||
waitpid(pid, &status, 0);
|
||||
free(argv);
|
||||
unset_all_redir(command->redirections ? command->redirections->children
|
||||
: NULL);
|
||||
unset_all_redir(command->redirections);
|
||||
|
||||
if (WIFEXITED(status))
|
||||
{
|
||||
|
|
@ -233,7 +225,8 @@ void unset_all_redir(struct list *redir_list)
|
|||
{
|
||||
while (redir_list)
|
||||
{
|
||||
struct ast_redir *redir = (struct ast_redir *)redir_list->data;
|
||||
struct ast *redir_node = (struct ast *)redir_list->data;
|
||||
struct ast_redir *redir = ast_get_redir(redir_node);
|
||||
int target_fd;
|
||||
if (redir->io_number != -1)
|
||||
{
|
||||
|
|
@ -258,7 +251,6 @@ void unset_all_redir(struct list *redir_list)
|
|||
close(redir->saved_fd);
|
||||
redir->saved_fd = -1;
|
||||
}
|
||||
|
||||
redir_list = redir_list->next;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue