issue #48 first step
This commit is contained in:
parent
8cba9bc113
commit
8a46d9fe2a
6 changed files with 25 additions and 16 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 03:25:53 by wescande ### ########.fr */
|
/* Updated: 2017/03/08 12:26:19 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ struct s_data_cmd
|
||||||
char **av;
|
char **av;
|
||||||
char *path;
|
char *path;
|
||||||
t_execf *execf;
|
t_execf *execf;
|
||||||
struct stat stat;
|
struct stat *stat;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_data_cond
|
struct s_data_cond
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/07 21:33:56 by wescande ### ########.fr */
|
/* Updated: 2017/03/08 12:42:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,7 +25,12 @@ int launch_file(t_process *p)
|
||||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||||
exit(127);
|
exit(127);
|
||||||
}
|
}
|
||||||
else if (S_ISDIR(p->data.cmd.stat.st_mode))
|
else if (!p->data.cmd.stat)
|
||||||
|
{
|
||||||
|
ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||||
|
exit(127);
|
||||||
|
}
|
||||||
|
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}%s: %s: Is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
ft_dprintf(2, "{red}%s: %s: Is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||||
exit(126);
|
exit(126);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 03:32:49 by wescande ### ########.fr */
|
/* Updated: 2017/03/08 12:42:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,6 +17,8 @@ int process_setexec(t_process *p)
|
||||||
t_btree *func;
|
t_btree *func;
|
||||||
p->data.cmd.path = NULL;
|
p->data.cmd.path = NULL;
|
||||||
p->data.cmd.execf = NULL;
|
p->data.cmd.execf = NULL;
|
||||||
|
p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
|
||||||
|
DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]);
|
||||||
if ((func = is_function(p)))
|
if ((func = is_function(p)))
|
||||||
{
|
{
|
||||||
p->data.subshell.content = func;
|
p->data.subshell.content = func;
|
||||||
|
|
@ -29,7 +31,8 @@ int process_setexec(t_process *p)
|
||||||
p->type = PROCESS_FILE;
|
p->type = PROCESS_FILE;
|
||||||
p->data.cmd.execf = &execve;
|
p->data.cmd.execf = &execve;
|
||||||
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
|
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
|
||||||
stat(p->data.cmd.path, &p->data.cmd.stat);
|
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
|
||||||
|
ft_memdel((void**)&p->data.cmd.stat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +40,12 @@ int process_setexec(t_process *p)
|
||||||
if (ft_hash(p))
|
if (ft_hash(p))
|
||||||
{
|
{
|
||||||
p->data.cmd.execf = &execve;
|
p->data.cmd.execf = &execve;
|
||||||
stat(p->data.cmd.path, &p->data.cmd.stat);
|
DG("found hash at [%s]", p->data.cmd.path);
|
||||||
|
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
|
||||||
|
{
|
||||||
|
ft_memdel((void**)&p->data.cmd.stat);
|
||||||
|
ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
|
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/05 18:06:24 by ariard ### ########.fr */
|
/* Updated: 2017/03/08 12:40:34 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,9 +22,5 @@ void redir_free(void *data, size_t content_size)
|
||||||
{
|
{
|
||||||
ft_strdel(&redir->word);
|
ft_strdel(&redir->word);
|
||||||
}
|
}
|
||||||
/* else */
|
|
||||||
/* redir->type = 0; */
|
|
||||||
/* redir->n = 0; */
|
|
||||||
/* redir->close = 1; */
|
|
||||||
free(redir);
|
free(redir);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 03:26:28 by wescande ### ########.fr */
|
/* Updated: 2017/03/08 12:40:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
t_itof g_freemap[] =
|
t_itof g_freemap[] =
|
||||||
{
|
{
|
||||||
{PROCESS_FUNCTION, process_free_subshell},
|
{PROCESS_FUNCTION, process_free_subshell},
|
||||||
{PROCESS_BUILTIN, NULL},
|
{PROCESS_BUILTIN, process_free_cmd},
|
||||||
{PROCESS_FILE, process_free_cmd},
|
{PROCESS_FILE, process_free_cmd},
|
||||||
{PROCESS_SUBSHELL, process_free_subshell},
|
{PROCESS_SUBSHELL, process_free_subshell},
|
||||||
{PROCESS_WHILE, process_free_cond},
|
{PROCESS_WHILE, process_free_cond},
|
||||||
|
|
@ -36,6 +36,6 @@ void process_free(void *content, size_t content_size)
|
||||||
return ;
|
return ;
|
||||||
if (g_freemap[p->type].f)
|
if (g_freemap[p->type].f)
|
||||||
(g_freemap[p->type].f)(p);
|
(g_freemap[p->type].f)(p);
|
||||||
ft_lstdel(&p->redirs, ft_lst_cfree);
|
ft_lstdel(&p->redirs, redir_free);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/08 12:20:37 by jhalford ### ########.fr */
|
/* Updated: 2017/03/08 12:41:03 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue