MiniDevil
As beautiful as a shell
Command execution from UI (forks, captures output, updates mood) More...
#include <sys/wait.h>#include <fcntl.h>#include "minishell_ui.h"#include "env.h"#include "get_next_line.h"
Include dependency graph for execute.c:Command execution from UI (forks, captures output, updates mood)
Definition in file execute.c.
Functions | |
| 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. More... | |
| 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. More... | |
| static void | exec_child (int *pipe_fd, int *saved_fds, t_shell *shell) |
| Redirect I/O to the pipe and run the command. More... | |
| 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. More... | |
| void | execute_minishell_cmd (t_shell *shell) |
| Fork a child to execute a minishell command & capture its output. More... | |
|
static |
Create a pipe and save current STDOUT / STDERR file descriptors.
On pipe failure it sets exit_code = 1 and waifu's mood to upset
| pipe_fd | 2 element array to receive the pipe read and write ends |
| saved_fds | 2 elements array to receive the duped STDOUT and STDERR |
| ui | UI state |
Definition at line 29 of file execute.c.
References t_out::exit_code, MOOD_UPSET, t_ui::out, out_add_line(), and update_waifu_mood().
Referenced by execute_minishell_cmd().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Clean up after a failed fork & report the error to the UI.
| ui | UI state |
| pipe_fd | The pipe ends to close |
| saved_fds | The saved STDOUT / STDERR to close |
Definition at line 50 of file execute.c.
References t_out::exit_code, MOOD_UPSET, t_ui::out, out_add_line(), and update_waifu_mood().
Referenced by execute_minishell_cmd().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Redirect I/O to the pipe and run the command.
/dev/null and STDOUT & STDERR to the pipe write end| pipe_fd | Pipe read and write ends |
| saved_fds | Saved STDOUT / STDERR originals to close |
| shell | Shell state |
Definition at line 71 of file execute.c.
References t_shell::env, free_env_list(), out_free(), process_ui_input(), and t_shell::ui.
Referenced by execute_minishell_cmd().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Collect output, restore I/O and wait for child.
| pipe_fd | The pipe read and write ends |
| saved_fds | Saved STDOUT / STDERR to restore |
| sh | Shell state (owns the UI) |
| pid | PID of the child to wait for |
Definition at line 107 of file execute.c.
References MOOD_PROUD, MOOD_UPSET, read_output_from_fd(), t_shell::ui, and update_waifu_mood().
Referenced by execute_minishell_cmd().
Here is the call graph for this function:
Here is the caller graph for this function:| void execute_minishell_cmd | ( | t_shell * | shell | ) |
Fork a child to execute a minishell command & capture its output.
Creates a pipe, forks, runs exec_child() in the child and exec_parent() in the parent
| shell | Shell state (contains command buffer and UI output) |
Definition at line 137 of file execute.c.
References exec_child(), exec_parent(), handle_fork_error(), init_pipe_and_fds(), MOOD_HAPPY, t_shell::ui, and update_waifu_mood().
Referenced by cmd_execute().
Here is the call graph for this function:
Here is the caller graph for this function: