typedef struct s_shell { t_env *env_lst; t_token *token; t_cmd *cmd; int prev_exit; int exit; // more to add } t_shell;
typedef struct s_redir { t_type type; char *file; int fd; struct s_redir *next;
In t_shell shell:
- *cmd is the head node of all the commands
- if there are more than one pipes, there will be more commands. aka cmd->next will be how to get to the next command.
- exit is to record the current process's exit code.
- After the whole execusion is done, update the prev_exit = exit
- *env_lst is a linked list. for execve(), we need a char **enviorn
In t_cmd cmd:
- char **cmd: cmd[0] is the command, the rest is the options of the command.
- char *path: is the command's execution path, like /usr/bin/echo for the usage of execve();
- t_redir *redir:
- t_type type: IN, OUT, HEREDOC, APPEND
- char *file: the address string of the file directory.
- int fd: the fd return by open(file);
- next: next redir node.
- ATTENTION: During Execution, dup_file, redir need to be checked with one will be replaced with pipes[i][0] and pipes[i][1];
- create_pipes
- create_process
- run child process
- builtin commd
- execve commd
- close parent pipes
- run child process
- wait for process finish and update shell->exit.
- in create_process
- create_environ()
- dup_files()
- redir_fd()_
- execve_cmd()
- intergrate builtin functions.
- wait for process finish
- set correct exit code.
- system error handling
- signal handling.