void exec(t_cmd *cmd) { pid_t pid; int stat; stat = 0; if (ft_strchr(cmd->tab[0], '/')) cmd->bin = 1; if (!sh_cmd(cmd)) return ; else if (cmd->bin == 1 || check_bin(cmd)) { gestion_signal(1); if ((pid = fork()) < 0) sh_error(1, cmd, -1); else if (pid == 0) if ((stat = execve(cmd->cmd, cmd->tab, cmd->env)) == -1) sh_error(2, cmd, stat); wait(&stat); if (WIFEXITED(stat)) cmd->ret = WEXITSTATUS(stat); else if (WIFSIGNALED(stat)) signal_message_exec(WTERMSIG(stat)); gestion_signal(0); } else sh_error(0, cmd, 0); }
int main(int argc, char **argv, char **env) { int fd; get_env(env, 's'); sh_increase_shlvl(); fd = 0; if (argc == 2) fd = open(argv[1], O_RDONLY); else if (argc > 2) ft_putendl("Sorry, too many files to handle. Only one at a time"); else { gestion_signal(0); ft_putendl("Welcome in this basic shell."); sh_help(); } if (fd >= 0) { sh_boucle_lecture(fd); close(fd); } else ft_putendl("An error occured: Could not open the file"); return (0); }