MiniDevil As beautiful as a shell
exec_utils.c File Reference

Execution utilities. More...

#include <sys/wait.h>
#include <stdio.h>
#include "executor.h"
#include "builtins.h"
#include "libft.h"
+ Include dependency graph for exec_utils.c:

Detailed Description

Execution utilities.

Definition in file exec_utils.c.

Functions

int exec_cmd_not_found (char *cmd)
 Print "command not found" to STDERR. More...
 
int is_builtin (char *cmd)
 Check if a command is a shell builtin. More...
 
int exec_builtin (char **args, t_shell *shell)
 Dispatch a builtin command to its function. More...
 
int exec_simple_command (char **args, t_shell *shell)
 Execute a simple command (builtin or external) More...
 
int pipe_fork_error (int pipe_fd[2], pid_t left_pid)
 Clean up pipe fds and wait for left child on fork failure. More...
 

Function Documentation

◆ exec_cmd_not_found()

int exec_cmd_not_found ( char *  cmd)

Print "command not found" to STDERR.

Parameters
cmdCommand name that wasn't found
Returns
always 127 (standard bash)

Definition at line 25 of file exec_utils.c.

Referenced by prepare_exec().

+ Here is the caller graph for this function:

◆ is_builtin()

int is_builtin ( char *  cmd)

Check if a command is a shell builtin.

Parameters
cmdCommand name to check
Returns
1 if builtin or 0 if external

Definition at line 39 of file exec_utils.c.

Referenced by exec_simple_command().

+ Here is the caller graph for this function:

◆ exec_builtin()

int exec_builtin ( char **  args,
t_shell shell 
)

Dispatch a builtin command to its function.

Parameters
argsArgument array with arg[0] being the command name
shellShell context
Returns
Exit status from the builtin function

Definition at line 67 of file exec_utils.c.

References builtin_cd(), builtin_echo(), builtin_env(), builtin_exit(), builtin_export(), builtin_pwd(), builtin_unset(), and t_shell::env.

Referenced by exec_simple_command().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exec_simple_command()

int exec_simple_command ( char **  args,
t_shell shell 
)

Execute a simple command (builtin or external)

Parameters
argsNULL terminated argument array
shellShell context
Returns
Exit status of the command

Definition at line 95 of file exec_utils.c.

References exec_builtin(), exec_external(), and is_builtin().

Referenced by exec_command_node().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pipe_fork_error()

int pipe_fork_error ( int  pipe_fd[2],
pid_t  left_pid 
)

Clean up pipe fds and wait for left child on fork failure.

Parameters
pipe_fdPipe file descriptors to close
left_pidPID of left child (0 if wasn't yet forked)
Returns
always 1 (exit code = error)

Definition at line 111 of file exec_utils.c.

Referenced by handle_pipe().

+ Here is the caller graph for this function:

Go to the source code of this file.