MiniDevil
As beautiful as a shell
Command execution: forks and execs external commands. More...
#include <sys/stat.h>#include <sys/wait.h>#include <signal.h>#include <stdio.h>#include <errno.h>#include "executor.h"#include "libft.h"#include "env.h"#include "ast.h"#include "signals.h"#include "get_next_line.h"
Include dependency graph for exec_cmd.c:Command execution: forks and execs external commands.
Definition in file exec_cmd.c.
Functions | |
| static void | handle_exec_error (char *path) |
| Print an error for when execve fails. More... | |
| static void | child_execute (char *path, char **args, char **envp, t_shell *shell) |
| Replace current process with the external command (execve) More... | |
| static int | wait_for_child (pid_t pid) |
| Wait for a child process and get the correct exit status. More... | |
| static int | prepare_exec (char **args, t_env *env, char **path, char ***envp) |
| Resolve the command's path and build envp array before forking. More... | |
| int | exec_external (char **args, t_shell *shell) |
| Fork and execute an external command. More... | |
|
static |
Print an error for when execve fails.
Fallback is EACCES (Permission denied) because it's the most likely otherwise
| path | Path that failed to execute |
Definition at line 32 of file exec_cmd.c.
Referenced by child_execute().
Here is the caller graph for this function:
|
static |
Replace current process with the external command (execve)
| path | Resolved path (free on failure) |
| args | Argument array for execve |
| envp | Environment array for execve (free on failure) |
| shell | Shell context (free on failure) |
Definition at line 61 of file exec_cmd.c.
References t_shell::current_ast, t_shell::current_input, t_shell::env, free_ast(), free_env_list(), handle_exec_error(), and reset_child_signals().
Referenced by exec_external().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Wait for a child process and get the correct exit status.
Handles normal exits (WEXITSTATUS) and signal deaths (128 + signal)
| pid | PID of the child to wait for |
Definition at line 85 of file exec_cmd.c.
Referenced by exec_external().
Here is the caller graph for this function:
|
static |
Resolve the command's path and build envp array before forking.
Handles special cases: . and ..
| args | Argument array with arg[0] being the command name |
| env | Environment list (for PATH) |
| path | resolved path |
| envp | envp array |
Definition at line 116 of file exec_cmd.c.
References env_to_array(), exec_cmd_not_found(), and find_cmd_path().
Referenced by exec_external().
Here is the call graph for this function:
Here is the caller graph for this function:| int exec_external | ( | char ** | args, |
| t_shell * | shell | ||
| ) |
Fork and execute an external command.
Resolves the path, builds envp and forks a child that calls execve
| args | Argument array with arg[0] being the command name |
| shell | Shell context |
Definition at line 150 of file exec_cmd.c.
References child_execute(), t_shell::env, t_shell::is_child, prepare_exec(), and wait_for_child().
Referenced by exec_simple_command().
Here is the call graph for this function:
Here is the caller graph for this function: