aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/cmd.c17
-rw-r--r--src/eval/exec.c22
2 files changed, 26 insertions, 13 deletions
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index 1953325..1e59347 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/14 10:41:31 by charles #+# #+# */
-/* Updated: 2020/07/17 11:43:59 by charles ### ########.fr */
+/* Updated: 2020/07/18 09:31:43 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -52,6 +52,7 @@ int fork_wrap(
int forked_cmd(void *void_param)
{
t_fork_param_cmd *param;
+ int ret;
param = void_param;
ft_vecpop(param->env_local, NULL);
@@ -63,7 +64,19 @@ int forked_cmd(void *void_param)
if (param->builtin != NULL)
return (param->builtin->func(param->argv, param->env));
else
- return (execve(param->exec_path, param->argv, (char**)param->env->data));
+ {
+ ret = execve(param->exec_path, param->argv, (char**)param->env->data);
+ if (ret == -1)
+ {
+ ft_putstr_fd(g_basename, STDERR_FILENO);
+ ft_putstr_fd(": ", STDERR_FILENO);
+ ft_putstr_fd(param->exec_path, STDERR_FILENO);
+ ft_putstr_fd(": ", STDERR_FILENO);
+ ft_putendl_fd(strerror(errno), STDERR_FILENO);
+ ret = 126;
+ }
+ return (ret);
+ }
}
int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast)
diff --git a/src/eval/exec.c b/src/eval/exec.c
index e41f994..fb97bdc 100644
--- a/src/eval/exec.c
+++ b/src/eval/exec.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:06:11 by charles #+# #+# */
-/* Updated: 2020/04/01 17:06:12 by charles ### ########.fr */
+/* Updated: 2020/07/18 09:39:53 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,12 +23,12 @@
** \return True if valid
*/
-bool exec_is_path(char *exec_name)
-{
- return (ft_strncmp(exec_name, "../", 3) == 0
- || ft_strncmp(exec_name, "./", 2) == 0
- || ft_strncmp(exec_name, "/", 1) == 0);
-}
+/* bool exec_is_path(char *exec_name) */
+/* { */
+/* return (ft_strncmp(exec_name, "../", 3) == 0 */
+/* || ft_strncmp(exec_name, "./", 2) == 0 */
+/* || ft_strncmp(exec_name, "/", 1) == 0); */
+/* } */
/*
** \brief Check if executable path is valid
@@ -60,13 +60,13 @@ char *exec_search_path(t_path path, char *path_var, char *exec_name)
{
char *exec_path;
- if (exec_is_path(exec_name))
+ if (ft_strchr(exec_name, '/') != NULL) // TODO test recursive link
return (exec_name);
- // try current first
+ // TODO if PATH contain empty path, consider current directory files as cmd
if ((exec_path = ft_htget(path, exec_name)) == NULL)
{
- if (path_update(path, path_var) == NULL) // optimise by not updating not changed path in ht
- return (NULL);
+ if (path_update(path, path_var) == NULL) // optimise by not updating not changed path in ht
+ return (NULL); // FIXME need to distiguish between malloc error and cmd not found error
if ((exec_path = ft_htget(path, exec_name)) == NULL)
return (NULL);
}