From cb5d5631c2e778786f961dc994e2eec32b6a5fee Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 20 Mar 2017 11:30:24 +0100 Subject: [PATCH] fd fix --- 42sh/src/main/shell_init.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 9d9ee45c..fcfb4611 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:21:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:30:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,9 +40,13 @@ static int get_input_fd(t_data *data) write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); } - else if ((file = *data->av_data) && !stat(file, &buf)) + else if ((file = *data->av_data)) { - if (S_ISDIR(buf.st_mode)) + DG("file=%s", file); + if (stat(file, &buf) < 0) + ft_printf("{red}%s: %s: No such file or directory\n{eoc}", + data->argv[0], file); + else if (S_ISDIR(buf.st_mode)) ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0], file); else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0) ft_printf("{red}%s: %s: No such file or directory\n{eoc}", @@ -71,7 +75,7 @@ static int interactive_settings(void) signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); - signal(SIGCHLD, SIG_DFL);//sigchld_handler); TBC IF dynamic notification are wanted + signal(SIGCHLD, SIG_DFL); *shell_pgid = getpid(); if (setpgid(*shell_pgid, *shell_pgid)) { @@ -107,8 +111,10 @@ int shell_init(int ac, char **av) DG(); if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); + DG(); if ((data->fd = get_input_fd(data)) < 0) return (-1); + DG(); if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) return (-1); return (0);