began to reimplement the new execution

This commit is contained in:
Jean 2026-01-28 21:55:55 +01:00 committed by matteo
parent 050a1909f0
commit ed64a1bc18

View file

@ -72,7 +72,9 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars)
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
free(argv); free(argv);
if (WIFEXITED(status)) if (WIFEXITED(status))
{
return WEXITSTATUS(status); return WEXITSTATUS(status);
}
return 1; return 1;
} }
@ -121,7 +123,7 @@ static int get_fd_target(const struct ast_redir *redir)
if (redir->io_number != -1) if (redir->io_number != -1)
return redir->io_number; return redir->io_number;
if (redir->type == AST_REDIR_TYPE_LESS 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) || redir->type == AST_REDIR_TYPE_LESSAND)
return 0; return 0;
return 1; return 1;
@ -163,6 +165,43 @@ static int handle_and_restore_fd(int saved_fd, int fd_target)
return 0; 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 exec_ast_redir(struct ast_redir *redir, struct hash_map *vars)
{ {
int fd_target = get_fd_target(redir); 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); int ret = execution(redir->child, vars);
handle_and_restore_fd(saved_fd, fd_target); handle_and_restore_fd(saved_fd, fd_target);
return ret; return ret;
} } */
// --- Builtins --- // --- Builtins ---
@ -234,7 +273,6 @@ static int builtin_echo(char **argv)
return 0; return 0;
} }
static int builtin_true(char **argv) static int builtin_true(char **argv)
{ {
(void)argv; (void)argv;
@ -256,7 +294,6 @@ static int builtin_exit(char **argv)
return exit_val; return exit_val;
} }
static int builtin_cd(char **argv) static int builtin_cd(char **argv)
{ {
const char *path = argv[1]; const char *path = argv[1];
@ -277,7 +314,6 @@ static int builtin_cd(char **argv)
return 0; return 0;
} }
/** /**
* @brief Tries to execute a builtin command if the command matches a builtin * @brief Tries to execute a builtin command if the command matches a builtin
* *