17 #include "get_next_line.h"
31 if (pipe(pipe_fd) == -1)
38 saved_fds[0] = dup(STDOUT_FILENO);
39 saved_fds[1] = dup(STDERR_FILENO);
79 dev_null = open(
"/dev/null", O_RDONLY);
82 dup2(dev_null, STDIN_FILENO);
85 dup2(pipe_fd[1], STDOUT_FILENO);
86 dup2(pipe_fd[1], STDERR_FILENO);
114 dup2(saved_fds[0], STDOUT_FILENO);
115 dup2(saved_fds[1], STDERR_FILENO);
118 waitpid(pid, &status, 0);
119 if (WIFEXITED(status))
120 sh->
ui->out.exit_code = WEXITSTATUS(status);
122 sh->
ui->out.exit_code = 1;
123 if (sh->
ui->out.exit_code == 0)
143 if (!shell || !shell->
ui)
Environment variable management prototypes.
void free_env_list(t_env **env_list)
Free all nodes in the env linked list.
static void handle_fork_error(t_ui *ui, int *pipe_fd, int *saved_fds)
Clean up after a failed fork & report the error to the UI.
static void exec_child(int *pipe_fd, int *saved_fds, t_shell *shell)
Redirect I/O to the pipe and run the command.
static int init_pipe_and_fds(int *pipe_fd, int *saved_fds, t_ui *ui)
Create a pipe and save current STDOUT / STDERR file descriptors.
void execute_minishell_cmd(t_shell *shell)
Fork a child to execute a minishell command & capture its output.
static void exec_parent(int *pipe_fd, int *saved_fds, t_shell *sh, pid_t pid)
Collect output, restore I/O and wait for child.
int process_ui_input(char *input, t_shell *shell)
Full pipeline inside the UI.
void read_output_from_fd(t_ui *ui, int fd)
Read all available bytes from fd and split into output lines.
UI mode structures, macros & function prototypes.
void out_free(t_out *out)
Clear all output lines and free the lines pointer array.
void out_add_line(t_out *out, const char *line)
Append a duplicate of a line to the output buffer.
int exit_code
Last command exit code.
t_env * env
Environment linked list.
struct s_ui * ui
UI state (NULL if off)
void update_waifu_mood(t_ui *ui, int mood)
Set the waifu mood.