From b1f730a833abd4aa252e15ffd1a9b1fe07ea2305 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 00:29:03 +0100 Subject: [PATCH 1/3] env ./42sh still making problems --- 42sh/includes/exec.h | 2 +- 42sh/includes/minishell.h | 2 +- 42sh/src/builtin/builtin_cd.c | 6 +++--- 42sh/src/builtin/builtin_echo.c | 2 +- 42sh/src/builtin/builtin_exit.c | 1 + 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/exec_reset.c | 23 ++++------------------- 42sh/src/exec/plaunch_builtin.c | 4 ++-- 42sh/src/exec/plaunch_file.c | 2 +- 42sh/src/exec/process_launch.c | 25 ++++++------------------- 42sh/src/exec/process_resetfds.c | 21 +++++++-------------- 42sh/src/job_control/job_wait.c | 1 + 42sh/src/lexer/lexer_word.c | 5 +++-- 42sh/src/line_editing/get_key.c | 5 ++++- 42sh/src/main/data_init.c | 3 +++ 42sh/src/main/main.c | 1 + 16 files changed, 40 insertions(+), 65 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 03f24f8a..f4e7419e 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -131,7 +131,7 @@ struct s_job struct s_exec { t_job job; - int fd_save[3]; + int fd_save[10]; t_flag attrs; int fdin; t_list *op_stack; diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index f80bc6e3..26b20751 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -67,7 +67,7 @@ int data_init(int ac, char **av); void data_exit(void); int get_c_arg(char ***av, t_data *data); -void content_free(void *data, size_t content_size); +/* void content_free(void *data, size_t content_size); */ char *ft_putast(void *node); void ft_putast2(void *node); diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index 1c1f8851..5e96339f 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -81,14 +81,14 @@ int builtin_cd(const char *path, opts = CDOPT_L; i = builtin_cd_opts(av, &opts); if (!(target = builtin_cd_special(av + i, envp))) - return (builtin_return_status(0, 1)); + return (1); cwd = getcwd(NULL, 0); builtin_setenv(path, (char*[4]){"setenv", "OLDPWD", cwd, NULL}, envp); free(cwd); if (chdir(target)) { SH_ERR(CDERR_1, target); - return (builtin_return_status(0, 1)); + return (1); } else if (target != av[i]) ft_printf("%s\n", target); @@ -97,5 +97,5 @@ int builtin_cd(const char *path, free(cwd); if (!ft_strcmp(*(av + i), "-")) free(target); - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/builtin/builtin_echo.c b/42sh/src/builtin/builtin_echo.c index fcae589b..8c6add7f 100644 --- a/42sh/src/builtin/builtin_echo.c +++ b/42sh/src/builtin/builtin_echo.c @@ -25,5 +25,5 @@ int builtin_echo(const char *path, char *const av[], char *const envp[]) ft_putchar(' '); } ft_putchar('\n'); - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index f9625fc9..b0294f64 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -35,6 +35,7 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); job_hup_all(); data_exit(); + DG("EXITING NOW"); exit(status); return (0); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index c8ea2ea7..7e5f7b13 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -52,6 +52,6 @@ int exec_leaf(t_btree **ast) } } else -DG("WHY HERE?"); +DG("WHY HERE? --> because no fork means no job control"); return (0); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index ed1892a3..8fe4a385 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -12,13 +12,6 @@ #include "minishell.h" -static int print_error(char *std) -{ - ft_dprintf(2, "{red}%s: internal fcntl %s error errno=%i{eoc}\n", - SHELL_NAME, std, errno); - return (errno); -} - int exec_reset_job(t_job *job) { job->id = 0; @@ -32,21 +25,13 @@ int exec_reset(void) { t_exec *exec; t_jobc *jobc; + int i; exec = &data_singleton()->exec; jobc = &data_singleton()->jobc; - if (errno != EBADF) - { - if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 - && errno != EBADF) - return (print_error("STDIN")); - if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 - && errno != EBADF) - return (print_error("STDOUT")); - if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 - && errno != EBADF) - return (print_error("STDERR")); - } + i = -1; + while (++i < 10) + exec->fd_save[i] = fcntl(i, F_DUPFD_CLOEXEC, 10); exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/plaunch_builtin.c b/42sh/src/exec/plaunch_builtin.c index 774171d4..f67b753c 100644 --- a/42sh/src/exec/plaunch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -14,8 +14,8 @@ int plaunch_builtin(t_process *p) { - return ((*p->data.cmd.execf)( + return (*p->data.cmd.execf)( p->data.cmd.path, p->data.cmd.av, - data_singleton()->env)); + data_singleton()->env); } diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index d084b35c..4c3a4050 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -14,7 +14,7 @@ static void error_launch(char *error_ori, char *error_type, int error_code) { - ft_dprintf(2, "{red}%s: %s%s{eoc}\n", SHELL_NAME, error_ori, error_type); + SH_ERR("%s: %s%s", SHELL_NAME, error_ori, error_type); exit(error_code); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index ab5d2de6..4cf71ad5 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -12,7 +12,7 @@ #include "minishell.h" -int do_the_muther_forker(t_process *p) +int process_fork(t_process *p) { pid_t pid; @@ -35,8 +35,9 @@ int do_the_muther_forker(t_process *p) exit(p->map.launch(p)); } -static int do_the_fork_if_i_have_to(t_process *p) +int process_launch(t_process *p) { + p->state = PROCESS_RUNNING; if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) { @@ -45,27 +46,13 @@ static int do_the_fork_if_i_have_to(t_process *p) set_exitstatus(1, 1); return (0); } - return (p->map.launch(p)); - /* set_exitstatus(p->map.launch(p), 1); */ - /* return (0); */ - } - return (do_the_muther_forker(p)); -} - -int process_launch(t_process *p) -{ - pid_t pid; - - p->state = PROCESS_RUNNING; - if (!(pid = do_the_fork_if_i_have_to(p))) - { + set_exitstatus(p->map.launch(p), 1); process_resetfds(p); process_free(p, 0); return (1); } - DG("FORK"); - p->pid = pid; - process_setgroup(p, pid); + p->pid = process_fork(p): + process_setgroup(p, p->pid); if (p->fdin != STDIN) close(p->fdin); if (p->fdout != STDOUT) diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/exec/process_resetfds.c index a8632b39..403f53d1 100644 --- a/42sh/src/exec/process_resetfds.c +++ b/42sh/src/exec/process_resetfds.c @@ -19,20 +19,13 @@ void process_resetfds(t_process *p) (void)p; exec = &data_singleton()->exec; - i = 0; - while (i < 10) + i = -1; + while (++i < 10) { - /* if (i!=3) //JACK SOME PB HERE on close la sortie debug en forcant le close sur tous les fd... ne risque-t-on pas autre chose ??!!! */ - /* { */ - close(i++); - /* } */ - /* else */ - /* i++; */ + if (exec->fd_save[i] != -1) + { + DG("dup2(%i, %i)", exec->fd_save[i], i); + dup2(exec->fd_save[i], i); + } } - if (exec->fd_save[0] != -1) - dup2(exec->fd_save[0], STDIN); - if (exec->fd_save[1] != -1) - dup2(exec->fd_save[1], STDOUT); - if (exec->fd_save[2] != -1) - dup2(exec->fd_save[2], STDERR); } diff --git a/42sh/src/job_control/job_wait.c b/42sh/src/job_control/job_wait.c index 2c80369c..b34371d6 100644 --- a/42sh/src/job_control/job_wait.c +++ b/42sh/src/job_control/job_wait.c @@ -30,6 +30,7 @@ int job_wait(int id) && errno != ECHILD) ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno); + DG("wait trigger pid=%i", pid); if (pid <= 1 || mark_process_status(pid, status) || job_is_stopped(j) || job_is_completed(j)) diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 665c0a0a..77296e3e 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -19,8 +19,9 @@ int lexer_word(t_list **alst, t_lexer *lexer) token = (*alst)->content; token->type = token->type ? token->type : TK_WORD; - if ((state = get_state_global(lexer)) - || (state = get_state_redir(lexer))) + if (lexer->str[lexer->pos] != '!' + && ((state = get_state_global(lexer)) + || (state = get_state_redir(lexer)))) lexer->state = state; else if (lexer->str[lexer->pos] == '=' && word_is_assignment((char *[]){token->data, (char *)token->esc})) diff --git a/42sh/src/line_editing/get_key.c b/42sh/src/line_editing/get_key.c index da810243..d8b60073 100644 --- a/42sh/src/line_editing/get_key.c +++ b/42sh/src/line_editing/get_key.c @@ -58,8 +58,11 @@ static int read_stdin(int *ret, int *j) { *j = 0; *ret = 0; - if (read(0, ret, sizeof(int)) < 0) + if (read(STDIN, ret, sizeof(int)) < 0) + { + DG("read problem: %s", strerror(errno)); return (-1); + } return (1); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 272a3e04..9fcce223 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -17,11 +17,14 @@ extern char **environ; static int localenv_init(void) { t_data *data; + char *pid; + pid = ft_itoa(getpid()); data = data_singleton(); data->local_var = NULL; builtin_setenv(NULL, (char *[]){"local", "IFS", " \t\n", 0}, NULL); builtin_setenv(NULL, (char *[]){"local", "PS2", " >", 0}, NULL); + ft_strdel(&pid); return (0); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 94c1f966..543de1a4 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -43,6 +43,7 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; + /* token_print(*token); */ if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); From 9e8855a9ef6d2c7c9f54091f2037f92b4c6ceec5 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 00:38:04 +0100 Subject: [PATCH 2/3] env ./42sh still making problems --- 42sh/includes/exec.h | 2 +- 42sh/src/exec/process_launch.c | 2 +- 42sh/src/glob/command_getoutput.c | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index f4e7419e..d0ee6e3c 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -140,7 +140,7 @@ struct s_exec }; int exec_reset(void); -int do_the_muther_forker(t_process *p); +int process_fork(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); void process_reset(t_process *p); diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 4cf71ad5..c7b959ff 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -51,7 +51,7 @@ int process_launch(t_process *p) process_free(p, 0); return (1); } - p->pid = process_fork(p): + p->pid = process_fork(p); process_setgroup(p, p->pid); if (p->fdin != STDIN) close(p->fdin); diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 18da3edc..8bd80bbb 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -21,8 +21,7 @@ static char *manage_output(int *fds) output = NULL; close(fds[PIPE_WRITE]); - while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0) - { + while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0) { buf[ret] = 0; ft_strappend(&output, buf); } @@ -89,7 +88,7 @@ char *command_getoutput(char *command) if (!command) return (NULL); pipe(fds); - if (!(pid = do_the_muther_forker(NULL))) + if (!(pid = process_fork(NULL))) { close(fds[PIPE_READ]); dup2_close(fds[PIPE_WRITE], STDOUT); @@ -110,7 +109,7 @@ int command_setoutput(char *const av[], char **env) if (!av) return (0); pid = 0; - if (!(pid = do_the_muther_forker(NULL))) + if (!(pid = process_fork(NULL))) execute_command(av, env); return (pid); } From 3ef3bc8f0ac2c225485ba4d53d33f2327285a9dc Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 22 Mar 2017 13:08:10 +0100 Subject: [PATCH 3/3] builtin now return their exit status, gonna merge onto master --- 42sh/Makefile | 1 - 42sh/src/builtin/builtin_env.c | 2 +- 42sh/src/builtin/builtin_exit.c | 1 - 42sh/src/builtin/builtin_export.c | 4 ++-- 42sh/src/builtin/builtin_hash.c | 4 ++-- 42sh/src/builtin/builtin_history.c | 4 ++-- 42sh/src/builtin/builtin_math.c | 12 ++++++------ 42sh/src/builtin/builtin_read.c | 2 +- 42sh/src/builtin/builtin_return_status.c | 19 ------------------- 42sh/src/builtin/builtin_setenv.c | 5 +++-- 42sh/src/builtin/builtin_unsetenv.c | 2 +- 42sh/src/exec/exec_leaf.c | 5 +---- 42sh/src/exec/process_launch.c | 10 ++++------ 42sh/src/exec/process_resetfds.c | 3 --- 42sh/src/line_editing/get_key.c | 3 --- 15 files changed, 23 insertions(+), 54 deletions(-) delete mode 100644 42sh/src/builtin/builtin_return_status.c diff --git a/42sh/Makefile b/42sh/Makefile index e1a3c6fd..60e13955 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -40,7 +40,6 @@ builtin/builtin_hash.c\ builtin/builtin_history.c\ builtin/builtin_math.c\ builtin/builtin_read.c\ -builtin/builtin_return_status.c\ builtin/builtin_setenv.c\ builtin/builtin_unset.c\ builtin/builtin_unsetenv.c\ diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index f52a8080..bf22360f 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -59,6 +59,6 @@ int builtin_env(const char *path, } waitpid(pid, &status, 0); ft_sstrfree(data.custom_env); + tcsetpgrp(STDIN, data_singleton()->jobc.shell_pgid); return (0); - /* return (builtin_return_status(pid, 0)); */ } diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index b0294f64..f9625fc9 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -35,7 +35,6 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); job_hup_all(); data_exit(); - DG("EXITING NOW"); exit(status); return (0); } diff --git a/42sh/src/builtin/builtin_export.c b/42sh/src/builtin/builtin_export.c index 4eee266a..9b8919d8 100644 --- a/42sh/src/builtin/builtin_export.c +++ b/42sh/src/builtin/builtin_export.c @@ -47,7 +47,7 @@ int builtin_export( if (cliopts_get((char**)av, g_export_opts, &data)) ft_perror(); if (data.flag & BT_EXPORT_LP) - return (builtin_return_status(0, bt_export_print())); + return (bt_export_print()); av = data.av_data; while (*av) { @@ -61,5 +61,5 @@ int builtin_export( builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL); av++; } - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/builtin/builtin_hash.c b/42sh/src/builtin/builtin_hash.c index 539f04b5..18aa0645 100644 --- a/42sh/src/builtin/builtin_hash.c +++ b/42sh/src/builtin/builtin_hash.c @@ -44,7 +44,7 @@ int builtin_hash(const char *path, char *const av[], char *const envp[]) (void)path; (void)envp; if (!av || ft_hash_opt(av)) - return (builtin_return_status(0, 1)); + return (1); i = 0; while (i < MAX_HASH) { @@ -52,5 +52,5 @@ int builtin_hash(const char *path, char *const av[], char *const envp[]) ft_hash_lst_print(g_hash[i]); ++i; } - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/builtin/builtin_history.c b/42sh/src/builtin/builtin_history.c index 7d66d2b0..1c315ee8 100644 --- a/42sh/src/builtin/builtin_history.c +++ b/42sh/src/builtin/builtin_history.c @@ -23,7 +23,7 @@ int builtin_history(const char *path, char *const av[], char *const envp[]) head = data_singleton()->line.list_end; len = 1; if (!head) - return (builtin_return_status(0, 0)); + return (0); if (head && !head->str) head = head->next; while (head && head->str) @@ -34,5 +34,5 @@ int builtin_history(const char *path, char *const av[], char *const envp[]) ++len; head = head->next; } - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 6d620c12..77072563 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -90,19 +90,19 @@ int builtin_math(const char *path, char *const av[], char *const envp[]) (void)path; (void)envp; if (!av || !av[1] || !av[2] || !av[3] || av[4]) - return (builtin_return_status(0, SH_ERR(MATHERR_0))); + return (SH_ERR(MATHERR_0)); init_math(&var, &value, &operator, &operand); var = av[1]; if (get_value(var, &value)) - return (builtin_return_status(0, 1)); + return (1); operator = av[2]; if (ft_strlen(operator) != 1 || !(ft_strchr("+-/*%", operator[0]))) - return (builtin_return_status(0, SH_ERR(MATHERR_2))); + return (SH_ERR(MATHERR_2)); operand = av[3]; if (!ft_stris(operand, &ft_isdigit)) - return (builtin_return_status(0, SH_ERR(MATHERR_3))); + return (SH_ERR(MATHERR_3)); if (do_math(&value, operator, operand)) - return (builtin_return_status(0, 1)); + return (1); builtin_setenv("setenv", (char *[]){"local", var, value, 0}, NULL); - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index d5edb32c..7410da42 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -114,5 +114,5 @@ int builtin_read(const char *path, char *const av[], char *const envp[]) SH_ERR("usage: read %s %s\n", US_READ, US_READ_1); if (ret != 2) bt_read_exit(&data); - return (builtin_return_status(0, ret)); + return (ret); } diff --git a/42sh/src/builtin/builtin_return_status.c b/42sh/src/builtin/builtin_return_status.c deleted file mode 100644 index d215cb19..00000000 --- a/42sh/src/builtin/builtin_return_status.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* builtin_return_status.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/20 12:48:04 by wescande #+# #+# */ -/* Updated: 2017/03/21 15:21:09 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int builtin_return_status(int ret, int status) -{ - set_exitstatus(status, 1); - return (ret); -} diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index 4cfda406..d6368d83 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -44,8 +44,9 @@ int builtin_setenv(const char *path, int ret; (void)path; + (void)envp; if (!av || !av[0]) - return (builtin_return_status(0, 1)); + return (1); env = (ft_strcmp(av[0], "local") == 0) ? &data_singleton()->local_var : &data_singleton()->env; if (!av[1]) @@ -62,5 +63,5 @@ int builtin_setenv(const char *path, return (SH_ERR(SETERR_0)); assign_var(av, env); } - return (envp ? builtin_return_status(0, 0) : 0); + return (0); } diff --git a/42sh/src/builtin/builtin_unsetenv.c b/42sh/src/builtin/builtin_unsetenv.c index d014efd9..2cc3b9c7 100644 --- a/42sh/src/builtin/builtin_unsetenv.c +++ b/42sh/src/builtin/builtin_unsetenv.c @@ -35,5 +35,5 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[]) } i++; } - return (builtin_return_status(0, 0)); + return (0); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 7e5f7b13..2f2bd313 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -38,9 +38,8 @@ int exec_leaf(t_btree **ast) if (p.type >= PROCESS_MAX) return (1); p.map = g_process_map[p.type]; - if (!(process_launch(&p))) + if (process_launch(&p)) { - DG("check"); job_addprocess(&p); if (IS_PIPEEND(p)) { @@ -51,7 +50,5 @@ int exec_leaf(t_btree **ast) job->pgid = 0; } } - else -DG("WHY HERE? --> because no fork means no job control"); return (0); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index c7b959ff..0d4d86dd 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -42,14 +42,12 @@ int process_launch(t_process *p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) { if (process_redirect(p)) - { set_exitstatus(1, 1); - return (0); - } - set_exitstatus(p->map.launch(p), 1); + else + set_exitstatus(p->map.launch(p), 1); process_resetfds(p); process_free(p, 0); - return (1); + return (0); } p->pid = process_fork(p); process_setgroup(p, p->pid); @@ -57,5 +55,5 @@ int process_launch(t_process *p) close(p->fdin); if (p->fdout != STDOUT) close(p->fdout); - return (0); + return (1); } diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/exec/process_resetfds.c index 403f53d1..4eb0da6c 100644 --- a/42sh/src/exec/process_resetfds.c +++ b/42sh/src/exec/process_resetfds.c @@ -23,9 +23,6 @@ void process_resetfds(t_process *p) while (++i < 10) { if (exec->fd_save[i] != -1) - { - DG("dup2(%i, %i)", exec->fd_save[i], i); dup2(exec->fd_save[i], i); - } } } diff --git a/42sh/src/line_editing/get_key.c b/42sh/src/line_editing/get_key.c index d8b60073..3647c734 100644 --- a/42sh/src/line_editing/get_key.c +++ b/42sh/src/line_editing/get_key.c @@ -59,10 +59,7 @@ static int read_stdin(int *ret, int *j) *j = 0; *ret = 0; if (read(STDIN, ret, sizeof(int)) < 0) - { - DG("read problem: %s", strerror(errno)); return (-1); - } return (1); }