23 #include "get_next_line.h"
37 if (stat(path, &buf) == 0 && S_ISDIR(buf.st_mode))
38 msg =
": Is a directory\n";
39 else if (errno == ENOENT)
40 msg =
": No such file or directory\n";
41 else if (errno == ENOEXEC)
42 msg =
": Exec format error\n";
44 msg =
": Permission denied\n";
45 ft_putstr_fd(
"minishell: ", STDERR_FILENO);
46 ft_putstr_fd(path, STDERR_FILENO);
47 ft_putstr_fd(msg, STDERR_FILENO);
64 if (execve(path, args, envp) == -1)
68 ft_free_strarray(envp);
91 waitpid(pid, &status, 0);
92 if (WIFEXITED(status))
93 exit_code = WEXITSTATUS(status);
94 else if (WIFSIGNALED(status))
96 if (WTERMSIG(status) == SIGINT)
97 ft_putchar_fd(
'\n', STDERR_FILENO);
98 else if (WTERMSIG(status) == SIGQUIT)
99 ft_putstr_fd(
"Quit (core dumped)\n", STDERR_FILENO);
100 exit_code = 128 + WTERMSIG(status);
118 if (ft_strncmp(args[0],
".", 2) == 0)
120 ft_putstr_fd(
"minishell: .: filename argument required\n",
122 ft_putstr_fd(
".: usage: . filename [arguments]\n", STDERR_FILENO);
125 if (ft_strncmp(args[0],
"..", 3) == 0)
157 if (!args || !args[0])
167 perror(
"minishell: fork");
168 return (free(path), ft_free_strarray(envp), 1);
174 ft_free_strarray(envp);
AST node creation and destruction prototypes.
void free_ast(t_ast *node)
Recursively free an entire AST tree.
Environment variable management prototypes.
char ** env_to_array(t_env *env)
Convert the env linked list to a NULL terminated string array.
void free_env_list(t_env **env_list)
Free all nodes in the env linked list.
static void handle_exec_error(char *path)
Print an error for when execve fails.
static void child_execute(char *path, char **args, char **envp, t_shell *shell)
Replace current process with the external command (execve)
int exec_external(char **args, t_shell *shell)
Fork and execute an external command.
static int wait_for_child(pid_t pid)
Wait for a child process and get the correct exit status.
static int prepare_exec(char **args, t_env *env, char **path, char ***envp)
Resolve the command's path and build envp array before forking.
int exec_cmd_not_found(char *cmd)
Print "command not found" to STDERR.
Executor prototypes for commands, pipes, redirections & heredocs.
char * find_cmd_path(char *cmd, t_env *env)
Resolve a command name into its full executable path.
void reset_child_signals(void)
Reset signals to default behavior for the child processes.
Signal handler prototypes.
Environment variable (doubly linked list)
t_env * env
Environment linked list.
int is_child
Child flag (to avoid leaks)
char * current_input
Current input line.
struct s_ast * current_ast
Currently executing AST.