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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ libutils_a_SOURCES = \
|
|||
ast/ast_neg.c \
|
||||
ast/ast_pipe.c \
|
||||
args/args.c \
|
||||
vars/vars.c
|
||||
vars/vars.c \
|
||||
ast/ast_assignment.c
|
||||
|
||||
libutils_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "ast_assignment.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
bool ast_is_assignment(struct ast *node)
|
||||
{
|
||||
|
|
@ -40,7 +41,7 @@ struct ast *ast_create_assignment(char *assignment)
|
|||
if (!assignment_data)
|
||||
return NULL;
|
||||
|
||||
init_assignments(assignement_data);
|
||||
init_assignments(assignment_data, assignment);
|
||||
return ast_create(AST_ASSIGNMENT, assignment_data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ struct ast *ast_create_command(struct list *command, struct list *redirections,
|
|||
|
||||
command_data->command = command;
|
||||
command_data->redirections = redirections;
|
||||
command_data->assignments = assignments;
|
||||
|
||||
return ast_create(AST_CMD, command_data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue