This commit is contained in:
Jack Halford 2017-03-20 11:30:24 +01:00
parent 38d8847f82
commit cb5d5631c2

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);